Key takeaways

  • Token cost is each token type times its price per million, summed across input, cache writes, cache reads and output.
  • In Anthropic's sample Claude Code session, cache reads make up about half of the $0.55 total despite costing a tenth of base input per token.
  • UsageAtlas applies known model prices to local token history across coding tools; its figures, like any calculator's, are estimates at list price.

An LLM token cost calculator multiplies each kind of token by its price per million and adds the results. For coding agents, the part most people miss is the cache: a long session can be dominated by cache reads, which are cheap per token but enormous in volume.

That is why a single "tokens used" number tells you little. The rest of this piece walks through the formula, a real example from Anthropic's documentation, and how UsageAtlas applies the same math across coding tools.

The formula

Providers price tokens per million (Anthropic writes it as MTok). Most now split prices into separate lines:

  • Base input tokens
  • Cache writes (storing a prompt prefix for reuse)
  • Cache reads, also called cache hits
  • Output tokens, which include thinking tokens on Anthropic models

The calculation is:

cost = (input × input price + cache writes × write price + cache reads × read price + output × output price) ÷ 1,000,000

OpenAI's pricing page uses the same idea, with separate input, cached input and output columns per million tokens.

A worked example

Anthropic's Claude Code cost docs show a sample session on Claude Sonnet 4.6: 1.2k input tokens, 5.3k output, 940k cache read and 50k cache write, for a total of $0.55. Using Sonnet 4.6 list prices from Anthropic's pricing page, the arithmetic checks out:

Token type Tokens Price per MTok Cost
Input 1,200 $3 $0.0036
Output 5,300 $15 $0.0795
Cache read 940,000 $0.30 $0.282
Cache write (5 minutes) 50,000 $3.75 $0.1875
Total about $0.55

Cache reads are about half the bill, even though each one costs a tenth of a normal input token. Anthropic's pricing page lists the multipliers: a five-minute cache write costs 1.25 times the base input price, a one-hour write twice the base price, and a cache read 0.1 times on most models, with lower read multipliers on some newer ones. The Batch API takes 50 percent off input and output.

Why a calculator is not a bill

Run the formula on your own logs and you get an estimate at list price. Anthropic says the same of the dollar figure in Claude Code's /usage: it is computed locally and is an estimate, and on Pro or Max plans it is not what you pay. Contracted rates, data residency pricing and subscriptions all move the real number.

The calculator is still the right tool for questions like which model made a week expensive, or whether long-lived sessions are worth clearing.

Doing it across tools

Running this by hand for one session is easy. Doing it for every session across Claude Code, Codex, Cursor and OpenCode is not. UsageAtlas is a free, open-source desktop app that applies known model prices to local token history and shows estimated cost by day, tool and model, with the input, cache and output split kept beside the total. Unknown prices stay unavailable rather than becoming zero. It labels every estimate as one and does not read prompts or responses.

For a single API account, the provider's console reports exact spend and needs no calculator. The math matters when you want to see why a number moved, or when several tools share the work.

FAQ

Do thinking tokens count in the calculation? Yes. Anthropic bills thinking tokens as output tokens, so they go in the output line.

Why are output tokens priced higher? That is how providers set their rates; on Anthropic's table, output costs five times base input for Sonnet 4.6.

Is there a free tool that does this for coding agents? Yes. UsageAtlas is free and open source and estimates cost from local token history.

Frequently asked questions

How do you calculate LLM token cost?

Multiply each token type by its price per million tokens, add the results, and divide by one million if you used raw counts.

How much do cache reads cost on Claude?

On most models a cache read costs 0.1 times the base input price, according to Anthropic's pricing page.

Is a token cost estimate my actual bill?

No. Subscriptions, contracted rates and data residency pricing change what you pay. Check the provider's billing page.

Sources

  1. PricingAnthropic
  2. Manage costs effectivelyAnthropic
  3. API pricingOpenAI
  4. AI coding cost tracker for tokens and estimated spendUsageAtlas