Anthropic usage API
The Anthropic usage API exposes per-tenant aggregated usage data sourced from the Anthropic organisation usage report.
The data is populated by a sync job that runs shortly after start-up and then every hour. For each tenant that has an anthropic-admin key stored, it reads the usage report of the last 30 days and stores per-tenant totals in the local database.
Reading tenant usage
GET /admin/v1/tenants/<ID>/anthropic-usage
Required permission: COGS_VIEW (a tenant_admin gate-class permission), and access to the tenant <ID>. Without the permission the request is rejected with 403.
Returns aggregated input tokens, output tokens, cache reads, cache writes, and cost per day for the requested tenant.
Optional query parameters:
| Parameter | Description |
|---|---|
from |
Inclusive lower bound, formatted as YYYY-MM-DD (a real calendar date, year 2000–2100). Send it together with to. |
to |
Inclusive upper bound, formatted as YYYY-MM-DD (same rule). Send it together with from. |
Send both bounds or neither. With neither (absent or empty) the window is the last 30 days, ending today (UTC). An empty value counts as absent.
Rejected input (always 400 with "code": "bad_param", nothing is read): a from / to that is not a real YYYY-MM-DD calendar date (2026-13-99, 2023-02-29, 20260101, a year outside 2000–2100); a repeated parameter (?from=…&from=…); only one of the two bounds (?to=2026-01-01 alone, or ?from= with a value and to absent or empty: "from and to must be given together" — the other end is never guessed); from later than to (from == to is one day and is accepted). A request with more than 100 query parameters is refused 400 too_many_params rather than having a bound silently dropped as "absent".
Rows are ordered by snapshot_date (newest first), then by model. A storage failure returns 500; the endpoint never answers with zero totals in that case.
The response is an object with three keys:
| Key | Description |
|---|---|
daily |
Array of usage rows grouped by day and by source, model, and service_tier — so a single day can produce several rows. Each row carries snapshot_date, source, model, service_tier, fetched_at, and the same token/cost fields as totals (uncached_input_tokens, output_tokens, cache_write_5m_tokens, cache_write_1h_tokens, cache_read_tokens, web_search_requests, cost_usd). fetched_at is unix seconds. |
totals |
Aggregate totals across the range, with uncached_input_tokens, output_tokens, cache_write_5m_tokens, cache_write_1h_tokens, cache_read_tokens, web_search_requests, and cost_usd. cost_usd is a decimal string (8 decimal places), not a number. |
last_synced_at |
Timestamp (unix seconds) of the most recent successful sync for the returned data; null when the range holds no synced rows. |
Triggering a sync
POST /admin/v1/anthropic-usage/sync
Required permission: COGS_VIEW.
Triggers a sync of the last 30 days for every tenant that has an anthropic-admin key, not only the caller's tenant. The sync runs asynchronously in the background; the endpoint returns immediately with { "ok": true, "message": "sync triggered" } and does not wait for the sync to finish or report a record count.