Your LLM Usage Tool Undercounts: Audit Spend per Feature, Not per Session

If your LLM usage tool shows a smaller number than your bill, the tool is usually not broken. It counts what reaches its own logs, prices it at list price, and groups it by your local day. Requests made by other features, such as a safety classifier on a different model, a separately billed code reviewer, or another app on the same key, never reach those logs. The fix is a reconciliation: pull the provider's own usage and cost data for the same UTC day, diff it by model, and give every feature a label so the gap gets a name.
This guide uses Claude Code, ccusage and the Anthropic Admin API as the example. The method works for any agent harness.
Why LLM Usage Tools Undercount
Local tools say what they are. The ccusage docs: "Stored costs are values from the logs, not a billing statement. ccusage does not retrieve invoices or subscription charges." Claude Code's costs page says its /usage figure is computed "locally from token counts at list price" and "is an estimate".
The common sources of the gap:
| Gap source | Why the local number misses it | Where it shows up |
|---|---|---|
| Contract rates | Local tools price at list price | Your invoice. Claude Code can apply your rates with the modelPricing managed setting (v2.1.242+) |
| Day boundary | ccusage groups by the timezone you give it; the cost report uses UTC days | Spend shifts between two dates |
| Auto mode classifier | A second model reviews actions, by default Claude Sonnet 5 | Usage report, under a model you did not pick |
| Code Review | "Billed on token usage through usage credits", to the organization | Code Review analytics, not your session |
| Background work | Recaps, idle compaction, check-ins, subagents send their own requests | Usage report; partly in OTel query_source |
| Other consumers | Scripts, CI jobs or teammates on the same workspace | Usage report grouped by api_key_id |
The classifier row surprises people most. Per the permission modes docs, in auto mode "a separate classifier model reviews actions before they run", and "by default, classifier requests go to Claude Sonnet 5". When Claude Code makes these requests itself, they "count toward your token usage on Enterprise plans" and on Claude API, Bedrock, Google Cloud and Foundry accounts. "Each request sends a portion of the transcript plus the pending action." On a direct Anthropic API connection, newer versions can ask the server to run the checks inside the session's own requests, and the classifier billing page says those checks are "at no charge". One user bug report said /cost left out classifier calls and background subagents. It was closed as not planned, so treat it as a lead to check, not a fact.
Step 1: Get the Local Estimate on UTC Days
Make the local tool group by the same day the provider uses, and price from tokens, not stored values:
npx ccusage@latest claude daily --since 20261125 --until 20261201 \
--timezone UTC --mode calculate --breakdown --json > local.json
--mode calculate ignores stored costs and prices tokens from the pricing table. --breakdown splits each day by model, which you need for Step 3. --instances adds a per-project split.
Step 2: Pull the Provider's Usage and Cost
With an Admin API key, pull the usage report by model and API key, and the cost report by description:
curl "https://api.anthropic.com/v1/organizations/usage_report/messages?\
starting_at=2026-11-25T00:00:00Z&ending_at=2026-12-02T00:00:00Z&\
group_by[]=model&group_by[]=api_key_id&bucket_width=1d" \
-H "anthropic-version: 2026-10-21" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY" > usage.json
curl "https://api.anthropic.com/v1/organizations/cost_report?\
starting_at=2026-11-25T00:00:00Z&ending_at=2026-12-02T00:00:00Z&\
group_by[]=workspace_id&group_by[]=description" \
-H "anthropic-version: 2026-10-21" \
-H "x-api-key: $ANTHROPIC_ADMIN_KEY" > cost.json
These are the legacy endpoints. Anthropic recommends the Usage and Cost Analytics API for new integrations; its cost endpoint takes products[]=claude_code&group_by[]=actor for per-user Claude Code cost. Three details from the docs matter here: cost data uses daily buckets only, costs come back in cents as decimal strings, and the cost report groups by description with a parsed model field. Follow next_page while has_more is true.
Step 3: Diff by Model
Put the two sources side by side per UTC day and per model. A worked example with invented numbers:
| Model | Local (ccusage) | Provider cost report | Gap |
|---|---|---|---|
Opus 5.5 (your /model) |
$38.10 | $40.20 | $2.10 |
| Sonnet 5 | $0.00 | $61.50 | $61.50 |
| Haiku 5.5 | $1.40 | $1.60 | $0.20 |
A small gap on the model you picked is pricing or rounding. A large gap on a model you never selected is a feature. Here, Sonnet 5 matches the default classifier model.
Check the size against pricing. Sonnet 5 input is $2 per million tokens and cache hits are $0.20. If each classifier request carried 30,000 uncached input tokens and a day had 1,000 reviewed actions, that is 30 million tokens, or $60. With cache hits the same traffic costs a tenth. Do not trust that guess; measure it:
claude --permission-mode auto --debug-file classifier-debug.log
# have Claude run: curl https://example.com
grep classifier_request_started classifier-debug.log
The model= value shows which model reviewed. If there is no such line, run /status: Auto mode server: Enabled means the server reviews the session. Use the api_key_id grouping from Step 2 the same way. A key nobody recognizes is a consumer, not a bug.
Step 4: Attribute LLM Spend per Feature
Once the gap has a name, make it visible every day. Claude Code exports per-request attribution over OpenTelemetry:
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_RESOURCE_ATTRIBUTES="team.id=platform,cost_center=eng-123"
The claude_code.cost.usage and claude_code.token.usage counters carry model, query_source (main, subagent, auxiliary, plugin_model_complete, plugin_model_classify), agent.name, skill.name and plugin.name. Graph cost by query_source and model. The docs do not map each internal request to a category, but side requests that are not the main loop, a subagent or a mod have only auxiliary left. If your session runs Opus and auxiliary spend on Sonnet 5 grows, check the classifier first. The docs warn that these metrics are approximations too, so the provider report stays the source of truth.
For traffic outside one harness, the simplest label is a separate API key or workspace per feature, so the usage report's api_key_id and workspace_id groupings become a per-feature bill.
Step 5: Price the Second AI Reviewer
A second AI reviewer is a feature with its own bill, and it often finds what the first one already found. Code Review is billed through usage credits, and in After every push mode it "runs on each push, multiplying cost by the number of pushes" (Code Review costs). Before you keep two reviewers, run both on the same 20 merged PRs and record:
- Findings per reviewer, after you remove duplicates of the other reviewer's findings.
- Tokens or dollars per reviewer, from its own label in Step 4.
- Cost per unique valid finding: spend divided by findings the other reviewer missed.
| Result | Decision |
|---|---|
| Reviewer B finds real issues A misses | Keep both; run B once per PR, not per push |
| B finds the same issues at higher cost | Drop B, or run it only on high-risk paths |
| B finds nothing new and costs less | Keep it as a cheap tiebreaker, if review time allows |
Set the reasoning effort the same on both before you compare, as our post on second-opinion models explains. Otherwise you compare settings, not reviewers.
Per-Feature Cost Attribution Checklist
- Local tool and provider both report UTC days.
- Contract rates loaded (
modelPricing) or the gap is explained as list price. - Usage grouped by
modelandapi_key_id; every model and key has an owner. - Auto mode classifier model known from the debug log; server review status known from
/status. - OTel cost graphed by
query_source,agent.nameandskill.name. - Each AI reviewer has its own label and a cost per unique finding.
- Alert when the daily provider total exceeds the local total by more than your agreed ratio.
For where tokens go inside a single run (cache misses, context re-reads), see where AI agent tokens go.
Troubleshooting
The daily totals never line up. Without --timezone UTC, ccusage can file late-evening usage under a different date than the provider does. Usage data appears "within about 30 minutes", and a cost day appears only after it ends in UTC, so skip today.
A notice says the session "isn't eligible" for no-charge classifier requests. An LLM gateway or proxy strips the anthropic-beta header or the safeguards field, so Claude Code makes its own billed classifier requests. Make the gateway pass both through unchanged and keep safeguard_results in responses. Note the irony: the proxy you added for cost tracking can raise the cost.
CLAUDE_CODE_AUTO_MODE_MODEL did not take effect. It needs v2.1.302 or later. Search the debug log for ignoring CLAUDE_CODE_AUTO_MODE_MODEL. Setting Opus 5, Sonnet 5.5 or Opus 5.5 falls back to the default classifier model.
api_key_id or workspace_id is null. Console playground usage has no API key, and the default workspace reports as null.
The Admin API rejects your key. Workspace-scoped keys do not work, Team plans have no Admin API, and Enterprise organizations use the Analytics API instead.
Metering Incident Agents in Akmatori
An incident agent needs the same per-feature view. In the Akmatori API, GET /incidents/:uuid returns an incident with its agent runs, token count and execution time, so investigation cost is its own line. To get central keys, budgets and logs, put a LiteLLM proxy in front as a Custom model, as the local models guide shows, with a virtual key for the agent.
Conclusion
A usage tool that disagrees with the bill is telling you that some feature spends outside its view. Reconcile by UTC day and model, name each gap, then give every feature its own label so the next gap shows up on a graph instead of an invoice.
If your team wants AI-assisted incident workflows on your own infrastructure, Akmatori helps SRE teams investigate alerts, coordinate response, and keep agent token spend visible per investigation. Powered by Gcore for global infrastructure reliability.
