Usage Tracking API
Get usage aggregation
Returns aggregated usage quantities by metric (total quantity, event count, first and last event timestamps) for volume reporting. Call it with a GET request to /usage/aggregation, authenticated with a restricted API key and the "usage:read" scope.
Returns aggregated usage quantities by metric (total quantity, event count, first and last event timestamps) for volume reporting. This endpoint returns no cost figures; for dollar amounts use GET /cost-data/summary or the other cost-data endpoints. Data sent via POST /usage-events aggregates under metricName `tokens`. Requests count toward your per-API-key rate limit; sustained overruns return 429 with the standard error envelope.
Authentication and scopes
Authenticate with a restricted API key in the Authorization: Bearer <key> header. This endpoint requires the usage:read scope.
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
start_date | query | string | Yes | Start of the aggregation range. ISO 8601 date or datetime (e.g. 2026-01-01 or 2026-01-01T00:00:00Z). Include an explicit UTC offset; date-only values are interpreted as UTC midnight. Must be strictly before end_date; the range may not exceed 365 days. |
end_date | query | string | Yes | End of the aggregation range. ISO 8601 date or datetime. Maximum range: 365 days. |
subscription_id | query | string | No | Optional: Filter by subscription ID. |
metric_names | query | string | No | Optional: Comma-separated list of metric names to include (max 50). Metric names are stored lowercase and matched exactly; pass lowercase values (e.g. tokens). |
Response fields
Fields returned in the 200 response body. Nested objects are listed under their parent. A field marked optional may be absent from the body; one marked nullable is always present but its value may be null.
| Field | Type | Description |
|---|---|---|
aggregations | object[] | Aggregated usage by metric. |
metric_name | string | Metric name. |
total_quantity | number (double) | Total quantity consumed. |
event_count | number (double) | Number of events. |
first_event_at | string | Timestamp of first event. |
last_event_at | string | Timestamp of last event. |
period_start | string | Start of the period. |
period_end | string | End of the period. |
total_events | number (double) | Total number of events in this period. |
Error codes
Errors return the standard error envelope with a code, message, and a correlationId you can quote to support.
| Status | When it happens |
|---|---|
400 | Invalid request parameters. Check that start_date and end_date are valid ISO 8601 dates, start_date is strictly before end_date, the range does not exceed 365 days, and metric_names lists at most 50 names. |
401 | Missing or invalid API key. Send your key as Authorization: Bearer YOUR_API_KEY. |
403 | Forbidden. The API key is missing the usage:read scope; create or update a key with that scope. |
404 | Subscription not found or not accessible with this API key. Check the subscription_id value. |
429 | Rate limit or plan quota exceeded. Slow down and retry after the current window resets. |
Rate limits and retries
Rate limit or plan quota exceeded. Slow down and retry after the current window resets.