Guides

Guide

Anthropic API cost tracking: Claude API spend by customer, feature and team

Published

Your Anthropic bill tells you how much you spent on the Claude API. It doesn't tell you which customer, product feature or team the spend served. This guide shows how to track Claude API costs at that level, check the figures against what Anthropic bills, and cap the spend before it surprises you.

What does Anthropic's own billing data show, and what's missing?

Your Anthropic bill shows the total you spent, and Anthropic's usage data, read with an Admin key, can be split by API key. What it can't show is your own business: which of your customers a call served, which feature made it, or which team owns the code. Those fields don't exist on Anthropic's side.

Provider invoices and usage exports have no customer field, so the split can't be rebuilt later from billing data. The only moment you know the customer and the feature is when your code calls Claude, so that is where tracking has to start.

How do you track Claude API costs per customer, feature and team?

Tag each Claude API call with the customer, feature and team when you make it. Token Meter offers two ways to do that: wrap the Anthropic client you already have with the SDK, or point the Anthropic SDK at Token Meter's router by changing its base URL. Pick one per call path; you don't need both.

The SDK (Python or TypeScript). Install it next to the Anthropic SDK with pip install "tokenmeter-sdk[anthropic]" or npm install @tokenmeter/sdk @anthropic-ai/sdk. Wrap the client, then open an action() scope around the calls it covers. The SDK is not a proxy: it reads usage from the reply Anthropic already sent and adds no network hop. A failed Anthropic call reaches your code unchanged, and the SDK's own record-keeping can never fail your call.

report.mjs
import Anthropic from "@anthropic-ai/sdk";
import { TokenMeterClient, wrapAnthropic, action } from "@tokenmeter/sdk";

const tl = new TokenMeterClient({ apiKey: process.env.TOKEN_METER_KEY ?? "" });
const anthropic = wrapAnthropic(new Anthropic(), tl); // reads ANTHROPIC_API_KEY

const reply = await action("generate-report", { customerRef: "acme", feature: "reports", team: "growth" }, () =>
  anthropic.messages.create({
    model: "claude-haiku-4-5",
    max_tokens: 200,
    messages: [{ role: "user", content: "Say hello in five words." }],
  }),
);

await tl.flush(); // a short script sends its usage before it exits

The wrapper records the Messages API, streaming or not. A long-running app sends usage every 2 seconds or every 500 calls, whichever comes first, and the call shows on Requests within a few seconds. Use an id such as cus_123 for the customer, not an email address: emails are replaced with [REDACTED:email], so those customers merge into one row.

The router. If you'd rather not touch the client code, point the Anthropic SDK at the router's address with no /v1 at the end (the SDK adds /v1/messages itself) and use your Token Meter ingest key as the API key. Unless your workspace pays from Token Meter credits, a call that names a Claude model runs on your own Anthropic key and Anthropic bills you as usual. Before the first request on your own key, an Owner or Admin does two things under Router › Providers:

  1. Choose Add provider key, pick Anthropic, paste a key from console.anthropic.com/settings/keys into Inference API key and choose Store key. It is stored encrypted and can't be read back. Without it the router answers 424 provider_not_configured.
  2. Under Advanced, choose Add capability for each Claude model you call, with its Max context tokens and Max output tokens. Without it the router answers 400 model_capability_not_configured.
report.mjs
import Anthropic from "@anthropic-ai/sdk";

// The router's address with no /v1: the SDK adds /v1/messages itself.
const anthropic = new Anthropic({
  baseURL: "https://router.timewastevc.com",
  apiKey: process.env.TOKEN_METER_KEY,
});

const message = await anthropic.messages.create({
  model: "claude-haiku-4-5", // a Claude model with a capability record
  max_tokens: 512,
  messages: [{ role: "user", content: "Say hello in five words." }],
});
for (const block of message.content) {
  if (block.type === "text") console.log(block.text);
}

Attribution goes in the request body as top-level fields (action, customer_ref, feature, team, environment, project), which the router records and removes before the request reaches Anthropic:

Shell
curl https://router.timewastevc.com/v1/messages \
  -H "x-api-key: $TOKEN_METER_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-haiku-4-5", "max_tokens": 512, "messages": [{"role": "user", "content": "Summarize the latest tickets."}], "action": "weekly-summary", "customer_ref": "acme", "feature": "reports", "team": "support"}'

Because the Anthropic SDKs read ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY, an app that creates its client without passing them can switch with environment variables alone, though calls then arrive without a customer or feature until you add the body fields.

SDK wrapperRouter
ChangeWrap the client, add action() scopes.New base URL (no /v1) and API key, tags as body fields.
Anthropic APIMessages API, streaming or not.Messages API at /v1/messages, streaming included.
Network pathDirect to Anthropic; usage read in-process.Through the router, which calls Anthropic with your stored key.
Can block a callNo; it records what already happened.Yes: an enforced budget, per-request cost caps and governance policies are checked before Anthropic is called.
Claude on your own Bedrock or Vertex AI accountYes: AnthropicBedrock and AnthropicVertex are wrapped the same way, recorded under AWS Bedrock and Google.No. The router stores your own key only for OpenAI, Anthropic and Google AI Studio.

On /v1/messages only Anthropic models answer, and cache_control markers inside messages are passed through. A Claude model called through the OpenAI-style /v1/chat/completions is translated for plain text only; tools and response_format there are refused with 400 claude_tools_require_native_messages_api. Don't send the same call through the router with a wrapped client: it is metered twice. A call with no tags still counts in every total; it shows as Unattributed. Details: Providers, Router and Attribution. To turn per-customer cost into margin, see LLM cost per customer.

How do you check the figures against what Anthropic bills?

Connect your Anthropic organization with an Admin API key. Token Meter then imports Anthropic's cost report and compares it, day by day, with the cost it metered from your calls. A day matches when the two are within 2% of the invoice; anything further apart is flagged as drift.

  1. In the Claude Console at platform.claude.com, open Settings › Admin keys, choose Create admin key, name it, pick an expiry and choose Add. Copy the key; it starts with sk-ant-admin and is shown only once.
  2. Open Settings › Organization and copy the organization ID. It is a UUID; an ID like org-… is an OpenAI ID.
  3. In Token Meter, open Settings › Connections and choose Connect an account. Owners and admins can do this.
  4. Pick Anthropic, paste the ID into Anthropic organization ID and the key into Admin API key, then choose Connect and sync. Token Meter checks the key with Anthropic, stores it encrypted and starts the first import.

You need an Admin key, from an organization

Only members with the admin role in your Claude Console organization can create an Admin key, and an individual Console account can't: set up an organization first. A normal API key (sk-ant-api…) is rejected. The key only reads billing and usage data and is never used to make AI calls. If you picked an expiry, the card shows Needs attention when it runs out; create a new key and use Edit credentials.

The first sync imports the last 7 days; the rest of the history, up to 90 days, follows in the background. After that the connection syncs about once an hour. Days are UTC, today is never requested, and the newest days can lag while Anthropic settles them. Reconciliation runs at 07:00 UTC each day:

StatusMeaning
MatchedEvery reconciled day in the range is within 2%.
Drift detectedInvoice lines exist, and at least one day differs by more than 2%.
Not reconciled yetLines are imported, but no day has been compared. For Anthropic a day is compared at the first 07:00 UTC run after a 3-day settlement delay.
Awaiting invoiceNo Anthropic invoice lines are imported for the range.

If you pay Anthropic a negotiated rate, open Settings › Connections, expand Advanced and choose Add a private rate; a start date up to 365 days back reprices usage from that day. On Analytics › Bill, once Anthropic invoice lines exist for a range, the invoice is what counts toward your total AI spend, never the invoice plus metered cost. Data health › Provider usage shows, per model, Anthropic's total next to what per-call metering saw, and per-key splits from the connection. See AI Bill and billing imports, and tracking AI spend across providers if Anthropic is one of several bills.

How are Anthropic's cache and reasoning tokens counted?

Anthropic reports prompt-cache reads and writes apart from input_tokens, so Token Meter uses them as they are, with nothing subtracted. Anthropic doesn't report reasoning tokens separately, so that count stays empty for Claude calls rather than guessed.

Every call is converted into five counts: input_tokens, output_tokens, cache_read_tokens, cache_write_tokens and reasoning_tokens. No token is in more than one count, so cost is each count times its price, added up. The arithmetic to get there differs by provider:

ProviderCache tokensReasoning tokens
Anthropic (Messages API)Reads and writes reported apart from input_tokens; used as they are.Not reported separately.
OpenAIPart of the prompt total, so subtracted: input = prompt_tokens − cached_tokens.Part of the completion total, so subtracted.
Claude on AWS Bedrock (Converse)inputTokens already leaves out cache reads and writes; used as it is.No reasoning count; Claude thinking tokens are billed inside outputTokens.

OpenAI teaches the habit of subtracting cache and reasoning tokens from the totals; Anthropic's numbers need nothing subtracted. The Anthropic rule is stated in Anthropic's documentation and checked against saved responses, and like every provider rule it has an automated test against a saved provider response. Through the router, Anthropic's cache_control markers inside messages are passed through on /v1/messages. See Providers.

How do you cap Anthropic API spend?

Set a budget: a monthly spend limit on the whole workspace or on one customer, feature, action, team, environment, provider or model, with alerts as spend climbs. Budgets are checked every 60 seconds against spend so far this calendar month (UTC), from every connected usage source.

  • Budgets. Thresholds default to 50%, 80% and 100%, each firing once a month, and a projection alert warns when the month's linear burn will end over the budget. Owners and admins create them under Governance › Budgets. On the Free plan you can set one advisory, workspace-wide budget; scoped budgets, router enforcement, alert rules and notification channels need a paid plan.
  • Enforced on the router. A workspace-wide budget can be enforced on router traffic: a call that doesn't fit what is left gets 402 monthly_budget_exceeded. Direct calls, SDK-reported usage and imported bills are counted and alerted on, but can't be blocked.
  • Per-request caps. Through the router, a request can carry max_cost_usd and is refused when its worst-case cost is above it.
  • Alert rules. A Threshold rule fires when spend for a scope, optionally limited to a provider and a model, reaches an amount within the UTC day or month. A Provider spike rule fires when today's spend so far reaches a set multiple of yesterday's, scaled to the part of the day that has passed.

Alerts go to email, Slack or Discord channels. With the Anthropic Admin API key connected, you can also add a provider control on Governance › Rules: fill in Approved projects / workspaces / accounts or Approved API key ids, and usage from anything else is recorded as a detected violation. If you opt in on the control and for the workspace, the offending Anthropic key is set to inactive. See Governance and alerts.

What doesn't this cover?

  • Claude calls that aren't metered appear only in the imported Anthropic totals, with no customer or feature.
  • Claude through your own AWS Bedrock or Vertex AI account appears on the AWS or Google bill, not the Anthropic one, so the SDK records it under those providers. The router can't carry that traffic on your account; use the SDK.
  • The router's response caches never answer /v1/messages requests.
  • Invoice figures are not live: today is never imported, and the newest days can lag while Anthropic settles them.
  • Claude Code on an Anthropic API key sits inside the same Anthropic invoice; to track it per developer, along with Claude seats, see AI coding tool costs.

Start tracking Anthropic API costs

Create a workspace, add an ingest key, wrap your Anthropic client and tag one call with a customer and feature. Then connect an Anthropic Admin API key to check the metered cost against your bill.