Prompt caching lets an AI provider store its processing of the beginning of your prompt, so the next request that starts with exactly the same text skips that work. Cached input tokens are billed at a fraction of the normal price and the response starts sooner, but only the identical prefix is reused, and only for a few minutes unless you pay for longer.
It is an API feature. Anthropic's Claude API turns it on with a cache_control field; OpenAI and Google's Gemini apply it automatically on supported models. The details below are from each vendor's documentation as of October 2026.
What actually gets cached
Before a language model writes a single word, it processes every input token and builds internal state for them (the attention "key-value" representations). For a long system prompt or a 50-page document, that processing is a large share of the work. Prompt caching keeps that state for a prefix of the prompt. Anthropic's docs describe it as holding key-value cache representations and cryptographic hashes of the cached content in memory, not stored at rest.
Two consequences follow:
- The answer is not cached. The model still generates a new response every time. Anthropic states that prompt caching has no effect on output token generation and the response is identical to what you'd get without it.
- Only a prefix can be reused. The model processes tokens in order, so the cache covers everything from the first token up to some point. Change one character near the start and everything after it has to be processed again.
How prefix matching works
Anthropic builds the cacheable prefix in a fixed order: tools, then system, then messages. A cache hit requires "100 percent identical prompt segments, including all text and images" up to the cache breakpoint. A typical request structured for caching looks like this:
{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"system": [
{
"type": "text",
"text": "...8,000 tokens of instructions and reference material...",
"cache_control": {"type": "ephemeral"}
}
],
"messages": [
{"role": "user", "content": "Summarise section 4 for a new hire."}
]
}
The long, stable system block ends with the breakpoint. The user's question comes after it, so a different question next time still hits the cache. You can set up to 4 breakpoints, or add a single top-level cache_control field and let the API place the breakpoint on the last cacheable block automatically.
OpenAI's guidance is the same in substance: put stable instructions and shared reference material first, and move dynamic content such as timestamps or user-specific text to the end. Caching is on by default for supported OpenAI models; the whole rendered prefix must match.
Lifetimes and minimum sizes
| Anthropic | OpenAI | Google Gemini | |
|---|---|---|---|
| Turned on by | cache_control (block-level or top-level) | Automatic on supported models | Implicit caching automatic on Gemini 2.5 and newer; explicit caching also available |
| Lifetime | 5 minutes, refreshed free on each hit; 1 hour optional ("ttl": "1h") | Depends on model: 5 to 10 minutes idle (up to 1 hour) on earlier models, at least 30 minutes on GPT-5.6 and later | Not stated for implicit caching |
| Minimum prefix | 512 to 4,096 tokens, by model | 1,024 tokens on GPT-5.6 and later | 2,048 or 4,096 tokens, by model |
| Where hits show up | usage.cache_read_input_tokens | usage.input_tokens_details.cached_tokens | usage.total_cached_tokens |
To check how big your prefix is before relying on caching, paste it into the token counter. Counts differ slightly between vendors' tokenizers, so leave some margin above the minimum.
When prompt caching pays off: the break-even maths
Anthropic charges extra to write a cache entry and much less to read one. Relative to the normal input price, a 5-minute write costs 1.25×, a 1-hour write costs 2×, and a read costs 0.1× on most models (some newer models are cheaper still). Using those multipliers, here is what sending the same prefix several times costs, in multiples of one uncached send:
| Times the prefix is sent | No caching | 5-minute cache | 1-hour cache |
|---|---|---|---|
| 1 | 1.00 | 1.25 | 2.00 |
| 2 | 2.00 | 1.35 | 2.10 |
| 3 | 3.00 | 1.45 | 2.20 |
| 10 | 10.00 | 2.15 | 2.90 |
Each row is one write plus (n − 1) reads at 0.1×, so you can extend it yourself. The pattern:
- A 5-minute cache pays for itself as soon as the prefix is reused once within the lifetime.
- A 1-hour cache needs at least two reuses to beat no caching (2.20 vs 3.00), but it survives gaps between requests that would let a 5-minute entry expire.
- A cache entry that is written and never read costs 25% to 100% more than not caching at all. Put breakpoints only where reuse is likely.
Because every hit refreshes the 5-minute timer at no extra cost, a busy chatbot or agent loop that sends a request every minute or two can keep one cache entry alive indefinitely at the read price.
What breaks the cache
Anthropic's documentation lists changes that invalidate cached segments. A change at one level invalidates that level and everything after it, while earlier segments stay valid:
- Tool definitions (names, descriptions, parameters): invalidate the entire cache.
- Turning web search or citations on or off: modifies the system prompt, so the system and message caches are invalidated.
tool_choicechanges and adding or removing images: invalidate the message cache.- Thinking settings: changing them always invalidates the message cache, and on some models the system and tool caches as well.
The everyday mistakes are simpler: a current date or request ID at the top of the system prompt, tools serialised in a different order on each request, or a user's name inserted into the instructions. Each makes the prefix unique per request, so you pay the write premium every time and never get a read.
How to confirm caching is working
Send the same request twice within a few seconds and compare the usage block. On Anthropic's API, the first response should show tokens under cache_creation_input_tokens and the second under cache_read_input_tokens. The docs give the total input as cache_read_input_tokens + cache_creation_input_tokens + input_tokens, where input_tokens is only the part after the last breakpoint. If both cache fields are 0, the prompt was not cached, most often because it is below the minimum length.
On OpenAI, look at usage.input_tokens_details.cached_tokens on the second request. A value of 0 after an identical repeat means the prefix was too short or something early in it changed.
Where prompt caching fits
Caching helps most when a large, fixed block is reused many times: a long system prompt, tool definitions for an agent, a document you ask several questions about, or a growing chat history where each turn repeats all earlier turns. It does nothing for one-off prompts or for the output side of the bill. For the other ways to cut costs, see how to reduce AI token usage, and for why long prompts are expensive in the first place, what a context window is.
Frequently asked questions
- Does prompt caching change the model's answer?
- No. Only the processing of the input prefix is reused; the model still generates a fresh response. Anthropic's documentation states that the response is identical to what you would get without prompt caching. It is not a cache of previous answers.
- Can other users hit my cache?
- No. A cache entry is keyed on a hash of the exact prompt prefix and is scoped to your account. Anthropic states that caches are never shared across organizations, even for identical prompts, and on its own API they are isolated per workspace within an organization.
- Does prompt caching work in the ChatGPT or Claude apps?
- Prompt caching is an API feature that developers control and are billed for. The consumer chat apps manage their own infrastructure, and you have no setting for it there. If you build on the API, you see caching directly in the usage fields of each response.
- Why is my prompt not being cached?
- The three common causes are a prefix below the model's minimum length, something that changes near the start of the prompt (a timestamp, a user name, reordered tools), and requests spaced further apart than the cache lifetime. Anthropic returns no error for a too-short prompt; the cache fields in the usage block are simply zero.