Blog

Claude API pricing explained: cost per million tokens

Claude API pricing is per million tokens, with separate rates per model for uncached input, output, cache writes and cache reads. Output costs several times input; cache reads cost a fraction. For coding agents the replies are not the expensive part: re-read context is, and how many times it gets re-read.

67.7%
of agent spend is cache reads
13.2%
is output
98.6%
token cache-hit rate

The four token types on a Claude API bill

Each response reports input_tokens, cache_creation_input_tokens, cache_read_input_tokens and output_tokens, each at its own rate. For agents the ratios matter more than the prices.

Price relative to uncached input
Sonnet 4.5 list prices
cache read
0.1×
input
1×
cache write, 5 min
1.25×
cache write, 1 hour
2×
output
5×
Opus is higher and Haiku lower; check Anthropic's pricing page for current rates. Ratios from the anatomy of a token bill.

Input vs output tokens: why input dominates for agents

An agent sends instructions, tools, history and every file and command output, gets a short step back, and sends it all again. Each request is mostly input it has sent before.

Where the money went
12 real sessions, 18,333 assistant turns, billed usage
  • cache read67.7%
  • cache write18.9%
  • output13.2%
  • uncached input0.2%
With a 98.6% cache-hit rate, "input price" alone says little about agent cost. From the anatomy of a token bill.

How prompt caching changes Claude API cost

A request that starts with the same bytes as a recent one reads the shared prefix at the discount. Claude Code sets the breakpoints.

  1. 1
    Warm while active

    The default cache lives about five minutes and refreshes on every use.

  2. 2
    Idle gaps break it

    Past the lifetime, the next request writes the whole context again.

  3. 3
    Prefix changes break it

    A new tool list, system prompt or model invalidates everything after it.

  4. 4
    Cheap is not free

    Re-reading 300k tokens a turn still bills 300k cache reads a turn. See caching vs compression.

Worked example: Claude tokens to dollars for one agent turn

One mid-session turn: 150,000 cached tokens, 3,000 new tokens of tool output and a 500-token reply, at the Sonnet 4.5 ratios.

Part of the turnTokensRateInput-token equivalents
Cache read150,0000.1×15,000
Cache write, 5 minutes3,0001.25×3,750
Output5005×2,500
Total21,250
Share of that turn's cost
Computed from the table above
  • cache read70.6%
  • cache write17.6%
  • output11.8%
Without caching the turn would be about 155,500 equivalents; with it, re-read context is still about 70% of cost, close to the real sessions.

Multiply 21,250 by the input rate per million and divide by one million for dollars. Repeat with growing context and cost outruns turn count.

Real sessions at list rates
Cost per turn rises with depth
200 turns, first 10 steps, Opus
$1.06
200 turns, Opus
$33.61
938 turns, Sonnet
$154
938 turns, Opus
$771
The 938-turn session peaked past 800k tokens of context. The 200-turn session is from our quality evaluation.

Estimating Claude API cost for your own agent

  1. 1
    Read it live

    /cost in Claude Code on an API key.

  2. 2
    Log the four fields

    For your own agent, record usage from every response and price it per model.

  3. 3
    Divide by finished tasks

    Not requests (why). Then see Claude Code cost and subscription vs API key.

How to lower Claude API cost for coding agents

  1. 1
    Keep the cache warm

    Stable prefix, no long idle gaps, model switches only at task boundaries.

  2. 2
    Cheapest model that finishes

    Sonnet or Haiku for routine steps, Opus where it saves turns.

  3. 3
    Send less context

    Fresh sessions, fewer tools, shorter output. The Batch API discount does not help interactive agents.

  4. 4
    Compress the history

    condense shrinks re-sent context and freezes compressed spans so they stay cached: $154 to $43 on Sonnet, $771 to $214 on Opus.

Share of the bill removed
Live head-to-head on Haiku
condense
37.3%
headroom
13.8%
headroom's best mode against condense on the same replays. From does context compression hurt agent quality.

Savings grow with session length and are negative on very short sessions. Anthropic still bills you directly; condense charges 15% of what it saves, and organizations can split traffic to measure it against a control.

Frequently asked questions

Why are Claude output tokens more expensive than input tokens?

Anthropic prices output at several times input. In agents it is still a minority of the bill, because re-sent input is much larger.

What is the difference between cache write and cache read tokens?

A cache write stores a prompt prefix at slightly above input price; a cache read reuses it later at a steep discount.

How long does the Claude prompt cache last?

About five minutes by default, refreshed on each use; a longer option costs more to write. After an idle gap the context is written again.

How do I convert Claude tokens to dollars?

Multiply each usage field by its per-million rate, divide by one million and add them up. In Claude Code, /cost does it for you.

Is Opus more expensive than Sonnet on the API?

Yes. One 938-turn session cost $154 on Sonnet and $771 on Opus at list rates.

All posts