{ "openapi": "3.0.1", "info": { "title": "OpenCost API", "description": "The OpenCost API provides real-time and historical reporting of Kubernetes cloud costs.", "license": { "name": "Apache 2.0", "url": "https://www.apache.org/licenses/LICENSE-2.0.html" }, "version": "1.0.0" }, "servers": [ { "url": "http://localhost:9003", "description": "kubectl port-forward --namespace opencost service/opencost 9003" } ], "paths": { "/allocation": { "get": { "summary": "query for costs and resources allocated to Kubernetes workloads", "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", "parameters": [ { "name": "window", "in": "query", "required": true, "description": "Duration of time over which to query. Accepts: words like `today`, `lastweek`; durations like `30m`, `7d`; RFC3339 date pairs; or Unix timestamps.", "schema": { "type": "string" }, "examples": { "today": { "value": "today" }, "lastweek": { "value": "lastweek" }, "range": { "value": "2024-01-01T00:00:00Z,2024-01-02T00:00:00Z" } } }, { "name": "aggregate", "in": "query", "description": "Field by which to aggregate. e.g., `namespace`, `controller`, `label:app`.", "schema": { "type": "string" }, "example": "namespace" }, { "name": "step", "in": "query", "description": "Duration of a single allocation set. Default is `window`.", "schema": { "type": "string" }, "example": "1d" }, { "name": "accumulate", "in": "query", "description": "If true, sums the entire window into a single result set.", "schema": { "type": "boolean" } } ], "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AllocationResponse" } } } } } } }, "/assets": { "get": { "summary": "query for underlying infrastructure assets", "description": "Returns the costs of Nodes, Disks, and Load Balancers.", "parameters": [ { "name": "window", "in": "query", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/AssetsResponse" } } } } } } }, "/cloudCost": { "get": { "summary": "query for cloud provider billing data", "description": "Retrieves non-K8s cloud provider costs via cloud integration.", "parameters": [ { "name": "window", "in": "query", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CloudCostResponse" } } } } } } } }, "components": { "schemas": { "AllocationResponse": { "type": "object", "properties": { "code": { "type": "integer" }, "status": { "type": "string" }, "data": { "type": "array", "items": { "type": "object", "additionalProperties": { "$ref": "#/components/schemas/Allocation" } } } } }, "Allocation": { "type": "object", "properties": { "name": { "type": "string" }, "cpuCost": { "type": "number" }, "cpuCoreUsageAverage": { "type": "number" }, "ramCost": { "type": "number" }, "ramByteUsageAverage": { "type": "number" }, "pvCost": { "type": "number" }, "networkCost": { "type": "number" }, "sharedCost": { "type": "number" }, "externalCost": { "type": "number" }, "totalCost": { "type": "number" }, "minutes": { "type": "number" }, "window": { "type": "object", "properties": { "start": { "type": "string", "format": "date-time" }, "end": { "type": "string", "format": "date-time" } } }, "properties": { "type": "object", "additionalProperties": { "type": "string" } } } }, "AssetsResponse": { "type": "object", "properties": { "code": { "type": "integer" }, "status": { "type": "string" }, "data": { "type": "object", "additionalProperties": { "$ref": "#/components/schemas/Asset" } } } }, "Asset": { "type": "object", "properties": { "type": { "type": "string" }, "totalCost": { "type": "number" }, "cpuCost": { "type": "number" }, "ramCost": { "type": "number" }, "providerID": { "type": "string" }, "window": { "type": "object", "properties": { "start": { "type": "string", "format": "date-time" }, "end": { "type": "string", "format": "date-time" } } } } }, "CloudCostResponse": { "type": "object", "properties": { "code": { "type": "integer" }, "status": { "type": "string" }, "data": { "type": "object", "properties": { "sets": { "type": "array", "items": { "$ref": "#/components/schemas/CloudCostSet" } } } } } }, "CloudCostSet": { "type": "object", "properties": { "cloudCosts": { "type": "object", "additionalProperties": { "$ref": "#/components/schemas/CloudCostItem" } } } }, "CloudCostItem": { "type": "object", "properties": { "netCost": { "type": "object", "properties": { "cost": { "type": "number" } } } } } } } }