Get API key →

Claude Code: what each client's work costs

Claude CodeOpenTelemetry

Claude Code reports every API request it makes over OpenTelemetry. Point that report at AgentBill with two small files in a client's project, and each request is recorded with its model, its tokens and what it cost at list price, under that client. There is no code to add and nothing in between: Claude Code talks to Anthropic exactly as before, and AgentBill receives the report after each request.

Set up a client's project

Once per project. In the project's folder, .claude/settings.json, which you can commit with the project:

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "https://agentbill.dev/otel",
    "OTEL_RESOURCE_ATTRIBUTES": "client=acme-dental"
  }
}

And your key, in .claude/settings.local.json beside it. This file is the one that stays out of git: if the project's .gitignore does not list .claude/settings.local.json yet, add it.

{
  "env": {
    "OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer agb_your_key"
  }
}

client is the name the calls are filed under: letters, digits, dots, dashes and underscores, no spaces, up to 64 characters. To name the agent too, add it after a comma: client=acme-dental,agent=support-bot. Without an agent name the calls are filed under claude-code; without a client, under default.

Check it

Open Claude Code in that project and ask it anything. A few seconds after it answers, the request is in the console, under Customers, with its model, its tokens and its price. Work in the same project goes on being recorded there; another client's project gets its own two files with its own name.

What is recorded, and what is not

Recorded, for each API request: the model, the input, output and cache tokens, how long it took, the session id, the price at list, and Claude Code's own cost figure beside ours.

Never stored: the email, account, organization and user ids Claude Code attaches to its report, and every event other than the API request itself. Claude Code does not send the text of your prompts unless you turn that on with OTEL_LOG_USER_PROMPTS, and even then AgentBill does not keep it.

What the dollar figure means

Every figure is an estimate at list price, from the tokens the request reported. On the API it is what those tokens cost at Anthropic's published rates. On a Pro or Max subscription you are not billed per token: the figure is what the same work would cost at list price, which is what makes one client's work comparable with another's, and it is not your bill.

What it does not do

This records requests after they are made. Claude Code does not ask AgentBill before a request, so a job ceiling does not refuse one here; use it to see what each client costs and when a client's work grows. Each request is one record, and records count toward your plan's monthly records.

Get API key →