KubeadaptDocsBack to site
Sign inStart free
DocsAPI ReferenceCLI
    • Discovery
    • Organization
    • Clusters
    • Namespaces
    • Workloads
    • Nodes
    • Node Groups
    • Recommendations
    • Teams
    • Departments
    • Cost Explorer
    • Cost Trends
Docs homev1Api ReferenceCost Explorer

API Reference

Cost Explorer

POST /v1/cost-explorer/query: aggregated cost rows with filters, grouping, and KPI summary. Body schema, filter DSL, response shape, and errors.


The Cost Explorer endpoint runs aggregated cost queries against your tenant's billable resources. One endpoint, one method, one body schema, one paginated response.

Endpoint

plaintext
POST /v1/cost-explorer/query
Required scopecost_explorer:read
PaginationOffset-based (page / per_page) — distinct from the cursor pagination used elsewhere.
Cost modeAccepted. Default fully_loaded.
Body cap1 MiB. Exceeding it returns 413 with error.code = BAD_REQUEST.
Cluster scopingResults are scoped to clusters your API key is authorized to access. A request that names only non-permitted clusters returns an empty result, not an error.

Request body

All fields are optional. Defaults below apply when a field is omitted.

FieldTypeDefaultDescription
group_byenumworkloadOne of workload, namespace, controller_kind, pod, container, deployment, statefulset, daemonset, node, instance_type. The cluster axis is not exposed on the public API — use /v1/organization/dashboard for fleet-wide cost breakdown.
cost_modeenumfully_loadedfully_loaded or workload_only. See Cost Modes.
start_datestring (YYYY-MM-DD)—Inclusive.
end_datestring (YYYY-MM-DD)—Inclusive.
pageinteger11-indexed.
per_pageinteger50Capped at 500 for normal requests, 10000 when export=true.
sort_bystringtotalCostAny field on a result row (e.g. workloadName, co2Kg).
sort_orderenumdescasc or desc.
searchstring—Substring match against the grouping dimension (workload name, namespace, etc.).
view_modeenumdetaildetail (per-resource rows) or grouped (aggregated rows).
filter_expressionobject—See Filter expression.
cluster_idsstring[]—UUIDs. Empty array means "all clusters the API key can access".
projectedbooleanfalseWhen true, scales partial-collection days up to a full 24-hour equivalent. When false, returns the observed cost (matches cloud billing).
exportbooleanfalseRaises the per_page cap to 10,000. UI clients should leave this false.
granularityenumdailydaily, weekly, or monthly. Time-bucket for daily-breakdown outputs.

Filter expression

A filter expression is a set of groups combined with AND or OR. Each group holds one or more field filters and one or more label filters; predicates within a group are always combined with AND.

json
1{
2  "filter_expression": {
3    "group_operator": "AND",
4    "groups": [
5      {
6        "filters": [
7          { "field": "namespace", "operator": "in", "values": ["prod", "staging"] }
8        ],
9        "label_filters": [
10          { "key": "team", "operator": "eq", "values": ["platform"] }
11        ]
12      }
13    ]
14  }
15}
Filter typeFieldOperators
filters[]field (any indexed dimension), operator, values[]eq, ne, in, not_in, contains
label_filters[]key (label name), operator, values[]eq, ne, exists, not_exists (values omitted for exists/not_exists)
group_operator—AND or OR (between groups).

Response

json
1{
2  "data": {
3    "items": [
4      {
5        "id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
6        "workloadName": "checkout-api",
7        "workloadKind": "Deployment",
8        "namespace": "prod",
9        "cluster": "c1a2b3c4-d5e6-7890-abcd-ef1234567890",
10        "clusterName": "prod-us-east",
11        "workloadUid": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
12        "pods": 12,
13        "totalCost": { "amount": "412.5300", "currency": "USD" },
14        "co2Kg": 7.4
15      }
16    ],
17    "summary": {
18      "periodCost": 412.53,
19      "previousPeriodCost": 387.10,
20      "changePercentage": 6.57,
21      "scannedResources": 248,
22      "queryTimeMs": 142,
23      "dataCompleteness": 0.99,
24      "topNamespace": "prod",
25      "topNamespaceCost": 287.42
26    },
27    "pagination": {
28      "page": 1,
29      "perPage": 50,
30      "totalCount": 248,
31      "totalPages": 5
32    },
33    "excludedClusterIds": []
34  },
35  "meta": {
36    "request_id": "req_01J5...",
37    "applied_at": "2026-05-21T10:30:00Z",
38    "cost_mode": "fully_loaded"
39  }
40}

Item fields

FieldTypeDescription
idstringStable row identifier within the response.
workloadNamestringResource name at the grouping dimension.
workloadKindstringResource kind (Deployment, StatefulSet, etc.).
namespacestringKubernetes namespace.
clusterstringCluster UUID.
clusterNamestringHuman-readable cluster name.
workloadUidstringKubernetes metadata.uid.
nodeUidstringOptional. Node UID; populated when the grouping dimension exposes it (e.g. group_by=pod, group_by=node).
podUidstringOptional. Pod UID; populated when the grouping dimension exposes it (e.g. group_by=pod, group_by=container).
podsintegerNumber of pods contributing to the row.
totalCostMoney{amount, currency}. amount is a decimal string.
co2KgnumberEstimated CO₂ emissions in kilograms for the period.

Summary fields

FieldTypeDescription
periodCostnumberTotal cost for the requested window.
previousPeriodCostnumberTotal cost for the equivalent prior window.
changePercentagenumber(periodCost − previousPeriodCost) / previousPeriodCost × 100.
scannedResourcesintegerDistinct resources touched by the query.
queryTimeMsintegerServer-side query duration.
dataCompletenessnumber[0,1] ratio of observed to expected data points for the window. Values below 0.98 indicate incomplete data for the period.
topNamespacestringNamespace contributing the most cost.
topNamespaceCostnumberCost for topNamespace.

Top-level response fields

items, summary, and pagination are documented above. The response also includes:

FieldTypeDescription
excludedClusterIdsstring[]Cluster UUIDs that were excluded from the aggregation (for example, clusters with no usage data). Clusters outside the API key's access do not appear in this list. Empty when no clusters were excluded. Sits at the response root, not inside summary.

Errors

HTTPerror.codeCause
400BAD_REQUESTMalformed body, unknown filter operator, unparseable date.
401UNAUTHORIZEDMissing or invalid Bearer token.
403FORBIDDENAPI key lacks cost_explorer:read.
413BAD_REQUESTBody exceeded the 1 MiB cap.
422VALIDATION_ERRORgroup_by, cost_mode, sort_order, view_mode, granularity, or operator value not in the allowed set.
422INVALID_COST_MODEcost_mode is not fully_loaded or workload_only.
429RATE_LIMITEDPer-key quota exceeded. Honor Retry-After.
500INTERNAL_ERRORUnhandled server error.
502UPSTREAM_UNAVAILABLEAn upstream service returned an error or was unreachable.
504UPSTREAM_TIMEOUTUpstream call exceeded the 60s deadline.

See Error Handling for the full catalog and retry guidance.

Example

Group spend by namespace across two clusters for the first week of May, sorted by total cost descending:

bash
1curl -X POST \
2  -H "Authorization: Bearer ka_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
3  -H "Content-Type: application/json" \
4  -d '{
5    "group_by": "namespace",
6    "cost_mode": "fully_loaded",
7    "start_date": "2026-05-01",
8    "end_date": "2026-05-07",
9    "page": 1,
10    "per_page": 100,
11    "sort_by": "totalCost",
12    "sort_order": "desc",
13    "cluster_ids": [
14      "c1a2b3c4-d5e6-7890-abcd-ef1234567890",
15      "c2b3c4d5-e6f7-8901-bcde-f23456789012"
16    ]
17  }' \
18  "https://public-api.kubeadapt.io/v1/cost-explorer/query"

See also

  • API Overview: base URL, envelope shape, the full endpoint index.
  • Permission Scopes: the cost_explorer:read scope and the cluster ACL model.
  • Cost Modes: the fully_loaded vs workload_only contract.
  • Error Handling: the full error code catalog including UPSTREAM_UNAVAILABLE and UPSTREAM_TIMEOUT.

Related

  • API Overview
  • Permission Scopes
  • Cost Modes
  • Error Handling
PreviousDepartmentsAPI ReferenceNextCost TrendsAPI Reference

On this page

  • Endpoint
  • Request body
  • Filter expression
  • Response
  • Item fields
  • Summary fields
  • Top-level response fields
  • Errors
  • Example
  • See also
Edit this page
Kubeadapt

Kubernetes FinOps platform. Cost visibility, rightsizing, and capacity planning that pays for itself in 30 days.

Product

  • Cost Monitoring
  • Cost Attribution
  • Workload Rightsizing
  • Recommendations
  • Smart Alerting
  • Best Practices
  • Network Cross-AZ

Resources

  • Documentation
  • Status Page
  • Feature Requests

Company

  • About Us
  • Security
  • Careers
  • Contact

© 2026 Kubeadapt. All rights reserved.

PrivacyTermsSecurity