If you send the same long system prompt, document or codebase to an AI API again and again, most of your bill may be repeat input. Prompt caching fixes that. The provider stores the processed prefix of your prompt, and later requests that start with the same prefix are billed at a small fraction of the normal input price. On Claude’s newest models a cache hit costs as little as 2.5% to 5% of the normal input rate. This guide covers how caching works on Claude, OpenAI, Gemini and the cheaper APIs, what each one costs, and the mistakes that quietly turn your hit rate to zero.
- Claude: you opt in with
cache_control. Writes cost 1.25x input (5-minute TTL) or 2x (1-hour TTL). Reads cost 0.1x by default, 0.05x on Opus 5.5 and Sonnet 5.5, and 0.025x on Fable 5.1 and Mythos 5.1. - OpenAI: caching is automatic for prompts of 1,024+ tokens. Cached input is roughly 10% of the normal price, and GPT-5.6 and newer add a 1.25x write charge.
- Gemini: implicit caching is on by default and costs nothing to write. Explicit caches bill storage per hour.
- DeepSeek: disk caching is automatic and hits cost a tiny share of the input price.
- The golden rule: put stable content first (tools, system prompt, documents) and changing content last. One changed character early in the prompt breaks the cache for everything after it.
What prompt caching is (and what it is not)
A language model has to process every input token before it can answer. When the first part of your prompt is identical across requests, the provider can save the processed state of that prefix and reuse it. You pay less for the reused tokens, and the time to first token usually drops too, because the model skips work it already did.
Three things are worth knowing up front:
- It is prefix based. The cache matches from the start of the prompt. If anything changes near the top, everything after that point is a miss.
- It does not change the answer. Caching affects cost and speed only. The model output is the same as it would be without the cache.
- It is not response caching. The provider does not store and replay answers. If you want to skip identical calls entirely, that is a separate layer you build yourself (for example, a Redis lookup keyed on the full request).
Caching pays off most for chatbots with long system prompts, coding agents that resend a big codebase every turn, RAG apps that put the same documents in front of many questions, and agent loops that repeat tool definitions on every step.
Prompt caching prices by provider (November 2026)
The table below uses each provider’s documented multipliers. Claude figures come straight from Anthropic’s docs. The others were cross-checked against two independent pricing roundups from October 2026, so check the provider’s own pricing page before you budget a large project.
| Provider | How you enable it | Write cost | Cache read price | Lifetime | Minimum prompt |
|---|---|---|---|---|---|
| Anthropic Claude | cache_control (top level or per block) |
1.25x input (5 min), 2x (1 h) | 0.1x default; 0.05x Opus/Sonnet 5.5; 0.025x Fable/Mythos 5.1 | 5 min or 1 h, refreshed on each hit | 512 to 4,096 tokens by model |
| OpenAI (GPT-5.6 and newer) | Automatic, optional explicit breakpoints | 1.25x input | About 0.1x input | About 30 minutes | 1,024 tokens |
| OpenAI (older models) | Automatic | None | Model’s cached rate | Minutes, or 24 h with extended retention | 1,024 tokens |
| Google Gemini (implicit) | Automatic | None | About 5-10% of input, by model | Short, not published | 2,048 to 4,096 tokens |
| Google Gemini (explicit) | caches.create |
Storage billed per hour | Cached rate | 1 h default, you set the TTL | Per model |
| DeepSeek | Automatic disk cache | None | Around 1-2% of input | Hours, best effort | 64-token blocks |
| xAI Grok | Automatic, helped by a conversation ID | None | About 25% of input | Not published | Not published |
| Mistral | Automatic | None | About 10% of input | Not published | 64-token blocks |
For the base input and output prices these multipliers apply to, see our Claude API pricing, OpenAI API pricing, Gemini API pricing and DeepSeek API pricing guides, or the side-by-side AI API pricing comparison.
Claude prompt caching: how to set it up
Claude gives you the most control, and on the newest models the cheapest hits. You can turn caching on in two ways.
Automatic caching (easiest)
Add cache_control at the top level of the request. Claude places the breakpoint on the last cacheable block and moves it forward as the conversation grows, which suits multi-turn chat.
response = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
cache_control={"type": "ephemeral"},
system="...your long system prompt...",
messages=[{"role": "user", "content": "Hello"}],
)
Explicit breakpoints (more control)
Put cache_control on the specific blocks you want cached, such as tool definitions, the system prompt, or a large document. You can use up to four breakpoints per request. Automatic caching uses one of those four slots.
system=[{
"type": "text",
"text": "...long reference document...",
"cache_control": {"type": "ephemeral", "ttl": "1h"}
}]
Claude cache prices per million tokens
| Model | Base input | 5-min write | 1-hour write | Cache hit |
|---|---|---|---|---|
| Claude Fable 5.1 | $10 | $12.50 | $20 | $0.25 |
| Claude Opus 5.5 | $4 | $5 | $8 | $0.20 |
| Claude Sonnet 5.5 | $2 | $2.50 | $4 | $0.10 |
| Claude Haiku 5.5 (prompts up to 100K) | $0.10 | $0.125 | $0.20 | $0.01 |
| Claude Sonnet 4.6 | $3 | $3.75 | $6 | $0.30 |
| Claude Haiku 4.5 | $1 | $1.25 | $2 | $0.10 |
Useful details from the docs:
- The minimum cacheable length is 512 tokens on the 5.x generation, 1,024 on Opus 4.8 and Sonnet 4.6, and 4,096 on Haiku 4.5. Shorter prompts are just processed normally, with no error.
- The 5-minute TTL resets every time the cache is hit, so a busy app can keep a cache warm for hours at the cheap write rate.
- Pick the 1-hour TTL when requests arrive less often than every 5 minutes, for example a support bot with gaps between users. It costs 2x on the write, so it only pays off if you would otherwise rewrite the cache more than once an hour.
- Cache multipliers stack with the Batch API discount, so batch jobs that share a long prefix get both savings.
- Check
cache_creation_input_tokensandcache_read_input_tokensin the response’s usage object to confirm hits.
If you hit rate limits while testing, our Claude API 429 and 529 error fix guide helps. Cached tokens are generally kinder to your input-token rate limit too, which is another reason to cache.
OpenAI prompt caching
OpenAI caches automatically. Any prompt of 1,024 tokens or more is eligible, and you see the hit count in usage.prompt_tokens_details.cached_tokens. You do not need to change your code to benefit.
From GPT-5.6 onward, OpenAI charges a write premium of 1.25x input and keeps caches for about 30 minutes. It also added optional controls: a prompt_cache_key to route requests that share a prefix to the same cache, and explicit breakpoints if you want to mark where the stable part ends. Older models cache with no write fee, and some support extended 24-hour retention.
Two practical tips for OpenAI:
- Set a stable
prompt_cache_keyper tenant or per agent. Without it, high traffic can spread identical prefixes across machines and lower your hit rate. - Keep the tool list and the system prompt byte-for-byte identical. Reordering tools or adding a timestamp to the system prompt breaks the prefix.
Gemini context caching
Google offers two modes.
- Implicit caching is on by default for Gemini 2.5 and newer. There is no write fee, and hits are billed at a small share of the input rate (around 5% on Gemini 4 Argon and 10% on 3.x models, per October 2026 pricing). The catch is that you cannot control how long it lasts.
- Explicit caching lets you create a named cache with
caches.create, set its TTL, and pass it ascachedContentin later calls. You pay for storage by the hour on top of the cheap read rate. It suits a large video, PDF set or codebase that many users query over a day. Note that Gemini 4 Argon supports implicit caching only.
Gemini’s minimum is higher than Claude’s (2,048 to 4,096 tokens), so very short system prompts will not cache. Watch cachedContentTokenCount in the usage metadata. Google has also announced price increases for Gemini 4 Argon (December 1, 2026) and Gemini 3.8 Flash (January 1, 2027), which makes caching more valuable on those models. Our Gemini API pricing guide tracks the base rates.
DeepSeek, Grok, Mistral and Qwen
DeepSeek has cached automatically to disk for a long time. There is nothing to set, and the usage object reports prompt_cache_hit_tokens and prompt_cache_miss_tokens. Cache hits are priced at a very small fraction of normal input, and off-peak hours are cheaper again, which makes DeepSeek one of the cheapest options for long, repeated contexts.
xAI Grok caches on all language models. Sending the same x-grok-conv-id header (or a prompt_cache_key) across turns improves hits, and cached input is roughly a quarter of the normal price. See Grok pricing for base rates.
Mistral caches automatically at about 10% of input. Qwen on Alibaba Model Studio offers both implicit caching and Claude-style explicit cache_control blocks.
If you reach several of these through one gateway, check how it passes cache settings along. Our OpenRouter guide covers that, since provider routing can send repeat requests to a backend that has no warm cache.
Worked cost example: how much does caching save?
Here is a simple calculation, not a benchmark. Say a support assistant on Claude Sonnet 5.5 sends a 50,000-token system prompt (product docs plus instructions) with every request, and handles 100 requests while the cache stays warm.
| Scenario | Calculation | Cost of the 50K prefix |
|---|---|---|
| No caching | 100 x 50K tokens x $2 per million | $10.00 |
| Caching (5-min TTL kept warm) | 1 write: 50K x $2.50/M = $0.125, plus 99 hits: 99 x 50K x $0.10/M = $0.495 | About $0.62 |
That is about a 94% cut on the repeated input. The user messages and output tokens still bill at normal rates, so your total saving depends on how much of each request is shared prefix. For agent loops and RAG apps the shared part is often 80% or more of the input, so the bill drops sharply.
The same 100 calls with almost no reuse (for example, a new document every time) would cost slightly more with caching than without, because you pay the write premium and never collect the discount. Cache only what repeats.
Mistakes that kill your cache hit rate
- Timestamps or request IDs in the system prompt. “Today is 5 November 2026, 18:42:07” at the top changes every call. Move dynamic values into the latest user message.
- Changing tool order. Tools usually sit at the very start of the prompt. Sort them the same way every time.
- Non-deterministic JSON. If your code serializes a dictionary with random key order, the bytes differ and the cache misses.
- Prompts under the minimum. A 400-token system prompt will not cache on most providers. Do not count savings you are not getting.
- Traffic too sparse for the TTL. If calls arrive every 10 minutes, a 5-minute Claude cache expires between them. Use the 1-hour TTL or batch the work.
- Editing earlier turns. Trimming or summarising old messages in a chat changes the prefix. Do it rarely and in big steps, not on every turn.
- Not checking usage fields. Always log cache read and write token counts. A hit rate of zero is the most common silent bug.
Coding tools such as Claude Code, Codex and Cursor rely heavily on caching under the hood, which is why their long sessions stay affordable. Our Claude Code commands cheat sheet and Codex guide explain how their context handling works.
Troubleshooting: cache not hitting
If your bill is not dropping, the usage fields tell you why. Start with the symptom you see, then work through the likely causes. Claude rows are based on Anthropic’s prompt caching docs.
| Problem | Likely cause | Fix |
|---|---|---|
Claude: cache_creation_input_tokens and cache_read_input_tokens are both always 0 |
The cached prefix is below the model’s minimum (512 tokens on Claude 5.x models, 1,024 on Opus 4.8 and Sonnet 4.6, 4,096 on Haiku 4.5). Short prompts are processed normally with no error | Move more stable content (instructions, examples, tool definitions) above the breakpoint, or accept that this prompt is too short to cache. |
| Claude: a cache write on every request, reads never | The breakpoint sits on a block that changes each call, such as one containing a timestamp or the new user message | Put cache_control on the last block that stays identical across requests. |
| Claude: hits stop in long conversations | Each breakpoint only looks back 20 blocks for an earlier cache entry | Add a second breakpoint earlier in the conversation. You have up to 4 per request, and automatic caching uses one of them. |
| Claude: parallel requests all miss | A cache entry only becomes available after the first response starts | Send one request, wait for its response to begin, then fan out the rest. |
| Claude: misses after changing a setting | Changing tool_choice, adding or removing images, or changing thinking or effort settings invalidates part of the cache |
Keep these settings fixed for requests that share a prefix. |
Claude: 400 error with top-level cache_control |
The legacy Amazon Bedrock integration (Opus 4.6 and earlier) does not support automatic caching, or 4 explicit breakpoints already use every slot | Use block-level breakpoints on legacy Bedrock, or remove one explicit breakpoint. |
| Claude: error when mixing TTLs | A 1-hour entry was placed after a 5-minute entry | Order breakpoints so longer TTLs come first: 1-hour entries before 5-minute ones. |
OpenAI: cached_tokens stays 0 |
Prompt under 1,024 tokens, a changing prefix, or traffic spread across machines | Keep the system prompt and tool list byte-identical and set a stable prompt_cache_key. |
Gemini: cachedContentTokenCount is 0 |
Prompt below the 2,048 to 4,096 token minimum, or implicit caching simply did not hit | Lengthen the shared prefix, or use explicit caching with caches.create on models that support it (not Gemini 4 Argon). |
Anthropic’s docs also describe cache diagnostics, which compare consecutive requests and report where the prompt prefix diverged. That is the fastest way to find a stray timestamp.
FAQ
Does prompt caching change the model’s answers?
No. It changes only cost and speed. The output is the same as an uncached request with the same input and settings.
Is prompt caching free to use?
Turning it on is free. On Claude and on OpenAI’s newer models you pay a premium when a cache is written, then a large discount on every hit. On Gemini implicit caching, DeepSeek, Grok and Mistral there is no write fee.
Which provider has the cheapest cached input?
In relative terms, Claude Fable 5.1 and Mythos 5.1 (2.5% of input) and DeepSeek (a few percent or less) are the cheapest. In absolute dollars per million tokens, small models such as Claude Haiku 5.5 at $0.01 per million cached tokens and DeepSeek’s flash model are the lowest.
How long does a cache last?
Claude offers 5 minutes or 1 hour, refreshed on each hit. OpenAI’s newer models keep caches for about 30 minutes. Gemini’s explicit caches last as long as the TTL you set and pay storage for. DeepSeek’s disk cache usually lasts hours on a best-effort basis.
Can I combine caching with the Batch API?
Yes on Claude, where the discounts stack. Check each provider’s docs, since batch jobs may run on hardware where the cache is less likely to be warm.
Does caching help with rate limits?
Often, yes. Cached input is cheaper to serve, and some providers count it more lightly against input-token limits. Check your provider’s rate-limit docs for the exact rule.



