Short answer: prompt caching lets the Claude API reuse the processed start of a prompt across requests. You mark a point in the prompt with cache_control; the first request writes everything up to that point to the cache, and later requests with the exact same prefix read it back at a fraction of the normal input price and with lower latency. It pays off whenever many requests share a long, stable beginning: a big system prompt, tool definitions, a document, or a growing conversation.
How prompt caching works
Caching is a prefix match. The API renders your request in a fixed order, tools first, then system, then messages, and caches the exact bytes up to each breakpoint you mark. If a single character changes anywhere before a breakpoint, that breakpoint and everything after it miss the cache.
That one rule explains almost every caching problem: put what never changes first, what changes per user or session next, and what changes on every request last.
Add caching in Python
The simplest option is automatic caching: a top-level cache_control caches up to the last cacheable block of the request.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
cache_control={"type": "ephemeral"}, # cache up to the last cacheable block
system=LONG_PRODUCT_MANUAL, # the same text on every request
messages=[{"role": "user", "content": "How do I reset my password?"}],
)
print(response.usage)
For control over where the cache ends, put cache_control on a specific content block instead. Here the long, shared manual is cached and the question after it is not:
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
system=[
{
"type": "text",
"text": LONG_PRODUCT_MANUAL,
"cache_control": {"type": "ephemeral"}, # 5-minute cache by default
}
],
messages=[{"role": "user", "content": question}],
)
In TypeScript the request has the same shape: pass cache_control: { type: "ephemeral" } on the block, or at the top level of client.messages.create().
Check that it is working
Every response reports cache activity in usage:
cache_creation_input_tokens: tokens written to the cache by this request.cache_read_input_tokens: tokens read from the cache instead of being processed again.input_tokens: the remaining, uncached input.
Send the same request twice. The first should show a cache write; the second, a cache read. If both show zero, the cached part is probably shorter than the model’s minimum cacheable length (it ranges from about 512 to 4,096 tokens depending on the model). Short prefixes are simply not cached, and there is no error.
What it costs, and when it pays off
- Cache reads cost a small fraction of the normal input price (around a tenth on most models, less on some newer ones).
- Cache writes cost more than normal input: 1.25 times for the default 5-minute cache, 2 times for the 1-hour cache.
- With the 5-minute cache, two requests that share a prefix already break even. With the 1-hour cache you need at least three.
Each read refreshes the timer, so steady traffic keeps a 5-minute cache warm indefinitely. Use the 1-hour option only when requests sharing a prefix arrive more than 5 minutes apart. Check current per-model prices on Anthropic’s pricing page before estimating savings.
Where to put breakpoints
- Large system prompt or tool list: one breakpoint on the last system block. Tools render before the system prompt, so both are cached together.
- Chat and agent conversations: a breakpoint on the last block of the newest turn. Each new request reuses the whole earlier conversation.
- Shared document, different questions: a breakpoint at the end of the document, not at the end of the question. Otherwise every request writes its own entry and nothing is ever read back.
You can use up to four breakpoints per request.
The mistakes that silently break caching
- A timestamp or date in the system prompt. The prefix changes every request. Pass the date later, in a user message.
- User names or IDs interpolated into the system prompt. Every user gets a separate cache. Keep the system prompt identical for everyone.
- Tools built per user or in random order. Tools come first in the prompt, so any difference invalidates everything. Sort them by name and keep the set fixed.
- JSON serialised without a stable key order. The same data produces different bytes. Sort keys.
- Switching models mid-conversation. Caches belong to one model.
Caching pairs well with the other cost levers in our production guide: right-sized models, shorter outputs and batching for work that is not urgent. In an agent loop, where every step resends the conversation so far, caching is often the biggest single saving.
FAQ
How much does prompt caching save?
Cached input is billed at a small fraction of the normal input price, around a tenth on most models, so savings on the cached part can approach 90%. Your real saving depends on how much of each request is a shared prefix and how often it is reused.
How long does the Claude prompt cache last?
Five minutes by default, refreshed every time the cache is read. You can ask for a one-hour cache with “ttl”: “1h”, which costs more to write.
Why is my prompt not being cached?
The usual causes are a prefix shorter than the model minimum, something that changes in the prefix on every request (a timestamp, an ID, unsorted JSON, a different tool list), or a breakpoint placed after content that varies per request.
Does prompt caching change the answers?
No. Caching only skips reprocessing an identical prefix; the model sees the same prompt and responds the same way.
Is the cache shared between customers?
No. Caches are isolated to your organization (per workspace on the Claude API) and are never shared with other organizations.