Usage export API
GET https://opencode.ai/console/api/v2/usage/export returns a workspace’s usage as CSV, with one row per UTC day,
member or service account, provider, and model. It’s the same file the Export usage button downloads from
Activity › Usage.
curl --fail-with-body "https://opencode.ai/console/api/v2/usage/export?range=30d" \
--header "Authorization: Bearer oc_sk_..." \
--output usage-30d.csvSend an API key as a bearer token. The key exports the workspace it was created in.
Authorization: Bearer oc_sk_...The key needs Usage › Read. Keys with All or Read only have it. A restricted key needs:
Permissions: Restricted
Usage: ReadUse a service account key for scheduled exports, or an owner’s or admin’s
personal API key. Members can’t read workspace usage, so their
keys return 403.
| Parameter | Required | Value |
|---|---|---|
range | Yes | 7d, 30d, or 90d. |
user_id | No | A member ID (user_...) or service account ID (svcacct_...). Returns only that member’s or service account’s rows. |
range counts UTC days and includes today, so 7d is today and the six days before it. Today’s rows keep growing
until midnight UTC.
To export one service account’s usage, pass its ID from the user_id column of an earlier export:
curl --fail-with-body "https://opencode.ai/console/api/v2/usage/export?range=7d&user_id=svcacct_01JD8Z4Q2W7N3K5M6P9R0S1T2V" \
--header "Authorization: Bearer oc_sk_..."An ID that isn’t in the workspace returns only the header row.
A successful request returns 200 with Content-Type: text/csv; charset=utf-8. The first line is the header. Rows
follow, newest day first.
day,user_type,user_id,user_name,provider,model,requests,input_tokens,output_tokens,cache_read_tokens,cache_write_5m_tokens,cache_write_1h_tokens,cost_micro_cents,cost_usd
2026-11-24,service_account,svcacct_01JD8Z4Q2W7N3K5M6P9R0S1T2V,CI Pipeline,opencode,claude-sonnet-5-5,412,1830211,96402,5120330,210044,0,1512334800,15.123348
2026-11-24,member,user_01JC2X7Y8Z9A0B1C2D3E4F5G6H,ada@example.com,opencode,claude-haiku-5-5,57,402118,31877,880012,0,0,214500000,2.145
2026-11-23,member,user_01JC2X7Y8Z9A0B1C2D3E4F5G6H,ada@example.com,opencode,claude-sonnet-5-5,96,711560,48210,2204118,61022,0,587000000,5.87- Lines end with
\r\n. - Days without usage have no rows.
- The response is a download (
Content-Disposition: attachment; filename="usage-30d.csv") and is never cached (Cache-Control: private, no-store). - A text cell that starts with
=,+,-, or@gets a leading', so spreadsheets don’t run it as a formula.
| Column | Meaning |
|---|---|
day | The UTC date, as YYYY-MM-DD. |
user_type | member or service_account. |
user_id | The member’s or service account’s ID. |
user_name | The member’s email, or the service account’s name. Can be empty. |
provider | The provider that served the requests, such as opencode for OpenCode Models. |
model | The model ID. |
requests | Number of requests. |
input_tokens | Input tokens. |
output_tokens | Output tokens. |
cache_read_tokens | Tokens read from the prompt cache. |
cache_write_5m_tokens | Tokens written to the prompt cache with a 5-minute lifetime. |
cache_write_1h_tokens | Tokens written to the prompt cache with a 1-hour lifetime. |
cost_micro_cents | Cost as a whole number of micro-cents. One US dollar is 100000000. |
cost_usd | The same cost in US dollars, as an exact decimal with at least two decimal places, such as 2.145 or 0.00. |
- Every model request made by the workspace’s members and service accounts.
- Requests to free models, and requests members make through their own Claude Code, Codex, or OpenCode subscriptions, are included with their tokens at zero cost.
- Web search and other hosted services aren’t included.
- Totals can trail new requests by about a minute.
- An export covers at most 90 days. To keep longer history, save the files on a schedule.
- Requests count toward the Console API’s limit of 300 requests per minute per account, shared with its other endpoints. Personal API keys count against the member who owns them.
| Status | Meaning |
|---|---|
400 | range is missing or isn’t 7d, 30d, or 90d, or user_id isn’t a member or service account ID. |
401 | No credentials, or an expired or revoked key. |
403 | The key doesn’t have Usage › Read, or it belongs to a member who isn’t an owner or admin. |
429 | Over the rate limit. Retry after the number of seconds in the Retry-After header. |
503 | Daily totals aren’t available yet. Retry the request later. |