Cloud Cost API

The Cloud Cost API cannot be used until you have enabled Cloud Cost via Helm. See Kubecost's Cloud Cost Explorer doc for instructions.

Intro to Cloud Cost API

The Cloud Cost API provides multiple endpoints to obtain accurate cost information from your cloud service providers (CSPs), including data available from cloud billing reports (such as AWS' Cost and Usage Report (CUR)).

There are three distinct endpoints for using the Cloud Cost API. The default endpoint for querying Cloud Costs should be /model/cloudCost/view.

Cloud Cost View API

GET http://<your-kubecost-address>/model/cloudCost/view

Samples full granularity of cloud costs from cloud billing report (ex. AWS' Cost and Usage Report)

Path Parameters

Name
Type
Description

window*

String

Window of the query. Only accepts daily intervals, example window=3d.

costMetric

String

Determines which cloud cost metric type will be returned. Acceptable values are AmortizedNetCost, InvoicedCost, ListCost, and NetCost. Default is AmortizedNetCost.

aggregate

String

Field by which to aggregate the results. Accepts: invoiceEntityID, accountID, provider, service, and label:<name>. Supports multi-aggregation using comma-separated lists. Example: aggregate=accountID,service

filterInvoiceEntityIDs

String

Filter for account

filterAccountIDs

String

GCP only, filter for projectID

filterProviders

String

Filter for cloud service provider

filterProvidersID

String

Filter for resource-level ID given by CSP

filterServices

String

Filter for cloud service

filterCategories

String

Filter based on object type

filterLabels

String

Filter for a specific label. Does not support filtering for multiple labels at once.

{
    "code": 200,
    "data": {
        "graphData": [
            {
                "start": "",
                "end": "",
                "items": []
            }
        ],
        "tableTotal": {
            "name": "",
            "kubernetesPercent": 0,
            "cost": 0
        },
        "tableRows": []
    }
}

The endpoint /model/cloudCost/top will use all parameters of /model/cloudCost/view listed above, except for CostMetric. This is because /top samples full granularity from your cloud billing reports and will return information for all four accepted metric types (see below for more information on these types).

The endpoint /view contains all parameters for /model/CloudCost/aggregate, and if your /view query parameters are in a subset of /aggregate, your payload will be pulled from /aggregate instead (this payload will return a larger amount of information than /view). Otherwise, your /view query will pull from /top.

Cloud Cost Aggregate API

GET http://<your-kubecost-address>/model/cloudCost/aggregate

Query cloud cost aggregate data

Path Parameters

Name
Type
Description

window*

string

Window of the query. Accepts all standard Kubecost window formats (See our doc on using the window parameter).

aggregate

string

Field by which to aggregate the results. Accepts: invoiceEntityID, accountID, provider, service, and label:<name>. Supports multi-aggregation using comma-separated lists. Example: aggregate=accountID,service

filterInvoiceEntityIDs

string

Filter for account

filterAccountIDs

string

GCP only, filter for projectID

filterProviders

string

Filter for cloud service provider

filterServices

string

Filter for cloud service

filterLabel

String

Filter for a specific label. Does not support filtering for multiple labels at once.

```json
{
    "code": 200,
    "data": {
        "sets": [
            {
                "cloudCosts": {
                    "": {
                        "properties": {
                            "provider": "",
                            "invoiceEntityID": ""
                        },
                        "window": {
                            "start": "",
                            "end": ""
                        },
                        "listCost": {
                            "cost": ,
                            "kubernetesPercent":
                        },
                        "netCost": {
                            "cost": ,
                            "kubernetesPercent":
                        },
                        "amortizedNetCost": {
                            "cost": 5,
                            "kubernetesPercent": 
                        },
                        "invoicedCost": {
                            "cost": ,
                            "kubernetesPercent": 
                        }
                    }
                },
                "window": {
                    "start": "",
                    "end": ""
                },
                "aggregationProperties": [
                    ""
                ]
            }
        ],
        "window": {
            "start": "",
            "end": ""
        }
    }
}

Using the CostMetric parameter

Using the endpoint /model/cloudCost/top will accept all parameters of model/cloudCost/view except for MetricCost.

CostMetric values are based on and calculated following standard FinOps dimensions and metrics. The four available metrics supported by the Cloud Cost API are:

CostMetric value
Description

NetCost

Costs inclusive of discounts and credits. Will also include one-time and recurring charges.

AmortizedNetCost

NetCost with removed cash upfront fees and amortized

ListCost

CSP pricing without any discounts

InvoicedCost

Pricing based on usage during billing period

Providing a value for CostMetric is optional, but it will default to AmortizedNetCost if not otherwise provided.

Understanding kubernetesPercent

Each CostMetric also has a kubernetesPercent value. Unaggregated, this value will be 0 or 1. When you aggregate, kubernetesPercent is determined by multiplying the costMetric cost by its kubernetesPercent and aggregating that value as kubernetesCost for that costMetric. That kubernetesCost is then divided by the aggregated total costs to determine the new kubernetesPercent. Since this process results in unique values for each costMetric, this value is included as part of the cost metric.

Examples

Query for cloud costs within the past three days, aggregated by cloud service, filtered for only services provided by AWS

http://<your-kubecost-address>/model/cloudCost/aggregate?window=3d&aggregate=service&filterProviders=AWS

Query for cloud net costs within the past two days, aggregated by accounts, filtered only for Amazon EC2 costs

http:/<your-kubecost-address>/model/cloudCost/view?window=2d&filterServices=AmazonEC2&aggregate=invoiceEntityID

Last updated