> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.mixlayer.com/api-reference/platform-api/billing-accounts/get-usage-spend-for-billing-account/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.mixlayer.com/_mcp/server. # Get billing usage spend GET https://api.mixlayer.com/v1/billing_accounts/{billing_account_id}/usage_spend When authenticated with an API key, this operation requires `api-read`. Reference: https://docs.mixlayer.com/api-reference/platform-api/billing-accounts/get-usage-spend-for-billing-account ## Authentication - `Authorization` header (bearer token, required) — Console user session or Mixlayer API key supplied as a Bearer token. ## Request ### Path parameters - `billing_account_id` (string, required) — Billing account ID ### Query parameters - `range` (V1BillingAccountsBillingAccountIdUsageSpendGetParametersRange, optional, default: 30d) — Reporting range: `30d`, `90d`, or `ytd`; defaults to `30d`. ## Response ### 200 Usage spend report - `data` (ApiDataResponseUsageSpendResponseData, required) — Billing usage spend for a requested date range. ## Errors ### 400 Bad Request Error Query parameters are missing or invalid. - `error` (ApiErrorBody, required) — Structured error details. ### 401 Unauthorized Error Authentication is missing or invalid. - `error` (ApiErrorBody, required) — Structured error details. ### 403 Forbidden Error The authenticated principal cannot perform this operation. - `error` (ApiErrorBody, required) — Structured error details. ### 404 Not Found Error The requested resource is not visible to the authenticated principal. - `error` (ApiErrorBody, required) — Structured error details. ### 500 Internal Server Error An unexpected server or database error occurred. - `error` (ApiErrorBody, required) — Structured error details. ## Types ### V1BillingAccountsBillingAccountIdUsageSpendGetParametersRange ### ApiDataResponseUsageSpendResponseData Billing usage spend for a requested date range. - `bucket_ms` (long, required) — Width of each reporting bucket in milliseconds. - `buckets` (list of UsageSpendBucket, required) — Spend grouped by date and model. - `models` (list of UsageSpendModel, required) — Total spend grouped by model. - `range_end` (datetime, required) — Exclusive end of the reporting range. - `range_start` (datetime, required) — Inclusive start of the reporting range. ### ApiErrorBody Structured error details returned by the platform API. - `message` (string, required) — Human-readable error message. - `code` (string, optional, nullable) — Stable machine-readable error code, when available. - `details` (any, optional) — Error-specific structured context, when available. ### UsageSpendBucket Usage spend for one reporting bucket. - `date` (string, required) — Bucket date formatted as `YYYY-MM-DD`. - `model_totals_cents` (map from string to long, required) — Spend in cents keyed by model SKU. - `t0` (long, required) — Inclusive bucket start as Unix milliseconds. - `t1` (long, required) — Exclusive bucket end as Unix milliseconds. - `total_cents` (long, required) — Total spend in the bucket, in cents. ### UsageSpendModel Total usage spend for one model. - `model` (string, required) — Model SKU. - `total_cents` (long, required) — Total usage spend in cents. ## Examples **Response** ```json { "data": { "bucket_ms": 1, "buckets": [ { "date": "string", "model_totals_cents": {}, "t0": 1, "t1": 1, "total_cents": 1 } ], "models": [ { "model": "string", "total_cents": 1 } ], "range_end": "2024-01-15T09:30:00Z", "range_start": "2024-01-15T09:30:00Z" } } ``` **SDK Code** ```python import requests url = "https://api.mixlayer.com/v1/billing_accounts/billing_account_id/usage_spend" headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.mixlayer.com/v1/billing_accounts/billing_account_id/usage_spend'; const options = {method: 'GET', headers: {Authorization: 'Bearer '}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.mixlayer.com/v1/billing_accounts/billing_account_id/usage_spend" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.mixlayer.com/v1/billing_accounts/billing_account_id/usage_spend") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.mixlayer.com/v1/billing_accounts/billing_account_id/usage_spend") .header("Authorization", "Bearer ") .asString(); ``` ```php request('GET', 'https://api.mixlayer.com/v1/billing_accounts/billing_account_id/usage_spend', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ```