Skip to main content

Query API Key Usage

Query a Regular API Key's usage.

Request Parameters

ParameterRequiredDefaultDescription
start_dateYesNoneUTC start date, inclusive
end_dateYesNoneUTC end date, inclusive
granularityNodailydaily, hourly, or model
limitNo100Bucket page size, 1–100
cursorNoNonenext_cursor returned by the previous page

Response Example

{
"total_usage": 1.6,
"total_tokens": 12500,
"total_requests": 8,
"data": [
{
"start": "2026-08-04T00:00:00Z",
"usage": 1.6,
"tokens": 12500,
"requests": 8
}
],
"by_model": [
{
"model": "gpt-4.1",
"usage": 1.6,
"tokens": 12500,
"requests": 8
}
],
"complete": true,
"retention_start": "2026-08-01T00:00:00Z",
"cursor": "",
"has_more": false,
"next_cursor": null
}

Notes:

  • The unit of total_usage and each bucket's usage is US dollars;
  • When granularity=model, data elements use the model field instead of start;
  • complete=false means the retention watermark has not yet been established, or the query range is earlier than the current log retention scope;
  • When has_more=true, the next page must use exactly the same key, date range, and granularity, and carry next_cursor;
  • The usage snapshot is valid for 15 minutes. If the snapshot expires or the retention watermark changes, 409 usage_snapshot_expired is returned; retry from the first page without the cursor;
  • If consumption logs are not enabled or details are unavailable, 503 usage_detail_unavailable is returned.
Snapshot and Cursor

The usage snapshot is valid for 15 minutes. If the snapshot expires or the retention watermark changes, 409 usage_snapshot_expired is returned; re-query from the first page without the cursor. When has_more=true, the next page must use exactly the same key, date range, and granularity, and carry next_cursor.

Related Endpoints

For general request conventions, data structures, and error codes, see the Key Management API overview.

Online Service