I find it really weird that Anthropic uses only a five minute cache on the API. Even in the course of active work, many commands—compiling, running tests, etc—take longer than five minutes to complete.
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.
They probably do around the edges. But I bet they'd lose more if they raised the list price per token and included a longer cache time by default even if it the average bill works out the same.
They are for subscription plans, where they pay by token and the user pays a fixed cost.
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 seems like what would best align the interests of the customer and company would be if they’d charge by completed task instead of… tokens/time. (Why are these internal compute metrics being exposed to the customers?).
There are many such open questions about "clandestine token-maxing" that get glossed over.
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".
The amount Anthropic can charge per token is determined by how much value users get from those tokens. If users are getting more value, Anthropic can charge more and take a bigger profit.
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.
The interest of any provider of proprietary inference is to make the most money per token.
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.
Does the average user even know what value they are getting from Anthropic? As though there is some kind of metric?
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.
> The amount Anthropic can charge per token is determined by how much value users get from those tokens. If users are getting more value, Anthropic can charge more and take a bigger profit.
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.
That economic statement assumes that customers are rational, transactional (vs relationship/brand-driven) and are monitoring and optimizing their cost spending frequently.
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.
Since the API is bare, the use cases will be broader than just agent sessions -- automated scripting and customer-served chatbotting are two obvious supplemental use-cases. Those are likely to have very different cache dynamics compared to a Claude Code session, so 5m expiry might be the hit-rate-optimizing point.
> I find it really weird that Anthropic uses only a five minute cache on the API.
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.
The API is used for a lot more than agentic coding. I would not be surprised if 5 minute was preferred on average across all types of usage.
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.
yeah, not sure why you're downvoted, but the API is clearly for using Claude in your products that you serve to your users. It's also why it's priced higher since it's assumed to be close to where you make money. It's the same with cloud computing, where clouds could charge 1000x the involved compute for some per-access DB, but you wouldn't run a nuclear reactor simulation on Firebase.
Given the massive opacity around tokens and how they're used in closed systems we interact with I'm often surprised when discussions around them just assume there is no underhandedness involved in inflation or controlled deflation to maximize revenue.
This is a place where it'd probably good if there wasn't a default set. I think we leap too readily to providing defaults for settings without thinking through whether the value is something the user should be intentional about declaring or leaving as-is.
It's also less vram and hence bandwidth hungry so much friendlier to hold for longer and swapping in and out to storage. If kv cache is large enough and slow enough, then prefill could turn out to be faster than cache restore... Although it depends on how the cluster and infra is setup, either way, Anthropic is subsidizing the subscriptions if all benefits and limits and etc. are included by at least 2 orders of magnitude aka ~100x compared to API which is rather insane..
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.
it takes claude 15-30 min to add a disk layer cache after system memory FYI... have this going on my 8x v100 server for all openweight models I'm running. currently preferring glm-5.3-flash. prefill is around 3k tok/s, decode is about 80 tok/s. have room for 3x 262k sessions with room to spare. and memory for another million. then a 6.4TB NVMe for quite a bit more.
deepseek-v4.1-flash per token kv is IIRC 600-700 bytes. this is much, much less than other models. and 500x less than deepseek v3.
If you use the claude cli via subscription Oauth2- you will see that this endpoint does not accept five or sixty minute cache control directives in request bodies, just "ephemeral". So presumably they are using a sensible time period for normal use, but this report is on third party harnesses, so it is using the bill-per-token api.
You can select 1h via api, but it’s seldom useful really. If you handle stuff via api, you can just have a keepalive around 4 min checkmark. It is quite irritating though.
On a subscription plan (not API requests) Claude Code defaults to 1-hour cache duration for the main conversation and 5 minutes for subagents.
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.
Claude code actually compacts the main session just before the cache runs out automatically.
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)
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.
Everything old is new again. Something similar was a time honored technique for getting an OS scheduler to keep a long-running task at interactive priority by writing a character to the console every so often, so it looked like an interactive process.
How to defeat these countermeasures used to be covered in os courses. I suspect the llm vendors will adopt similar techniques.
Is there a pi plugin for resetting the keepalive? Sounds simple enough. From the article:
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.
If I'm not mistaken, on subscription plans your main agent defaults to 1 hour cache with subagents spawned by the main session on 5 minute cache timer.
Best ensure your subagents avoid getting blocked if there's any wait or command that takes more than 5 minute.
Yeah, this looks like a discussion of API traffic, not claude code subscription traffic. I'd be shocked to find out that my claude code sessions, which auto-compact "before the cache expires", after 54 minutes of idle time, due to claude code's own idleCompaction setting, was actually already expired at that point.
Welp, doing this immediately. I had to build a Rust build queue and a client lease system for a game I have been building entirely with agents (intentionally with a lot of subagents and multiple top-level sessions) just to avoid consuming all available memory and compute on a server I have laying around. I have a lot of subagents that end up having to wait for a long time for their turn to build and run the game to verify behavior.
It's not Claude Code so much as provider. If you're on a subscription plan this article doesn't apply to you. If you're using Vertex API or similar it defaults to 5m.
Several studies have found that performance degrades sharply after 100k tokens or so, even in models with much larger contexts. (The further out you get the lossier the attention gets from what I understood.)
(Which is funny, because you pay a premium on many providers for the worse attention!)
The last study I found was from a little while ago though, and there's been a lot of development in attention mechanisms since then. So it might be less bad now.
I guess that refers to cache pricing? (Surely after some time the tokens are no longer cached, but you mean they still charge you as though they were?) Either way, that's surprising.
This is obvious if you just put cache timeout in your statusline. If the nature of your work is such that every time you return to the window the 5m cache is expired, bump it up.
Where can I find cache "duration" of different providers? I have never seen such information, despite it being a very big deal in cost estimation. Or maybe it's dynamic?
It's not dynamic, in the sense pricing has rules, but, it is dynamic in the sense you won't always hit the cache.
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)
Not all providers publish it, and aren't always correct when they do. For some providers (e.g. DeepSeek, Antigravity Gemini) it is indeed dynamic/not guaranteed.
Bet bet is to measure it yourself by observing billing/credit usage or time-to-first-token.
This is a big contributor to long-running sessions. I built a small CLI that opens in a tmux popup and shows what my Cursor agents cost: https://github.com/rishabhBudhouliya/tend.
It uses a ridgeline chart to show how big each chat's context has grown and what it's spending.
I've felt this long before and my agent's contexts are compacted very very often. Even though they work on a common bus, I try to keep them regularly pooled back to minimum.
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.
As stated by others, it’s a precaution. It’s been shown that agents can get desperate and use whatever they can get their hands on to solve the problem at hand. I don’t want them snooping around the network for information, credentials or test data.
Edit: Not likely to happen currently but having this infra makes it easier to demonstrate compliance with your orgs rules.
Many services have ports open, which could give access to things you dont want to share. E.g. if you run syncthing, there's full access to your synced folders if you have localhost access.
These AI written articles are exhaustingly long, and the #s included make it feel very scientific but are one offs for one person.
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.
Not even 3 min. Took like 3 seconds to skim the title and understand that it's about cache misses (and that Claude is probably presenting it in some inane incomprehensible technobabble so someone who isn't familiar with prompt caching's budget impact already is going to read the whole thing and still have zero idea wtf is going on)
>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.
> 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.
On subscription (so 1h cache) I run into this being even higher, reaching 50%, before I noticed problem.
Edwin from Anthropic here. Thanks for the thorough writeup. I will point out two things:
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].
Requisite smarmy comment about how this is not an issue with local models.
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)
Up until a few weeks ago, I wouldn't say it (at least for my use case).
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.
Neon really cooked with tamping down on the inane incomprehensible Claude slop huh? It's so damn annoying when they spew this poetic babbling gibberish.
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 $$$$
I find it really weird that Anthropic uses only a five minute cache on the API. Even in the course of active work, many commands—compiling, running tests, etc—take longer than five minutes to complete.
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.
Interesting that you'd conclude Anthropic is looking out for the economic interests of their customers over their own.
I regularly favor the economic interests of my customers over my own.
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.
It's a competitive market, is it not? If they don't, they'll lose market share to Google or OpenAI
They probably do around the edges. But I bet they'd lose more if they raised the list price per token and included a longer cache time by default even if it the average bill works out the same.
They are for subscription plans, where they pay by token and the user pays a fixed cost.
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 seems like what would best align the interests of the customer and company would be if they’d charge by completed task instead of… tokens/time. (Why are these internal compute metrics being exposed to the customers?).
For the same reason cars are sold with fuel gauges and people ask how many liters of gas they need to go 100 km.
It's a useful metric, especially for those who know what it means.
That's not true.
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.
There are many such open questions about "clandestine token-maxing" that get glossed over.
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".
The amount Anthropic can charge per token is determined by how much value users get from those tokens. If users are getting more value, Anthropic can charge more and take a bigger profit.
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.
The interest of any provider of proprietary inference is to make the most money per token.
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.
Does the average user even know what value they are getting from Anthropic? As though there is some kind of metric?
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.
> The amount Anthropic can charge per token is determined by how much value users get from those tokens. If users are getting more value, Anthropic can charge more and take a bigger profit.
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.
That economic statement assumes that customers are rational, transactional (vs relationship/brand-driven) and are monitoring and optimizing their cost spending frequently.
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.
From their side as well it's preferable for uses to hit the cache. Definitely cheaper for them too
Since the API is bare, the use cases will be broader than just agent sessions -- automated scripting and customer-served chatbotting are two obvious supplemental use-cases. Those are likely to have very different cache dynamics compared to a Claude Code session, so 5m expiry might be the hit-rate-optimizing point.
> I find it really weird that Anthropic uses only a five minute cache on the API.
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...
> You get the cheapest option (5 minutes) if you don't specify the time.
Okay, but isn't it weird that the default is a giant footgun?
The API is used for a lot more than agentic coding. I would not be surprised if 5 minute was preferred on average across all types of usage.
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.
yeah, not sure why you're downvoted, but the API is clearly for using Claude in your products that you serve to your users. It's also why it's priced higher since it's assumed to be close to where you make money. It's the same with cloud computing, where clouds could charge 1000x the involved compute for some per-access DB, but you wouldn't run a nuclear reactor simulation on Firebase.
> you wouldn't run a nuclear reactor simulation on Firebase.
I mean... you say I wouldn't, but im all up for trying.
naturally on a single instruction move-only VM in real time database that works via database trigger cloud functions!
It's what their business model tells them to do: maximize profit per token.
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.
Given the massive opacity around tokens and how they're used in closed systems we interact with I'm often surprised when discussions around them just assume there is no underhandedness involved in inflation or controlled deflation to maximize revenue.
> footgun
What a load-bearing observation. Good instinct!
This is a place where it'd probably good if there wasn't a default set. I think we leap too readily to providing defaults for settings without thinking through whether the value is something the user should be intentional about declaring or leaving as-is.
Deepseek seemingly stores the cache for literally days, so its a really odd choice to have it so short.
Latest deepseek kv cache is tiny compared to other models thanks to its architecture, so storing it requires much less space
It's also less vram and hence bandwidth hungry so much friendlier to hold for longer and swapping in and out to storage. If kv cache is large enough and slow enough, then prefill could turn out to be faster than cache restore... Although it depends on how the cluster and infra is setup, either way, Anthropic is subsidizing the subscriptions if all benefits and limits and etc. are included by at least 2 orders of magnitude aka ~100x compared to API which is rather insane..
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.
If the KV cache is in RAM (whether system or GPU) it's because RAM is at a huge $$$ premium right now.
it takes claude 15-30 min to add a disk layer cache after system memory FYI... have this going on my 8x v100 server for all openweight models I'm running. currently preferring glm-5.3-flash. prefill is around 3k tok/s, decode is about 80 tok/s. have room for 3x 262k sessions with room to spare. and memory for another million. then a 6.4TB NVMe for quite a bit more.
deepseek-v4.1-flash per token kv is IIRC 600-700 bytes. this is much, much less than other models. and 500x less than deepseek v3.
If you use the claude cli via subscription Oauth2- you will see that this endpoint does not accept five or sixty minute cache control directives in request bodies, just "ephemeral". So presumably they are using a sensible time period for normal use, but this report is on third party harnesses, so it is using the bill-per-token api.
You can select 1h via api, but it’s seldom useful really. If you handle stuff via api, you can just have a keepalive around 4 min checkmark. It is quite irritating though.
On a subscription plan (not API requests) Claude Code defaults to 1-hour cache duration for the main conversation and 5 minutes for subagents.
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.
Claude code actually compacts the main session just before the cache runs out automatically.
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)
That is indeed a setting that is in by default now, though I've noticed in some session that it doesn't trigger and I have no idea why
> and 5 minutes for subagents.
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.
Everything old is new again. Something similar was a time honored technique for getting an OS scheduler to keep a long-running task at interactive priority by writing a character to the console every so often, so it looked like an interactive process.
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...
Is there a pi plugin for resetting the keepalive? Sounds simple enough. From the article:
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.
"hey claude make a plugin for our api proxy that removes 1hr cache requests" and sends keepalives like this ^^^
lol if this works there is no way they are gonna let you keep getting away with it
You pay for the cache reads. It's not a loophole.
It’s actually builtin pi, see cache warming https://docs.pi.dev/latest/settings#model-and-thinking
That was useful to know. Thanks!
If I'm not mistaken, on subscription plans your main agent defaults to 1 hour cache with subagents spawned by the main session on 5 minute cache timer.
Best ensure your subagents avoid getting blocked if there's any wait or command that takes more than 5 minute.
Yeah, this looks like a discussion of API traffic, not claude code subscription traffic. I'd be shocked to find out that my claude code sessions, which auto-compact "before the cache expires", after 54 minutes of idle time, due to claude code's own idleCompaction setting, was actually already expired at that point.
You can also spawn subagents with 1h TTLs if you know they'll be doing activity with lots of time spent waiting
Welp, doing this immediately. I had to build a Rust build queue and a client lease system for a game I have been building entirely with agents (intentionally with a lot of subagents and multiple top-level sessions) just to avoid consuming all available memory and compute on a server I have laying around. I have a lot of subagents that end up having to wait for a long time for their turn to build and run the game to verify behavior.
Do those tokens cost more? Why would anyone choose the shorter cache?
They cost 2x as much
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.
Probably takes more usage though, so it's the same deal
Though not the same cost since cache hits are significantly cheaper than a new cache load.
Eg Opus 5.5 is $4/m input vs $0.2/m cache hit
Isn't Claude Code on a 1hr cache?
It's not Claude Code so much as provider. If you're on a subscription plan this article doesn't apply to you. If you're using Vertex API or similar it defaults to 5m.
It applies on a subscription too. Not using the cache burns your usage faster.
Yes but the cache on subscription plans is 1hr
Not for subagents it isnt, 5 minutes for them
For some context, on Codex subscriptions, the cache is forever
I also make it compact at 200K tokens and not 1M. Has anyone seen a benefit to using 1M context wth Fable?
Several studies have found that performance degrades sharply after 100k tokens or so, even in models with much larger contexts. (The further out you get the lossier the attention gets from what I understood.)
(Which is funny, because you pay a premium on many providers for the worse attention!)
The last study I found was from a little while ago though, and there's been a lot of development in attention mechanisms since then. So it might be less bad now.
I guess that refers to cache pricing? (Surely after some time the tokens are no longer cached, but you mean they still charge you as though they were?) Either way, that's surprising.
Okay and? The article is not about subagents, and subagents are a natural fit for the shorter cache window.
On the subscription plan it is 1h for the main agent, its subagents get 5m with some exceptions that also get 1h.
API is all 5m but apparently keeping it warm every 4.5 mins on API is fine.
This is what i heard.
This is obvious if you just put cache timeout in your statusline. If the nature of your work is such that every time you return to the window the 5m cache is expired, bump it up.
Where can I find cache "duration" of different providers? I have never seen such information, despite it being a very big deal in cost estimation. Or maybe it's dynamic?
It's not dynamic, in the sense pricing has rules, but, it is dynamic in the sense you won't always hit the cache.
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)
Not all providers publish it, and aren't always correct when they do. For some providers (e.g. DeepSeek, Antigravity Gemini) it is indeed dynamic/not guaranteed.
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...
For Codex subscriptions, cache does not expire
This is a big contributor to long-running sessions. I built a small CLI that opens in a tmux popup and shows what my Cursor agents cost: https://github.com/rishabhBudhouliya/tend.
It uses a ridgeline chart to show how big each chat's context has grown and what it's spending.
I've felt this long before and my agent's contexts are compacted very very often. Even though they work on a common bus, I try to keep them regularly pooled back to minimum.
What helps: run agents in a VM so they can have full control and don’t need to wait for your approval. Firewall it from your local network.
And start a new blank session with its own branch (and have the agent update the project readme) so you can restart without context.
Why firewall it from your local network?
To not let the clanker own every computer on your local network?
isolation from your own agents hacking you.
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.
As stated by others, it’s a precaution. It’s been shown that agents can get desperate and use whatever they can get their hands on to solve the problem at hand. I don’t want them snooping around the network for information, credentials or test data.
Edit: Not likely to happen currently but having this infra makes it easier to demonstrate compliance with your orgs rules.
Many services have ports open, which could give access to things you dont want to share. E.g. if you run syncthing, there's full access to your synced folders if you have localhost access.
These AI written articles are exhaustingly long, and the #s included make it feel very scientific but are one offs for one person.
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.
Nice summary.
I could tell that this was AI-written just from the turn of phrase in the title before I even clicked :\
Not even 3 min. Took like 3 seconds to skim the title and understand that it's about cache misses (and that Claude is probably presenting it in some inane incomprehensible technobabble so someone who isn't familiar with prompt caching's budget impact already is going to read the whole thing and still have zero idea wtf is going on)
There’s potential for a 12hr cache on OpenAI?? That’s so good! Thank you I didn’t know this, I’ll have to configure that
>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.
Yep, KISS seems to have been thrown out the window in the age of AI
> 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.
On subscription (so 1h cache) I run into this being even higher, reaching 50%, before I noticed problem.
just use deepseek
10-100x cheaper is not something to sneeze at
shhh don't share our secret
Via what portal?
Deepseek official API is best.
Can I get close to Opus 5.5 levels of goodness?
10-100x cheaper than what?
Are they offering Opus 5.5 quality and quantity of 20$ Claude subscription at and 2$/month? Or 0.2$/month?
Link should be changed to https://code.claude.com/docs/en/prompt-caching
Edwin from Anthropic here. Thanks for the thorough writeup. I will point out two things:
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...
Requisite smarmy comment about how this is not an issue with local models.
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)
Up until a few weeks ago, I wouldn't say it (at least for my use case).
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.
What do you use bonsai for? I haven’t really played with it yet
Requisite smarmy reply about how local models are still a subscription, NVIDIA just bills you for it up front
Neon really cooked with tamping down on the inane incomprehensible Claude slop huh? It's so damn annoying when they spew this poetic babbling gibberish.
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 $$$$
Are you saying this is neon? This one sounds like slop to me.
It feels a little click baity to not include the word API in that title somewhere.
That's why pi has cache warming.
so we need this loop to keepalive?
for +i; send prompt=prompt+"."
Rust developers be like: "seriously?"
indecipherable slop article
This is so dumb. Sign the cache and ship it to the client, accept signed caches from clients, problem solved.
What about the latency problem? Caching takes gigabytes for each session.
How do you figure?
I would rather pay for bandwidth than tokens anyway.