How to Reconcile Claude Code Session Cost

Match Claude Code output tokens to provider billing rows. Follow one edit, seven itemized charges and a client estimate that differs from the bill.

An orange binder clip aligns two sets of billing records.

To reconcile Claude Code session cost on an API gateway, record the session window and compare the client’s usage with the provider’s itemized charges. In one Ofox session, Claude Code reported an estimated $0.0466248. Seven matching provider rows recorded $0.00293546. The client estimate and the gateway charges answer different questions. Here is how we linked the seven rows to a single accepted edit.

1. Capture one session you can identify

Use a dedicated or idle API key for a short task, so another session cannot add activity in the same window. Follow Ofox’s Claude Code provider configuration and use /status to confirm the model and provider. Record the start and end times, their time zone, the selected model and the protocol. Save the client’s usage summary, including output tokens and any displayed cost.

You can use our original ledger task and prompt (ZIP). Open Claude Code in an extracted copy, give it the prompt, and save the diff. For a billable test, use your own API key and check that the provider exposes per-request usage.

2. Match the usage rows, then add the charges

Open Ofox Activity. Filter to the key when available, the model, the Claude protocol and the session window. Use request IDs if you have them. Otherwise check the row count and the sum of output tokens against the run before treating the group as matched. If multiple sessions overlap or the totals differ, keep the charges as unresolved and repeat with an isolated key.

In our November 27 session, Claude Code 2.1.332 used DeepSeek V4.1 Flash 1017 through Ofox, from 09:39:32 to 09:40:04 UTC. The matching Activity timestamps ran from 17:39:42 to 17:40:00 UTC+8. The match used the time window, model, protocol, count and output-token total. We did not have a request ID for every client event.

What we matchedRecorded result
Responses and tools7 distinct assistant message IDs, 8 tool calls, 7 Activity rows
Output1,495 tokens in the client summary and 1,495 in the matched rows
Client estimate$0.0466248
Sum of the seven provider charges$0.00293546

Download the itemized Activity rows (CSV) and the session summary (CSV). Sum the activity_cost_usd column to reproduce the charge total. Keep currency and precision intact, and include all attributable requests, even if an attempted edit or tool call failed. A denied local action does not tell you whether the model response that requested it was billed.

The client also reported 3,554 input tokens, 12,544 cache-read tokens and zero cache writes. Those counts describe this session. We did not run a controlled cold/warm pair, so the two dollar amounts do not measure how much caching saved. See Claude Code’s cost documentation for the client-side usage display.

3. Check what the session delivered

This session took 31.27 seconds before independent verification. The unattended client denied a shell redirect. The model recovered with the permitted Edit tool. Only ledger.py changed. We moved the submitted file into a clean test copy, where it passed all six public tests and preserved the inputs and correct totals in all 585 cases. That is one accepted edit for this fixture.

Inspect the delivered patch and download the independent verifier (ZIP). After inspecting and applying the patch to a disposable task copy, run python3 -m unittest -v from that copy. From the audit kit root, run python3 controls/verify_patch.py /absolute/path/to/patched/ledger.py. Both counters should reach 585/585.

If the client cannot make its first request, check the endpoint and protocol when curl works but Claude Code fails. If it reaches the provider but cannot write, check the local permission result before starting another paid session.