Prompt Caching: How It Works and What It Saves in 2026
Table of contents:
Quick Answer:
Prompt caching lets an LLM provider reuse the work it already did on the start of your prompt.
If a request begins with exactly the same tokens as a recent one (the same system prompt, tools or document), the provider skips reprocessing that part and bills it at a steep discount, usually 90–95% off.
Answers are unchanged, and long prompts respond faster. Caching is automatic on OpenAI and Gemini. On Claude, you turn it on with a cache_control field.
If your app sends the same long system prompt, tool list or document with every request, you're paying to process those tokens again and again. Caching fixes that.
It's one of the biggest cost levers in LLM APIs, but the rules differ by provider and changed a lot in 2026.
This guide explains how prompt caching works and what it costs at Anthropic, OpenAI, Google and Amazon Bedrock.
It also covers what breaks the cache, how to check it's working, and what to watch for when you call models through a gateway like ScriptRun's OpenAI-compatible API, which gives you one key for many models.
Prices, limits and TTLs below were checked against each provider's own documentation on November 27, 2026.
Disclosure: ScriptRun publishes this article and sells access to models from several providers.
What is prompt caching
Prompt caching is a feature of LLM APIs that stores the model's processed state for the beginning of a prompt.
When a later request starts with exactly the same tokens, the model reuses that state instead of computing it again.
Before a model writes a single word, it reads your whole input (system prompt, tools, documents, conversation history) and computes internal values for every token. This step, called prefill, is the expensive part of a long prompt.
With caching, the provider keeps those computed values, called the KV (key-value) cache, for a short time.
The next request with the same prefix skips that work.
Two things follow from that:
-
The output doesn't change. Caching stores the model's work on the input, not its answer. You get the same kind of response you'd get without caching.
-
Only the input gets cheaper. Output tokens are billed as usual.
It's sometimes called prefix caching or context caching (Google's term).
It's different from caching answers in your own app; see the comparison near the end.
How does prompt caching work
Every provider's caching follows the same four rules:
-
It matches the prefix exactly. The cache only hits if your request starts with the same tokens, in the same order, as a cached request. One changed character early in the prompt means everything after it is processed again.
-
It has a minimum size. Short prompts aren't cached. Minimums range from 512 tokens (newest Claude models) to 4,096 tokens (some Gemini models).
-
Cache entries expire. Each entry has a time to live (TTL), from 5 minutes to 24 hours depending on the provider and settings. On Claude, every cache hit resets the 5-minute timer for free.
-
Writes and reads are priced differently. The first request writes the cache. On some providers, that write costs more than normal input. Later requests read the cache at a large discount.
A cache breakpoint marks where the cached prefix ends.
Some providers place breakpoints for you (implicit caching), and some let you place them yourself (explicit caching).
Everything before the breakpoint can be cached; everything after it is processed fresh.
Prompt caching by provider
Here's how caching compares across the major providers, based on Anthropic's prompt caching docs, OpenAI's prompt caching guide, Google's Gemini context caching docs and Amazon Bedrock's prompt caching guide.
Anthropic (Claude) | OpenAI | Google Gemini | Amazon Bedrock | |
How you turn it on | Add cache_control: one top-level field (automatic) or on specific blocks (explicit) | Automatic. Explicit breakpoints also available on GPT-5.6 and later | Implicit, on by default for Gemini 2.5 and newer | Add cachePoint in the Converse API. Amazon Nova also caches automatically |
Minimum prompt | 512 tokens on the newest models; up to 4,096 on older ones | 1,024 tokens (GPT-5.6 and later) | 2,048 or 4,096 tokens, by model | Varies by model |
Cache lifetime | 5 minutes (refreshed on each hit) or 1 hour | 30 minutes or 12 hours (GPT-5.6 and later) | Managed by Google for implicit caching | 5 minutes by default; check AWS docs per model |
Cache write cost | 1.25x input (5 min) or 2x (1 hour) | 1.25x (30 min) or 2.5x (12 hours) on GPT-5.6 and later; no write charge on earlier models | No write charge for implicit caching | Follows the model's pricing |
Cache read cost | 0.1x input; 0.05x on Opus 5.5 and Sonnet 5.5 | 0.1x input; 0.05x on GPT-6.1 and GPT-6.2 models | About 0.1x or less on current models | Up to 90% off input |
1. Anthropic prompt caching (Claude)
Claude prompt caching is opt-in, but it's now one line.
It has two modes:
-
Automatic caching: add a single cache_control field at the top level of the request. Claude places the breakpoint on the last cacheable block and moves it forward as the conversation grows.
-
Explicit caching: put cache_control on individual blocks, such as your system prompt or tool definitions. You can use up to 4 breakpoints per request.
The cache covers tools, then the system prompt, then messages, in that order.
The default lifetime is 5 minutes and refreshes for free every time the cache is used; a 1-hour lifetime costs more to write.
On the newest models (Opus 5.5, Sonnet 5.5 and Haiku 5.5), the minimum cacheable prompt is 512 tokens.
Shorter prompts are simply processed without caching, with no error.
Two extra benefits: cache hits don't count against your rate limit, which helps if you hit 429 rate-limit errors, and caches are isolated per organization and per workspace.
For every model's base and cache prices, see our Claude API pricing guide.
2. OpenAI prompt caching
OpenAI caches automatically: any prompt of at least 1,024 tokens can be cached with no code changes.
Since GPT-5.6, three things changed:
-
Cache writes now cost extra: 1.25x the input price for the default 30-minute lifetime, or 2.5x for 12 hours. Earlier models have no write charge.
-
Explicit breakpoints are available through prompt_cache_breakpoint, if you want to choose where the cached prefix ends.
-
Reads are cheaper: 0.1x the input price, or 0.05x on GPT-6.1 and GPT-6.2 models. OpenAI says cached input "can cost up to 95% less".
The optional prompt_cache_key parameter helps route related requests to the same cache.
On older models, OpenAI suggests about 15 requests per minute per key; above that, requests can overflow to other machines and miss the cache.
OpenAI also reports better cache use on the Responses API than on Chat Completions; see our Completions vs Responses API comparison.
3. Gemini prompt caching
Gemini's version, which Google calls context caching, is implicit and on by default for Gemini 2.5 and newer models.
The minimum prompt is 2,048 tokens on Gemini 2.5 Flash and Pro, and 4,096 on Gemini 3.x and Gemini 4 Argon.
There's no write charge for implicit caching, and on Google's current pricing pages cached input costs about a tenth of regular input or less.
Explicit caching (creating a named cache and referencing it) still exists for Gemini 3 and 2.5 models, with an hourly storage charge.
It isn't supported on Gemini 4 Argon and later, so new projects should rely on implicit caching.
4. Bedrock prompt caching
On Bedrock, caching works with Claude and Amazon Nova models.
In the Converse API, you add a cachePoint block after the content you want cached, such as the system prompt or tool definitions.
Nova models also cache text prompts automatically. Two Bedrock-specific details matter:
-
Claude's automatic caching isn't available on Bedrock. Anthropic's docs say a top-level cache_control field returns an error there, so use explicit cache points.
-
Caches are isolated by organization only, not by workspace as on the Claude API.
AWS says caching can cut input token costs by up to 90% on Bedrock.
Prompt caching pricing: when it pays off
Because cache writes can cost more than normal input, caching isn't free money on every request.
The question is how many times you reuse the prefix before it expires.
Take Anthropic prompt caching pricing with the default 5-minute cache: a write costs 1.25x, and each read costs 0.1x.
-
1 request: you pay 1.25x instead of 1x. Caching costs you 25% more.
-
2 requests: 1.25 + 0.1 = 1.35x instead of 2x. You save about a third.
-
10 requests: 1.25 + 9 × 0.1 = 2.15x instead of 10x. You save almost 80%.
So a 5-minute cache pays off from the second request.
A longer cache needs more reuse: with Claude's 1-hour cache (2x write) or OpenAI's 12-hour cache (2.5x write), you need at least three requests to come out ahead.
OpenAI prompt caching pricing on its default 30-minute cache follows the same 1.25x and 0.1x pattern as Claude's 5-minute cache.
A worked example. A support bot on Claude Sonnet 5.5 sends a 10,000-token system prompt with every request and handles 1,000 requests, often enough that the cache never expires. Sonnet 5.5 costs $2 per 1M input tokens, $2.50 per 1M for 5-minute cache writes and $0.10 per 1M for cache reads.
Tokens | Cost of the system prompt | |
Without caching | 10M input tokens | $20.00 |
With caching: 1 write | 10,000 tokens | $0.025 |
With caching: 999 reads | 9.99M tokens | $1.00 (rounded) |
With caching: total | About $1.02, roughly 95% less |
The user's question and the model's answer are billed normally in both cases. If traffic is sparse and the cache expires between requests, you pay the write price again each time, so the real saving depends on your traffic.
For more ways to bring the bill down, see our guide to LLM API cost optimization, or compare base prices in our list of the cheapest LLM APIs.
How to structure prompts for prompt caching
The golden rule of caching is static first, dynamic last.
Put everything that never changes at the start of the request, and everything that changes at the end:
-
Tool definitions, in a fixed order.
-
The system prompt: instructions, rules and examples that are the same for every user.
-
Large shared context: a document, knowledge base or codebase summary.
-
Conversation history, which only grows by appending.
-
The new user message, last.
A few habits keep the prefix identical from request to request:
-
Don't put timestamps, request IDs or user names in the system prompt. Pass them in the user message instead.
-
Serialize JSON and tool lists in a stable order.
-
Pick reasoning and tool settings at the start of a conversation and keep them.
-
To warm a prompt cache before traffic arrives, send one request first and wait for it to finish before sending parallel requests. Parallel requests can't read a cache that hasn't been written yet. Claude also supports pre-warming with a max_tokens: 0 request.
What breaks the prompt cache
Most cache failures come from a small change early in the prompt.
On Claude, the cache is layered (tools, then system prompt, then messages), and a change invalidates its own layer and everything after it:
Change | What gets reprocessed |
Editing a tool definition | Everything: tools, system prompt and messages |
Editing the system prompt (for example, a timestamp) | The system prompt and all messages |
Changing tool_choice, or adding or removing images | The messages |
Changing thinking or effort settings | The messages, and on some models the tools and system prompt too |
Switching to a different model | Everything; caches belong to one model |
Waiting longer than the cache lifetime | Everything; the cache has expired |
Anthropic's prompt caching docs list these invalidation rules in full.
OpenAI's caching follows the same prefix rule, and OpenAI's caching guide describes a way to change reasoning effort on supported models without rewriting the prefix.
How to check prompt caching is working
Don't assume caching is working; measure it. Each provider reports cache activity in the response's usage data:
-
Anthropic: cache_creation_input_tokens (written) and cache_read_input_tokens (read). If both are 0, nothing was cached.
-
OpenAI: cached_tokens and, on GPT-5.6 and later, cache_write_tokens, inside the input token details.
-
Gemini: the cached token count in the response's usage metadata.
-
Bedrock: CacheReadInputTokens and CacheWriteInputTokens.
Here's a minimal Python example for Claude that turns on automatic caching and prints the hit rate for each call:
import anthropic
client = anthropic.Anthropic()
SYSTEM_PROMPT = open("support_guide.md").read() # Long, stable instructions
def ask(question):
response = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=512,
cache_control={"type": "ephemeral"}, # Automatic caching
system=SYSTEM_PROMPT,
messages=[{"role": "user", "content": question}],
)
u = response.usage
written = u.cache_creation_input_tokens or 0
read = u.cache_read_input_tokens or 0
total = u.input_tokens + written + read
print(f"written: {written}, read: {read}, hit rate: {read / total:.0%}")
return response
ask("How do I reset my password?")
ask("Can I change my billing email?")
The first call should show tokens written and a 0% hit rate.
The second, sent within 5 minutes, should show those tokens read from the cache.
If the second call also shows 0 read, something in the prefix changed between calls, or the prompt is below the minimum length.
For OpenAI, the equivalent check reads usage.input_tokens_details.cached_tokens:
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-5.6",
instructions=SYSTEM_PROMPT, # Same long, stable text
input="How do I reset my password?",
prompt_cache_key="support-bot-v1",
)
details = response.usage.input_tokens_details
print("cached:", details.cached_tokens)
Prompt caching through gateways and routers
If you call models through a gateway or router instead of directly, caching depends on two things the gateway controls:
-
Does it pass cache settings through? Claude's cache_control and OpenAI's prompt_cache_key have to reach the provider unchanged.
-
Does it keep a conversation on one provider? Caches live on one provider, and often on one machine. A router that spreads the turns of one conversation across providers starts with a cold cache every time.
OpenRouter prompt caching is a good example of handling both. It supports caching with OpenAI, Anthropic, Gemini, DeepSeek, Groq and others.
It also uses "sticky routing" to send follow-up requests to the same provider, with sessions that expire after 10 minutes of inactivity.
Its responses include a cache_discount field showing what you saved.
Before choosing a gateway, test it: send the same long prompt twice and check the cached-token fields in the second response.
Our guides to how LLM routing works and LLM gateways compared cover the trade-offs.
Calling models from several providers? ScriptRun gives you one OpenAI-compatible API key for models from OpenAI and other providers. It has unified request formats, one bill, and smart routing to keep costs down.
Prompt caching vs semantic caching vs KV caching
Three kinds of caching often get mixed up. Here's how it compares with the other two:
KV caching | Prompt caching | Semantic caching | |
What's reused | The model's work on earlier tokens, within one response | The model's work on a prompt prefix, across requests | A whole previous answer |
Where it runs | Inside the model, always on | At the provider | In your app, usually with a vector database |
Match rule | n/a | Exact prefix match | Similar meaning |
Output | Unchanged | Unchanged | A stored answer, which may be stale or not quite fit |
Prompt and semantic caching work well together: semantic caching avoids a model call entirely for repeated questions, and provider caching makes the calls you still need cheaper.
The bottom line on prompt caching
Prompt caching is the closest thing to a free discount in LLM APIs, as long as your prompts are built for it.
Keep the prefix stable, put changing content last, and check the cached-token fields to make sure it's working.
With a 5-minute cache, it pays off from the second request, and long, frequently reused prompts can cost about 95% less.
If you use models from several providers, ScriptRun's OpenAI-compatible API gives you one key and one bill for all of them.
FAQs about prompt caching
What is prompt caching?
Prompt caching is an LLM API feature that stores the model's processed state for the start of a prompt. When a later request begins with the same tokens, the provider reuses that state, bills those tokens at a large discount (usually 90–95% off) and responds faster. The model's answer is unaffected.
How does prompt caching work?
The provider matches each new request against recently cached prompt prefixes. If the request starts with exactly the same tokens as a cached prefix that hasn't expired, the model skips reprocessing that part. Only the tokens after the match are processed at the normal price. Any change in the prefix means everything after the change is processed again.
What is prompt caching in Claude?
It's Anthropic's version of the feature. You turn it on with a cache_control field, either once at the top level of the request or on specific blocks. Cache writes cost 1.25x the input price for a 5-minute cache or 2x for 1 hour. Reads cost 0.1x, or 0.05x on Claude Opus 5.5 and Sonnet 5.5.
Does OpenRouter support prompt caching?
Yes. OpenRouter supports caching with OpenAI, Anthropic, Google Gemini, DeepSeek, Groq, Grok, Moonshot AI, Alibaba Qwen and Z.AI. Most cache automatically. For Claude, you add cache_control as you would with Anthropic's API. OpenRouter keeps follow-up requests on the same provider so the cache stays warm.
How to implement prompt caching?
Put stable content (tools, system prompt, shared documents) at the start of every request and changing content at the end. Then turn caching on where needed: nothing to do on OpenAI and Gemini, a cache_control field on Claude, or a cachePoint on Bedrock. Finally, check the cached-token fields in the response to confirm it's working.
Does Claude Code use prompt caching?
Yes. Claude Code manages caching automatically unless you turn it off, and Anthropic has written that it builds Claude Code around a high cache hit rate. Claude Code prompt caching also explains two quirks: switching models mid-session makes the next turn slow and uncached, because caches belong to one model, and edits to CLAUDE.md don't apply until a new session.
Does prompt caching reduce latency?
Yes, for long prompts. The model skips processing the cached prefix, so the first token arrives sooner. The longer the cached part, the bigger the gain; for short prompts the difference is small. See our guide to reducing API latency for other techniques.
How to enable prompt caching in AWS Bedrock?
Use a supported model, such as Claude or Amazon Nova, and add a cachePoint block in the Converse API after the content you want cached (for example, after the system prompt or tool definitions). Nova models also cache text prompts automatically. Check CacheReadInputTokens in the response to confirm cache hits.
What does prompt cache warm mean?
A warm cache is one that already holds your prompt prefix, so the next request gets a cache hit. A cold cache means the next request has to write it first. Warming means sending a request in advance, or keeping traffic regular enough, so the cache doesn't expire. On Claude, a request with max_tokens: 0 warms the cache without generating any output.
Which LLM router avoids breaking provider-side prompt caching?
Look for a router that passes cache fields (cache_control, prompt_cache_key) through unchanged and keeps each conversation on the same provider, sometimes called sticky routing. OpenRouter documents both. For any router, the reliable test is to send the same long prompt twice and check that the second response reports cached tokens.
Related posts
Zapier Alternatives: 8 Tools Compared on Price (2026)
Zapier alternatives compared: what each tool costs, how it counts usage, a 10,000-action cost example, and open-source and enterprise picks.
LLM Vision API: Processing Images and PDFs Across OpenAI, Claude, and Gemini
Run images and PDFs through OpenAI, Claude, and Gemini from one OpenAI-compatible LLM vision API. Includes Python and TypeScript base64 examples, 2026 token math, pre-resizing, JSON extraction, and async Workflow API batch jobs.
What Is OpenRouter? How It Works, Pricing and Limits (2026)
What is OpenRouter and should you use it? How the gateway works, what it costs, free limits, Auto Router and Fusion, privacy and who owns it.
OpenAI API Alternative: 8 Providers Compared for 2026
Eight OpenAI API alternatives compared on current prices, speed, context and what changes when you switch, with a checklist and a gateway option.








