If you run an AI agent on the Claude API, stop for a few minutes and then ask the next question, and that message often costs far more than the last one. The cause is prompt caching. The official docs say the default cache only lasts 5 minutes, and the timer resets each time it's used. If there's no request for more than 5 minutes, the whole history has to be processed again at the normal price.
How the billing works
Every turn of a long conversation sends the earlier history to the model again. With prompt caching on, the repeated part is billed at a much lower "cache read" price. Once the cache expires, that history has to be written into the cache again. Per Anthropic's official docs:
| Situation | Multiple of the base input price |
|---|---|
| Cache read (hit) | 0.1x |
| Writing a 5-minute cache (default) | 1.25x |
| Writing a 1-hour cache (you turn it on) | 2x |
So for the same 200K-token history, a cache hit and a rewrite after expiry can differ by more than ten times on that one turn's input cost. You step away to get a glass of water or check another window, come back, ask again, and fall right into this trap.
What it means for you
- If you write code that calls the API: requests often come more than 5 minutes apart, like when you're waiting for an approval or another job to finish. You can set
ttlto1hincache_control. Writes cost more, but if you'll reuse the cache several times within an hour, the total is cheaper. - If you run long tasks with an AI agent: if you need to stop for a long time, have the agent compress its progress into a short set of notes, then start a new session when you're back. That's cheaper than pushing an expired long history.
- Claude app and Claude Code on subscription plans: some users say the cache lasts longer on subscriptions, which is why it feels more durable. That's not verified yet. The official docs only describe the API rules.
Have your AI agent check your setup
Check my code that calls the Claude API and tell me whether cache expiry is costing me extra money:
1. Find every place that sends a request, and check whether cache_control is set and whether ttl is the default 5 minutes or 1h
2. Estimate the typical gap between two requests, and list the cases where the gap is longer than 5 minutes
3. For each case, suggest one option: keep the 5-minute cache, switch to a 1-hour cache, or compress the history and start a new session. Explain why.
4. Only give advice and show the changes. Do not edit the code directly. Wait for my confirmation.
Things to watch
- The cache is kept separately for each model. If you switch models in the middle of a long chat, the whole history gets processed again too. See Why switching models mid-chat in Claude Code makes the next message so expensive.
- The multipliers and prices in the official docs are the final word. Base prices differ by model.
- The cache only covers the repeated opening part. Anything new in each turn is still billed as usual.


Comments (0)
No comments yet. Start the conversation.