swagger.json 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. {
  2. "openapi": "3.0.1",
  3. "info": {
  4. "title": "OpenCost API",
  5. "description": "The OpenCost API provides real-time and historical reporting of Kubernetes cloud costs.",
  6. "license": {
  7. "name": "Apache 2.0",
  8. "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
  9. },
  10. "version": "1.0.0"
  11. },
  12. "servers": [
  13. {
  14. "url": "http://localhost:9003",
  15. "description": "kubectl port-forward --namespace opencost service/opencost 9003"
  16. }
  17. ],
  18. "paths": {
  19. "/allocation": {
  20. "get": {
  21. "summary": "query for costs and resources allocated to Kubernetes workloads",
  22. "description": "The standard OpenCost API query for costs and resources allocated to Kubernetes workloads. Note that 'data' is an array of sets (one per 'step').\n",
  23. "parameters": [
  24. {
  25. "name": "window",
  26. "in": "query",
  27. "required": true,
  28. "description": "Duration of time over which to query. Accepts: words like `today`, `lastweek`; durations like `30m`, `7d`; RFC3339 date pairs; or Unix timestamps.",
  29. "schema": {
  30. "type": "string"
  31. },
  32. "examples": {
  33. "today": {
  34. "value": "today"
  35. },
  36. "lastweek": {
  37. "value": "lastweek"
  38. },
  39. "range": {
  40. "value": "2024-01-01T00:00:00Z,2024-01-02T00:00:00Z"
  41. }
  42. }
  43. },
  44. {
  45. "name": "aggregate",
  46. "in": "query",
  47. "description": "Field by which to aggregate. e.g., `namespace`, `controller`, `label:app`.",
  48. "schema": {
  49. "type": "string"
  50. },
  51. "example": "namespace"
  52. },
  53. {
  54. "name": "step",
  55. "in": "query",
  56. "description": "Duration of a single allocation set. Default is `window`.",
  57. "schema": {
  58. "type": "string"
  59. },
  60. "example": "1d"
  61. },
  62. {
  63. "name": "accumulate",
  64. "in": "query",
  65. "description": "If true, sums the entire window into a single result set.",
  66. "schema": {
  67. "type": "boolean"
  68. }
  69. }
  70. ],
  71. "responses": {
  72. "200": {
  73. "description": "Success",
  74. "content": {
  75. "application/json": {
  76. "schema": {
  77. "$ref": "#/components/schemas/AllocationResponse"
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. },
  85. "/assets": {
  86. "get": {
  87. "summary": "query for underlying infrastructure assets",
  88. "description": "Returns the costs of Nodes, Disks, and Load Balancers.",
  89. "parameters": [
  90. {
  91. "name": "window",
  92. "in": "query",
  93. "required": true,
  94. "schema": {
  95. "type": "string"
  96. }
  97. }
  98. ],
  99. "responses": {
  100. "200": {
  101. "description": "Success",
  102. "content": {
  103. "application/json": {
  104. "schema": {
  105. "$ref": "#/components/schemas/AssetsResponse"
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. },
  113. "/cloudCost": {
  114. "get": {
  115. "summary": "query for cloud provider billing data",
  116. "description": "Retrieves non-K8s cloud provider costs via cloud integration.",
  117. "parameters": [
  118. {
  119. "name": "window",
  120. "in": "query",
  121. "required": true,
  122. "schema": {
  123. "type": "string"
  124. }
  125. }
  126. ],
  127. "responses": {
  128. "200": {
  129. "description": "Success",
  130. "content": {
  131. "application/json": {
  132. "schema": {
  133. "$ref": "#/components/schemas/CloudCostResponse"
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. },
  142. "components": {
  143. "schemas": {
  144. "AllocationResponse": {
  145. "type": "object",
  146. "properties": {
  147. "code": {
  148. "type": "integer"
  149. },
  150. "status": {
  151. "type": "string"
  152. },
  153. "data": {
  154. "type": "array",
  155. "items": {
  156. "type": "object",
  157. "additionalProperties": {
  158. "$ref": "#/components/schemas/Allocation"
  159. }
  160. }
  161. }
  162. }
  163. },
  164. "Allocation": {
  165. "type": "object",
  166. "properties": {
  167. "name": {
  168. "type": "string"
  169. },
  170. "cpuCost": {
  171. "type": "number"
  172. },
  173. "cpuCoreUsageAverage": {
  174. "type": "number"
  175. },
  176. "ramCost": {
  177. "type": "number"
  178. },
  179. "ramByteUsageAverage": {
  180. "type": "number"
  181. },
  182. "pvCost": {
  183. "type": "number"
  184. },
  185. "networkCost": {
  186. "type": "number"
  187. },
  188. "sharedCost": {
  189. "type": "number"
  190. },
  191. "externalCost": {
  192. "type": "number"
  193. },
  194. "totalCost": {
  195. "type": "number"
  196. },
  197. "minutes": {
  198. "type": "number"
  199. },
  200. "window": {
  201. "type": "object",
  202. "properties": {
  203. "start": {
  204. "type": "string",
  205. "format": "date-time"
  206. },
  207. "end": {
  208. "type": "string",
  209. "format": "date-time"
  210. }
  211. }
  212. },
  213. "properties": {
  214. "type": "object",
  215. "additionalProperties": {
  216. "type": "string"
  217. }
  218. }
  219. }
  220. },
  221. "AssetsResponse": {
  222. "type": "object",
  223. "properties": {
  224. "code": {
  225. "type": "integer"
  226. },
  227. "status": {
  228. "type": "string"
  229. },
  230. "data": {
  231. "type": "object",
  232. "additionalProperties": {
  233. "$ref": "#/components/schemas/Asset"
  234. }
  235. }
  236. }
  237. },
  238. "Asset": {
  239. "type": "object",
  240. "properties": {
  241. "type": {
  242. "type": "string"
  243. },
  244. "totalCost": {
  245. "type": "number"
  246. },
  247. "cpuCost": {
  248. "type": "number"
  249. },
  250. "ramCost": {
  251. "type": "number"
  252. },
  253. "providerID": {
  254. "type": "string"
  255. },
  256. "window": {
  257. "type": "object",
  258. "properties": {
  259. "start": {
  260. "type": "string",
  261. "format": "date-time"
  262. },
  263. "end": {
  264. "type": "string",
  265. "format": "date-time"
  266. }
  267. }
  268. }
  269. }
  270. },
  271. "CloudCostResponse": {
  272. "type": "object",
  273. "properties": {
  274. "code": {
  275. "type": "integer"
  276. },
  277. "status": {
  278. "type": "string"
  279. },
  280. "data": {
  281. "type": "object",
  282. "properties": {
  283. "sets": {
  284. "type": "array",
  285. "items": {
  286. "$ref": "#/components/schemas/CloudCostSet"
  287. }
  288. }
  289. }
  290. }
  291. }
  292. },
  293. "CloudCostSet": {
  294. "type": "object",
  295. "properties": {
  296. "cloudCosts": {
  297. "type": "object",
  298. "additionalProperties": {
  299. "$ref": "#/components/schemas/CloudCostItem"
  300. }
  301. }
  302. }
  303. },
  304. "CloudCostItem": {
  305. "type": "object",
  306. "properties": {
  307. "netCost": {
  308. "type": "object",
  309. "properties": {
  310. "cost": {
  311. "type": "number"
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }