Agents mostly read#
When we think about what a model costs to run, we usually think about the tokens it outputs. But that's actually the smaller part of the bill.
An agent like Claude Code works in a loop. It reads the conversation, decides what to do, and calls a tool, like reading a file or running a command.
The result of that tool call gets added to the conversation, and the loop starts over. Every step is a brand new request to the model, and every request includes the entire conversation so far.
You can see where this is going.
The conversation keeps growing, and the model reads all of it again on every step. In my own logs, agents read between 200 and 330 tokens for every token they write.
Some people still tell Claude to talk like a caveman to save usage, but the text the model writes is <.5% of tokens - a rounding error.
For example, I like to make animated explainer diagrams with Claude Code. So I ask it: "Read the social animations skill and give me 20 ideas." (A skill is just a saved file of instructions.)
About eight minutes later, I had my 20 ideas - it took 40 steps and read 5.1 million tokens. My part of that conversation was 10 words.
If the model had to re-read the prior steps tokens from scratch every turn of the loop, agents would be way too expensive to use.
What prompt caching is#
As a model reads text, it builds up an internal state. Remember, models process text one token at a time, and every new token updates that state. Prompt caching stores the state.
For example, here are the first 10 steps of my “20 animation ideas” session. Each step’s new tokens are in orange bars, and grey bars are “cache hits”.
On step 10, the prompt was 99,336 tokens, and 84,940 of them came from the cache, so the model only had to process the 14,396 new ones.
It's like adding up a long receipt. If you wrote down the subtotal, you don't add up every item again when one more gets added. You just add the new item to the subtotal.
This only works if everything before the new part is exactly the same. If something early in the conversation changes, everything after it has to be computed again.
Changing one line of the system prompt, the hidden instructions sent at the start of every chat, is like changing the price of the first item on the receipt. Your subtotal is wrong now, and you have to re-add everything from that point on.
Storing that internal state takes space in what’s called the “KV cache” (for a key-value store of vectors). The larger the model is, and the more tokens of context are built up, the more space it takes.
That's why providers don't keep the cache around forever, but it's still much cheaper than recomputing everything every time.
How much it saves#
Providers charge a lot less for cached tokens than for regular input. Opus 5.5 costs $4 per million input tokens, but only $0.20 per million cached tokens. Those 20 animation ideas cost $3.17 at API prices, which would’ve been $21.18 without caching (~7x if you’re scoring at home).
Here's my own Claude Code and Codex usage from the last six weeks, priced at API rates:
It's generally about 10 times as much without caching. For me, that's $78,000 over six weeks at API rates, or $7,600 with the discount. For the French, that’s about 78,000 baguettes, or 7,600 baguettes, respectively.
Even with caching, reading is most of the bill. On my Opus usage, the text the model writes is only 22% of the cost. Reading from the cache is 46%. The other 32% is cache writes, which is what you pay the first time something gets saved to the cache.
Cache writes cost 1.25x to 2x regular input depending on how long the cache lasts, so just 2% of my tokens made up 32% of the bill.