Skip to main content
Version: 3.6.0

Export API key usage

You can export your tenant's token usage per API key as a CSV file in two ways: download it from the CM portal, or call the export endpoint.

Download from the CM portal​

  1. On the Usage page, set the period with Time range, or with From and To.
  2. Select Export API-key CSV.

For more about the Usage page, see Monitor tenant usage.

Call the export endpoint​

POST /cmind.metering.v1.TenantUsageService/ExportTokenUsageByApiKey

Download one CSV file with token usage for every attributed API key in a tenant. The caller must be a tenant administrator for that tenant.

Request Fields:

  • window (required): The time range, with a start and an end. end must be after start.

The time range includes start and excludes end.

The request does not name a tenant. The tenant comes from the credential you call with: an API key belongs to one tenant, and a user token must send the tenant ID in the X-Cm-Tenant-Id header. A call that names no tenant fails with permission_denied.

Response Fields:

  • filename: Suggested filename, such as api-key-usage-2026-08-01T000000Z-to-2026-08-06T000000Z.csv
  • csv: CSV file contents as bytes

CSV Columns:

ColumnDescription
period_start_utcStart of the requested range, in UTC
period_end_utcEnd of the requested range, in UTC
api_key_idStable API key ID, to distinguish keys with the same name
modelInternal model resource name stored with the usage
input_tokensTokens sent in requests
output_tokensTokens returned in responses
embedding_tokensTokens used for embedding
rerank_tokensTokens used for reranking
audio_duration_msLength of audio submitted for transcription, in milliseconds
api_key_nameCurrent display name, as shown in the portal
api_key_prefixCurrent key prefix, as shown in the portal; never the full secret
model_display_nameCurrent display name; empty when unset
model_public_idPublic ID of the underlying model, used to invoke it directly

The file has one row for every pair of API key and model. There is no summary row for a key and no total column. To get a key's token total, add its rows and its four token columns together in a spreadsheet or in your own code. audio_duration_ms is not a token count, so leave it out of that sum.

Rows are ordered by API key ID, and by model within each key. Revoked keys with usage are included. Key names and prefixes describe the key at export time, not at the time of each request. Model metadata also reflects the current model resource. The model fields are separate: an unset display name stays empty. Model display names and public IDs are empty when the caller cannot see the model in the selected tenant, the resource no longer exists, or a deployment and an external model have the same resource name. The stored resource ID and usage stay in the export. Usage through an alias is attributed to its underlying model. If a key is absent from the caller's key lists, its name and prefix are empty, but its ID and usage stay in the export.

The file uses UTF-8 with a byte-order mark and CRLF line endings so Excel can open names with non-ASCII characters. This changes the file's leading bytes: programmatic readers must use a BOM-aware decoder, such as Python's encoding="utf-8-sig", or remove the leading U+FEFF before parsing the CSV. Otherwise the first header can be read as \ufeffperiod_start_utc instead of period_start_utc.

Text that starts with a spreadsheet formula marker has a leading apostrophe. Token counts and audio duration remain exact decimal integers.

The export is not paginated and has no row limit. It includes every API key with attributed usage in the requested range. If no key has usage, the file contains only the header row.

Only usage that the platform can attribute to an API key is included. Requests made without an API key are omitted, so the CSV totals can be lower than the tenant totals shown in the usage views.

The request fails with invalid_argument if window is missing, if its start or end is missing, or if end is not after start.

The export reads current API key and model information before it creates a file with usage rows. If a lookup fails, the request returns an error, such as unavailable, and no CSV file. For unavailable, try the export again later.