The Cost V2 API (GET /v2/cost) returns real-time estimated costs for your cluster workloads. Filter by pod, namespace, label, controller name, or controller type, and aggregate results by any of those dimensions for cost trend analysis and internal reporting.
Prerequisites
Before you begin, complete the setup described in Overview of obtaining cost data using APIs.
API reference
Request syntax
GET /v2/cost
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
window |
string | Yes | Time range to query. Supported formats: <br>- today — the current day <br>- yesterday — the previous day <br>- week — the current week <br>- lastweek — the previous week <br>- month — the current month <br>- lastmonth — the previous month <br>- Duration: 30m (last 30 minutes), 12h (last 12 hours), 7d (last 7 days) <br>- RFC3339 date range: 2024-03-26T00:00:00Z,2024-03-27T00:00:00Z <br>- Unix timestamp range (seconds): 1711382400,1711468800 |
filter |
string | No | Filter results by resource category. Supported categories: namespace, controllerName (e.g., csi-plugin), controllerKind (e.g., DaemonSet, ReplicaSet, Job), pod, label (e.g., [app]:"nginx"). <br><br>To filter by multiple values in the same category, separate values with a comma: namespace:"default","kube-system". <br><br>To combine different categories, use a plus sign: namespace:"default"+label[app]:"nginx". |
step |
string | No | Time interval for splitting the response into multiple cost sets (e.g., 1d or 1w). If not specified, the entire window is returned as a single cost set. <br>Note
A cost set contains cost data for a Kubernetes object (such as a pod) over a specific time period. |
aggregate |
string | No | Dimension to aggregate results by. Supported values: <br>- namespace — aggregates across all namespaces in the cluster <br>- controller — aggregates by individual controllers <br>- controllerKind — aggregates by controller type (e.g., DaemonSet, ReplicaSet) <br>- label:<name> — aggregates by a specific label key <br>- node — aggregates by compute node |
idle |
boolean | No | Specifies whether to include idle costs in the response. Default: true. |
shareIdle |
boolean | No | Specifies whether to distribute idle costs across non-idle allocations. Default: false. |
shareSplit |
string | No | Policy for allocating idle costs. Valid values: <br>- weighted (default) <br>- even |
idleByNode |
boolean | No | Specifies whether to aggregate idle costs at the node level before distribution. Applies only when aggregate=node and shareIdle=false. Default: false. |
format |
string | No | Output format. Valid values: json (default), csv. |
Response parameters
| Parameter | Type | Description |
|---|---|---|
properties |
object | Properties of the associated Kubernetes object. |
pod |
string | Pod name. |
node |
string | Node name. |
namespace |
string | Namespace. |
controllerKind |
string | Controller type (e.g., DaemonSet, ReplicaSet). |
controller |
string | Controller name. |
providerID |
string | ID of the Elastic Compute Service (ECS) instance that corresponds to the node. |
labels |
map[string]string | Pod labels. Note
Prometheus supports only underscores ( |
start |
string | Start time of the cost set. |
end |
string | End time of the cost set. |
cpuCoreRequestAverage |
float | Average CPU cores requested over the period. |
cpuCoreUsageAverage |
float | Average CPU cores used over the period. |
ramByteRequestAverage |
float | Average memory requested over the period, in bytes. |
ramByteUsageAverage |
float | Average memory used over the period, in bytes. |
cost |
float | Estimated cost for the period. The default cost estimation policy uses a 100% CPU weight. To customize resource weights, see Cost estimation policies. |
costRatio |
float | This resource's cost as a fraction of total cluster cost (resource cost / total cluster cost). |
customCost |
float | Cost calculated using a custom cost estimation policy. |
(Optional) Step 1: Customize resource cost weights
By default, the Cost V2 API calculates costs using a 100% CPU weight ({"cpu": "1.0", "memory": "0.0"}). To use a mixed CPU and memory weighting, update the ack-alibaba-cloud-metrics-adapter Helm chart.
-
Log on to the ACK console. In the left navigation pane, click ACK consoleClusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click Applications > Helm.
-
On the Helm page, find
ack-alibaba-cloud-metrics-adapterand click Update in the Actions column. -
In the YAML file, update the
AlibabaCloudMetricsAdapter.costWeightsparameter, then click OK.
For details on mixed-resource cost estimation, see Cost estimation policies.
Step 2: Query cost data
All examples use curl to access the Kubernetes API via client certificate authentication. For setup instructions, see Use the Kubernetes API.
Example 1: Query yesterday's DaemonSet costs
Filters by namespace, controller type, and label to return per-pod cost data for yesterday.
Request
curl -G -k --cert ./client-cert.pem --key ./client-key.pem \
-d 'window=yesterday' \
-d 'filter=namespace:"kube-system"+controllerKind:"DaemonSet"+label[app]:"terway-eniip"' \
"$APISERVER/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/v2/cost" | jq .
Sample response
Example 2: Query hourly pod costs over a 3-hour window
Uses step=1h to split a 3-hour window into three separate cost sets, each covering one hour.
Request
curl -G -k --cert ./client-cert.pem --key ./client-key.pem \
-d 'window=2024-03-24T00:00:00Z,2024-03-24T03:00:00Z' \
-d 'step=1h' \
-d 'filter=namespace:"kube-system"+pod:"terway-eniip-kz68n"' \
"$APISERVER/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/v2/cost" | jq .
Sample response
Example 3: Query costs aggregated by the app label
Uses aggregate=label:app to group costs by the app label value.
Request
curl -G -k --cert ./client-cert.pem --key ./client-key.pem \
-d 'window=2h' \
-d 'aggregate=label:app' \
"$APISERVER/api/v1/namespaces/kube-system/services/ack-metrics-adapter-api-service:8080/proxy/v2/cost" | jq .
Sample response
What's next
The Allocation API combines bill data with cluster cost data to provide amortized costs for reconciliation. See Obtain data using the Allocation API.