# Claude usage export
Source: https://greenpixie.com/docs/guides/ai-usage-data/claude

How to pull token counts and cost per model from the Claude Admin APIs.

Anthropic reports usage through two Admin APIs. The Usage and Cost Analytics API covers everything billed through your Claude Console organisation, including Claude Code, with token counts per model, and is the one to use. The Claude Code Analytics API adds per-developer productivity metrics. Both return JSON that flattens to a CSV table in a few lines of code.

## Usage and Cost Analytics API [#usage-and-cost-analytics-api]

You need an Admin API key for your Claude Console organisation. Organisation admins create these from the Console; the Admin API is not available on individual accounts. For a Claude Enterprise organisation, the primary owner creates a key with the `read:analytics` scope in claude.ai instead.

1. Create a dedicated Admin API key for the export and store it in your secrets manager.
2. Call `GET https://api.anthropic.com/v1/organizations/analytics/usage` for token counts, and `GET https://api.anthropic.com/v1/organizations/analytics/cost` for spend. Send the key in `x-api-key`, with `anthropic-version` and the beta header shown below.
3. Set `starting_at` and `ending_at` in RFC 3339, a bucket width of `1d`, and `group_by[]=model`. A request can span at most 31 days, so loop month by month for a longer baseline.
4. Follow `next_page` until `has_more` is false, then write the rows out as CSV.

```bash
curl "https://api.anthropic.com/v1/organizations/analytics/usage?\
starting_at=2026-10-01T00:00:00Z&ending_at=2026-11-01T00:00:00Z&\
time_bucket_width=1d&group_by[]=model&order_by=time&limit=1000" \
  -H "x-api-key: $ANTHROPIC_ADMIN_KEY" \
  -H "anthropic-version: 2026-10-21" \
  -H "anthropic-beta: analytics-usage-cost-2026-08-24"
```

Each row carries `starting_at`, `ending_at`, the `group` you asked for and a `usage` object with `uncached_input_tokens`, `cache_creation`, `cache_read_input_tokens`, `output_tokens`, `total_tokens` and `requests`. You can group by up to five dimensions, including `workspace_id`, `api_key_id`, `service_tier`, `product` and `actor`, and filter with `models[]`, `workspace_ids[]` or `api_key_ids[]`. The cost endpoint returns `amount` and `list_amount` as strings in US cents. To isolate Claude Code spend, call the cost endpoint with `products[]=claude_code&group_by[]=actor`.

Data refreshes within about four hours and can take up to 24. Figures can still move until roughly seven days after a month ends, so for a final baseline query months that closed at least a week ago. `starting_at` must be on or after 1 January 2026 and within the last 365 days. Claude on Amazon Bedrock and Google Cloud is also supported, using cloud credentials in place of the Admin key.

## Claude Code Analytics API [#claude-code-analytics-api]

If your developers use Claude Code through the Console organisation, this endpoint returns one record per user per day with sessions, lines of code, commits, pull requests, tool acceptance rates and a per-model token breakdown with an estimated cost. It covers one day per call.

```bash
curl "https://api.anthropic.com/v1/organizations/usage_report/claude_code?starting_at=2026-10-01" \
  -H "x-api-key: $ANTHROPIC_ADMIN_KEY" \
  -H "anthropic-version: 2026-10-21"
```

Each record has `date`, an `actor` (a user email or an API key name), `customer_type`, `terminal_type`, `core_metrics`, `tool_actions` and a `model_breakdown` list with `tokens.input`, `tokens.output`, `tokens.cache_read`, `tokens.cache_creation` and `estimated_cost` per model. Page with `next_page` and loop the date to build a range.

Only usage authenticated against the Console organisation is returned. Claude Code used on Pro, Max, Team or Enterprise subscriptions is attributed to claude.ai and reported through the Claude Enterprise Analytics API or the claude.ai analytics dashboard instead. Usage through Bedrock, Foundry or Vertex AI is not included.

## Check the export worked [#check-the-export-worked]

You should have:

* One row per day per model for the full date range, with `uncached_input_tokens`, `cache_read_input_tokens` and `output_tokens` populated.
* No gaps where a request spanned more than 31 days, and the most recent week treated as provisional.
* If you use Claude Code through the Console, a matching per-user daily file from the Claude Code Analytics API.

## Next steps [#next-steps]

Once you have the export, send it to Greenpixie for enrichment with energy, carbon and water metrics, or enrich it yourself using the API.

- [Enriching your usage data using the API](https://greenpixie.com/docs/guides/enrich-api): Pull the rate card and enrich the data yourself, in your own environment.
- [Connect your data for Greenpixie to enrich it](https://greenpixie.com/docs/guides/connect-data): Grant Greenpixie access to your bucket or container for managed enrichment.

## References [#references]

* [Usage and Cost Analytics API](https://platform.claude.com/docs/en/manage-claude/usage-cost-analytics-api)
* [Claude Code Analytics API](https://platform.claude.com/docs/en/manage-claude/claude-code-analytics-api)