Skip to main content

Get Consumption by API Key (Admin)

Per-key credit consumption with per-tool breakdown for the calling org. Includes deleted/rotated keys (with deleted: true) for historical attribution. Without api_key_id: all keys with attributed usage. Requires an admin-scoped API key.

Parameters

NameTypeDefaultDescription
api_key_idstring-Filter to a single API key. When omitted, all keys with attributed usage in the window are returned.
fromstring-ISO datetime; window start.
tostring-ISO datetime; window end.
daysinteger-Window in days (1-366). Mutually exclusive with from/to.

Use Cases

  • Which API key drove a sudden credit spike this week? — per-key attribution for incident response
  • Attribute historical usage to a rotated or deleted key (returned with deleted: true)
  • Which tools is a single API key spending credits on? — per-tool breakdown for one key

Example Usage

All keys with attributed usage over the last 7 days

{
"tool": "admin_get_consumption_by_api_key",
"arguments": {
"days": 7
}
}

Single key over an explicit window

{
"tool": "admin_get_consumption_by_api_key",
"arguments": {
"api_key_id": "3f7c2b1a-9d4e-4c2a-8b1f-0a1b2c3d4e5f",
"from": "2026-08-01T00:00:00Z",
"to": "2026-08-27T00:00:00Z"
}
}

Response Format

FieldTypeDescription
apiKeysarrayPer-key consumption rows for the resolved window, sorted by credits desc.
apiKeys[].apiKeyIdstring
apiKeys[].apiKeyNamestring
apiKeys[].apiKeyPrefixstring
apiKeys[].creatorEmailstring | null
apiKeys[].authMethodstring
apiKeys[].oauthClientIdstring | null
apiKeys[].oauthClientNamestring | null
apiKeys[].deletedbooleanTrue if the underlying api_keys row no longer exists (rotated/deleted). Historical consumption is preserved for audit.
apiKeys[].callCountintegerBillable calls (excludes cache hits) within the window.
apiKeys[].creditsnumber
apiKeys[].byToolarray
apiKeys[].byTool[].toolNamestring
apiKeys[].byTool[].callCountinteger
apiKeys[].byTool[].creditsnumber
fromstringStart of the consumption window (inclusive), ISO string.
tostringEnd of the consumption window (exclusive), ISO string.