454 points · by danvdb · 1d ago · 201 comments
I of course don't know what it costs Anthropic to keep the cache warm—but since their subscription plans use one hour, Anthropic must have concluded a longer cache is more economical for most users. And there's a big difference between one hour and five minutes.
You can set 5 minute or 1 hour with API requests. It's the user's choice, not something they force on you. You get the cheapest option (5 minutes) if you don't specify the time.
https://platform.claude.com/docs/en/build-with-claude/prompt...
Okay, but isn't it weird that the default is a giant footgun?
If Anthropic set it to the more expensive option by default, we'd be reading articles about people complaining how evil they were for defaulting to the more expensive option.
The root comment mentions commands that take over five minutes to complete. How often is the agent doing that, versus something quicker? Usage tends to be, the agent does a ton of quick back and forth actions with directory listings and edits and file reads, and then after many quick rounds it eventually kicks off some slower compile/test/run stage which might exceed five minutes. If you use the 1h cache then that slower stage might be cheaper, but all of those quick rounds leading up to it are definitely more expensive. For 1h to work out in your favor, you need a substantial proportion of your work to wait between 5-60 minutes between rounds, including all those little back and forth rounds that happen while the agent is working and barely appear in the UI. This isn't very likely.
Making you spend tokens without noticing it is a free meal to them.
There are various other possibilities to clandestinely extract tokens from you. People just haven't thought about it yet.
What a load-bearing observation. Good instinct!
Why not 30 minutes and 1 hour?
Because 5 minutes is probably good only for uninterrupted agentic work, if I have to pause and read anything, it's expired.
It's surprising, and also not really surprising that they then charge enterprises and companies with over 100/150 employees full API prices with some bulk discounts. I have seen a bill for a small 100+ person company for their tokens and it's insane when you compare it to how many tokens I burn in a week.
I waste more tokens on chasing useless stuff over a couple weeks, then their entire company spends in an entire month tbh that might include resets but this is madness, I am not sure if the music will stop but if it does I don't feel like I nor my current employer will be paying the full price for the tokens.
We save about $1,000 per week by implementing an Opus cache warmer that keeps the 5-minute cache alive for ~30 minutes instead (on the router level).
It's so strange to me that Anthropic does not do this on their end...
Which means it is in Anthropic's interest to set cache lifetimes at a number that will let users get the most value from their tokens, relative to whatever it costs Anthropic to maintain the cache.
Which is not true for many in the enterprise world. Anthropic has been much better (IMHO) at branding than OpenAI, and rather than talking about "agents" many of my coworkers talk about "Claude". I think most of us aren't aware of the cache lifetimes; we just use the model we're used to, and switch only if pressured/forced by our company AI staff to do something different.
Grocery stores are a great example of the power of branding --- some grocery stores are more expensive on the whole but people still shop there for other reasons: because it's conveniently located, because they have certain items in stock, because they have sales, because they just like the shopping environment.
I don't think value is some immediately obvious and observable phenomenon. The average person doesn't even know what prompt caching is. It's completely feasible for them to set defaults that overcharge customers without them knowing.
I feel like statements like that, looked at most charitably, benefit from the confusion between some technical definition of "value" and a a more colloquial definition.
The easiest way to interpret that is: "what's good for you is good for Anthropic, so trust Anthropic," but that's almost never what's going on when you're dealing with a sophisticated business. In all market interactions, "value" is relative and everything is almost always obscured by intense information asymmetries. The business wants to maximize profit for itself, which often entails minimizing the value provided to customers (because more "value" usually costs something) and maximizing the price they pay for it.
Users don't have such a precise metric that would allow them to discriminate value per token reliably. Or have you never seen those comparison sites, with dozens of different scales?
If they can make you reload your cache statistically more often without you noticing (increasing their profits), their business model mandates them doing so.
Subscription plans best align the user’s interest with the company’s interest. Presumably, the user’s goal is not token burn but some underlying task. The cheaper the company can accomplish that task, the more money the company keeps. If the user has to constantly retry because the model is bad, that’s more cost to the provider. If the model is big and slow and wastes tokens, that’s more cost to the provider. The more tasks that can be accomplished in the fixed quota, the better value perception by the user.
It's rather an equilibrium based on what they can get away with.
It's safe to say, that equilibrium is a safe distance from what's in the users interest.
Modern business seems to be forgetting this lesson, and Anthropic may not be "smart" by this definition, but it would be completely rational for them to look for ways to cut their customers' costs.
For any provider of proprietary inference, the targeted optimization of how (long) their models work according to their own goals is a central part of their business.
People believe those optimizations being about giving them the "best" inference. They fail to notice whose "best".
I’m also not running a multi billion or trillion dollar company, and probably never will if I keep doing it.
I’m okay with that.
So if you're not paying API rates, you need not worry. You can force the main conversation or subagents to either 5 minute or 1 hour in the Claude settings file if you would like.
If you are paying API rates, paying close attention to caching is important. 1 hour is best for sessions where you have to think a lot, examine output, or wait for long builds because 5 minute interruptions are very common. The price premium for 1-hour TTL isn't that high over 5-minute, so I use it by default.
It's also good to get in the habit of doing /compact when you know you might be AFK for more than the cache TTL. Doing the /compact on a long context conversation after the cache has expired is much more expensive.
No idea when they added that, Its gray text that looks exactly like the auto summary line, so easy to miss (as it only shows up when you're idle for 55 minutes or so, and have a session that's compact worthy - again no idea what threshold they use)
https://code.claude.com/docs/en/settings-reference#idlecompa...
Ah, this explains so much, I need to adjust my settings. Lately I've been using bigger models to drive smaller models to do changes, sometimes they run for 45 minutes or more, so I definitely need to tweak my subagent cache time window. I'm not on API billing, but still.
They are nice like that
What is a keep-alive ping for prompt caching? - You send the last request again with max_tokens set to 0 about every 4.5 minutes. The API reads the cached prefix, returns no output tokens and restarts the cache timer. In our replay, keep-alive pings capped by session depth cut a Claude coding bill by about 8 to 9% net.
lol if this works there is no way they are gonna let you keep getting away with it
How to defeat these countermeasures used to be covered in os courses. I suspect the llm vendors will adopt similar techniques.
https://algomaster.io/learn/operating-systems/multilevel-que...
Best ensure your subagents avoid getting blocked if there's any wait or command that takes more than 5 minute.
Ask your agent to look at its own usage metrics to see if you would have saved money by doing so. If your test suite is >5 mins then you likely will.
API is all 5m but apparently keeping it warm every 4.5 mins on API is fine.
This is what i heard.
Bet bet is to measure it yourself by observing billing/credit usage or time-to-first-token.
Claude Code is here: https://code.claude.com/docs/en/prompt-caching
If you're using OpenRouter they publish cache hit rates, which can be used as a sort of proxy, e.g.: https://openrouter.ai/deepseek/deepseek-v4.1-flash-1017#pric...
Generally, by Googling "(provider) llm cache cost and duration" - can't recommend any source that collects them all.
Generally OpenAI and Anthropic are very serious about this and document it well.
Google is currently a shit show but getting better if you're on Interactions API.
The not-$1T crowd, i.e. other inference providers, can't and won't really guarantee anything.
OpenRouter shows data on their cache hit rates.
On not-$1T-crowd APIs, they'll want to set an arbitrary hint that they'll use for server affinity. (i.e. Fireworks needs to know this request wants to run on the same server/cluster/whatever as the last request so it can get a cache hit)
I think they’d rather have you pay for the 60 minute vs the 5 minute cache than upload / download the huge KV cache at every request.
It uses a ridgeline chart to show how big each chat's context has grown and what it's spending.
It's self-labelled as a 15m read and a human in the loop should recognize it's about 3m, tops. Here:
LLM API context caches, by default, only last for 5 minutes on Anthropic and 30m on OpenAI.
If you use Claude, there's an hour cache for 2x the cost of the 5 minute one.
If you use OpenAI, there's a 12 hour cache for 2.5x the cost of the 30m one.
FWIW, it's very Chicken Little / "the sky is falling!!111!": the idea is if you walked away for > 5m between every Claude request, re-caching would be 23% of your bill.
I did indeed run into this problem when I was steering 4 or 5 chats that would ask for feedback that took a few minutes to provide. Pretty soon you're juggling a bunch of 5 min timers if you don't want every single response to have to rebuild the cache.
I could tell that this was AI-written just from the turn of phrase in the title before I even clicked :\
On subscription (so 1h cache) I run into this being even higher, reaching 50%, before I noticed problem.
10-100x cheaper is not something to sneeze at
Are they offering Opus 5.5 quality and quantity of 20$ Claude subscription at and 2$/month? Or 0.2$/month?
And start a new blank session with its own branch (and have the agent update the project readme) so you can restart without context.
It's a bit overkill for most users but depending on what you're asking it to work on it could theoretically traverse your local network to compromise devices/computers and escape the sandbox.
This is not something that happens, or that is worth spending time or energy thinking about.
Edit: Not likely to happen currently but having this infra makes it easier to demonstrate compliance with your orgs rules.
Unless you think it has some secret stash of 0days, in which case you should monitor its traffic and sell the RCE for a million bucks.
The problem I found was that in a multi-harness, multi-agent setup, the other workstreams may take over and then it comes back to a CC agent. Now it's no longer in cache and gets the hit of 800k token close to the limit (example). Burns tokens very, very quickly.
NOTE: you have to `/autocompact 300000` for every model; the setting is model-by-model.
[0] https://chrlschn.dev/blog/2026/10/larping-with-agents-and-wh...
1. This looks like API-billed traffic only. Claude Code defaults to a 1 hour cache, not 5 min! So if you're within your plan's usage, this doesn't really apply [1].
2. In the API, we have 5 min and 1 hour TTL options. The "23%" here for the 5 min option includes breaks over 30 min, where both Claude's and GPT's default caches have expired and the loss is the ~same (7.8% vs. 8.5%). If you run long sessions with breaks, and are using an API key, you could set "ttl": "1h". There will be a bit higher write price, though [2].
[1] https://code.claude.com/docs/en/prompt-caching
[2] https://platform.claude.com/docs/en/build-with-claude/prompt...
I measured not just anthropic and openai but also google and deepseek. The cache logic these providers have makes sense for chat but doesn't make sense for agentic workflows. My guess is they have already optimized this on their end or are working on it.
the length of time that a given AI/LLM provider caches prompts for...
(apparently 5 minutes in the case of Claude, 30 minutes in the case of ChatGPT (other vendors will have different numbers) -- if the claims of the article are accurate, as of the article's publication date -- and remember, those numbers even if accurate could be subject to change in the future...),
...does make a very real, important difference in AI/LLM economics!
That is, it's another variable in AI/LLM pricing/costing that must be accounted for!
And, I never saw it, nor thought about it, prior to reading this article...
So, an excellent article for getting me to consider it; for getting me to think about it!
There's even the ability to persist your kv cache to disk, so future session resumptions load back into context instantly without needing to do a full prefill ingestion by the LLM. (CachyLLaMA, iirc, not sure where the project is now)
But now, with Bonsai 2.5 27B, this is the first time that I don't need Haiku (or a similar cheap model) for tasks in their scope. I think local models are close to an inflection point in usefulness.
Note: I don't have anything local remotely close to reasoning capabilities of SOTA models such as Opus/Neon/Astra.
TDLR prompts are cached. Prompt cache hit == $. Cache miss == $$$$$$$. Claude ttl is 5 min. Codex ttl is 30 min. If u take longer than 5 min between turns then $$$$
for +i; send prompt=prompt+"."