---
title: How do you track Claude API spend per agent with Anthropic's usage and cost APIs?
url: https://opencontroller.lyzr.com/blog/anthropic-usage-and-cost-api-for-agent-spend
published: 2026-11-15
updated: 2026-11-15
author: Lyzr
---

# How do you track Claude API spend per agent with Anthropic's usage and cost APIs?

**Give each agent its own API key or workspace, then pull usage grouped by `api_key_id` and cost grouped by workspace from Anthropic's Admin API. That maps provider spend to agents with about five minutes of delay. It cannot see agent versions, end users, or Claude calls made through Amazon Bedrock or Google Cloud, so treat it as the provider-side half of attribution.**

Finance teams ask for this as soon as Claude spend shows up as one line on an invoice. The data exists. The work is in structuring keys so the data means something.

## Which Anthropic endpoints report usage and cost?

| Endpoint | What it returns | Granularity | Useful groupings |
|---|---|---|---|
| `/v1/organizations/usage_report/messages` | Token counts: uncached input, cached input, cache creation, output; server tool use | `1m`, `1h` or `1d` buckets | API key, workspace, model, service tier, context window, inference geo, speed |
| `/v1/organizations/cost_report` | Cost in USD, as decimal strings in cents | `1d` only | Workspace, description (parsed into model and geo) |

Both need an Admin API credential; workspace keys do not work. Bucket limits matter for dashboards: up to 1,440 one-minute buckets, 168 hourly buckets or 31 daily buckets per request.

Anthropic now labels these two endpoints legacy and recommends the newer Usage and Cost Analytics API for new integrations, which adds more grouping and filtering dimensions, including cost by API key. Claude Enterprise organizations use an Analytics API key instead of an Admin key.

## How should you structure keys so spend maps to agents?

Provider data can only be as granular as your credentials. Pick one pattern and enforce it:

1. **One key per production agent.** Name the key with the agent's registry ID. Usage grouped by `api_key_id` then equals usage per agent.
2. **One workspace per team or product, one key per agent inside it.** Workspaces give you cost by team and spend limits; keys give you the agent split.
3. **No shared keys across agents.** A shared key collapses attribution and makes revocation dangerous. Our post on [workspaces for agent spend limits](/blog/anthropic-workspaces-for-agent-spend-limits) covers the limit side.

Keep a mapping table of key ID to agent ID to owner to cost centre. The [Admin API key list](/blog/find-anthropic-api-keys-across-workspaces) gives you the key IDs.

## How do you build a per-agent spend report?

1. Pull daily usage grouped by `api_key_id` and `model`.
2. Multiply token types by the current price per model, or pull cost by workspace and allocate it across keys by token share.
3. Join key IDs to your agent registry.
4. Add Priority Tier usage separately. Priority Tier costs are not in the cost endpoint; find them in the usage endpoint by `service_tier`.
5. Add code execution costs from the cost endpoint, where they appear under the description field. They are not in the usage endpoint.
6. Reconcile monthly against the invoice.

Data usually appears within five minutes of a request completing. Anthropic supports polling once a minute for sustained use, so near-real-time budget alerts are feasible.

## What does provider data miss?

| Gap | Why | Fix |
|---|---|---|
| Agent version | The key does not change when the prompt or model does | Attribute in a gateway that tags versions |
| End user | One agent key serves many users | Pass user context through a gateway or trace |
| Default workspace | Usage there shows a `null` workspace ID | Move agents out of the default workspace |
| Console playground | No API key, so `api_key_id` is `null` | Exclude or track separately |
| Bedrock and Google Cloud | Different credentials and billing | Pull cloud billing; see [Claude on Bedrock vs the Anthropic API](/blog/track-claude-spend-bedrock-vs-anthropic-api) |

Most enterprises end up with both: provider reports for invoice reconciliation, and gateway attribution for per-version and per-user views. Our guide to [attributing LLM costs to AI agents](/blog/how-to-attribute-llm-costs-to-ai-agents) explains how the two fit, and [budgets and alerts for agent spend](/blog/set-budgets-and-alerts-for-ai-agent-spend) covers enforcement.

## How Opencontroller does this

The Lyzr LLM Gateway in Opencontroller attributes cost per agent and per version for every call it routes, across providers, with caching, routing and fallback in the same path. In our October 2026 benchmark, caching cut model cost by 23.5% on mixed synthetic traffic under the stated test conditions. Discovery across AWS, Azure and Google Cloud finds agents and keys you have not registered yet. Read how this fits an [AI agent control plane](/blog/what-is-an-ai-agent-control-plane), compare approaches on the [LLM gateway comparison page](/compare/llmgateway), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Can the Anthropic cost endpoint group by API key?**
The legacy cost endpoint groups by workspace and description. Use the usage endpoint grouped by `api_key_id`, or the newer Usage and Cost Analytics API, for per-key cost.

**How fresh is Anthropic usage data?**
Usually within five minutes of the request completing.

**Does this include Claude Code costs?**
Per-user Claude Code cost is available through the Usage and Cost Analytics API and the Claude Code Analytics API.

## Key facts

Anthropic Admin API usage endpoint /v1/organizations/usage_report/messages: token counts by 1m/1h/1d buckets (max 1,440/168/31), group or filter by API key, workspace, model, service tier, context window, inference_geo, speed. Cost endpoint /v1/organizations/cost_report: USD as decimal strings in cents, daily only, group by workspace_id or description; Priority Tier costs excluded; code execution only in cost endpoint. Both labelled legacy; Usage and Cost Analytics API recommended. Data typically within 5 minutes; polling once per minute supported. Default workspace = null workspace_id. Opencontroller LLM Gateway attributes cost per agent and per version; Oct 2026 benchmark 23.5% lower model cost with caching on mixed synthetic traffic. Pricing starts from $250K per deployment per year.

## Related

- [How do you use Anthropic Console workspaces to cap agent spend?](https://opencontroller.lyzr.com/blog/anthropic-workspaces-for-agent-spend-limits.md)
- [How do you attribute LLM costs to individual AI agents?](https://opencontroller.lyzr.com/blog/how-to-attribute-llm-costs-to-ai-agents.md)
- [How do you track Claude spend across Amazon Bedrock, Claude Platform on AWS and the Anthropic API?](https://opencontroller.lyzr.com/blog/track-claude-spend-bedrock-vs-anthropic-api.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
