Who this is for: Organization owners and the teams who need their organization’s usage and estimated cost in their own tools.The Analytics API is a read-only HTTP API that returns your organization’s token usage and estimated cost, from the same metering as the Analytics page. It can return figures for each member, with the member’s name and email address. It doesn’t return conversation content, files, or anything your users type into Claude.
Get access to the Analytics API
The API is off by default. To start using it:- As an Owner or a Primary Owner, go to Settings > Config in the organization admin portal, expand Analytics API under Admin Console, turn on its switch, and click Save changes.
- As a Primary Owner, create an admin API key with Usage and cost reports selected.
Send a request to the Analytics API
Send a GET request to one of these paths on your Claude for Government host, which is the domain name in the address of your organization admin portal:/gateway-api/v1/organizations/analytics/usagefor token usage/gateway-api/v1/organizations/analytics/costfor estimated cost
x-api-key header. Every request also needs the anthropic-beta header while the API is in beta. This request returns token usage for each model:
Query parameters
The/usage and /cost paths accept these parameters. To give a parameter that ends in [] several values, repeat it, as in products[]=desktop&products[]=m365. With curl, add --globoff so that it doesn’t interpret the [].
A misspelled model or member ID returns no rows, not an error.
Daily rows run from midnight to midnight UTC, whatever offset you send. The API rounds both ends of the range down, to midnight UTC for daily rows and to the hour otherwise. To include today in daily rows, set
ending_at to tomorrow’s date at 00:00:00Z.
Read the response
Each row indata covers one period and one combination of the fields you group by. A day, hour, member, product, or model with no usage has no row. Count a missing row as zero if its period ends at or before data_refreshed_at. This is a response to the example request for one week, shortened to one row and three of the group fields:
/cost has cost in place of usage. This one, shortened the same way, is from a request with group_by[]=actor:
amount is in US cents, so "288.678000" is about $2.89.
The usage and cost responses have these fields.
What the estimated cost covers
amount covers usage on self-managed tiers. It is an estimate, not your invoice.
Anthropic-managed tiers. If your agency buys seats, usage on those tiers is covered by the seat price, so it adds
0 to amount. The API’s token and request figures still include it, and the Analytics page shows these tiers separately.When totals differ from the Analytics page
A total can differ from the one on the Analytics page for these reasons:- Anthropic-managed tiers: see What the estimated cost covers.
- Cached input:
total_tokensincludes input written to or read from the prompt cache, and the page’s token figures don’t. The page’s input tokens areuncached_input_tokens. - Time: the page shows times in your browser’s time zone and includes the latest usage.
How current the figures are
The figures are one to two hours behind, and run up todata_refreshed_at. For example, a request sent at 15:30 UTC returns usage up to 14:00. When a row’s ending_at is later than data_refreshed_at, the row covers only part of its period, so read it again later. When data_refreshed_at is null, no usage in the range is available yet.
A request to Claude is counted when it ends, in the hour it started, so an hour’s figures can still rise after you read them.
Read every page of results
Whilehas_more is true, send the same request again with page set to the value of next_page. Send the other parameters as they were. You can change limit. To read many rows, set limit to 1000.
Rate limits
An organization can send about 60 requests per minute, across all its keys, and four at the same time. A request over either limit returns a 429 error.Troubleshoot errors
An error response is JSON. Itserror object has a message, and can have a code and a request_id to give your Anthropic representative.