Cut Claude API costs with prompt caching
How Anthropic prompt caching is priced, when it pays off, and how to enable it with one top-level cache_control field or an explicit breakpoint, based on Anthropic's official prompt caching docs.
Verification
- Test environment
- Unknown
- Tested on
- Unknown
- Last updated
- 2026-11-11
Related models: Claude Haiku 5.5, Claude Opus 5.5, Claude Sonnet 5.5
If your requests keep resending the same long prefix (a system prompt, tool definitions, a document, a growing chat history), prompt caching lets Claude reuse it at a fraction of the input price. Everything below comes from Anthropic's official Prompt caching page; the code is copied from it and we have not run it ourselves.
How it is priced
Cache writes cost more than normal input; cache reads cost much less. Per million tokens, from Anthropic's table:
| Model | Base input | 5-min cache write | 1-hour cache write | Cache read | Output |
|---|---|---|---|---|---|
| Claude Opus 5.5 | $4 | $5 | $8 | $0.20 | $20 |
| Claude Sonnet 5.5 | $2 | $2.50 | $4 | $0.10 | $10 |
| Claude Haiku 5.5 (prompts up to 100K tokens) | $0.10 | $0.125 | $0.20 | $0.01 | $0.50 |
The rules behind the table: a 5-minute write is 1.25× the base input price, a 1-hour write is 2×, and a read is normally 0.1×. Opus 5.5 and Sonnet 5.5 are cheaper still at 0.05×. These multipliers stack with the Batch API discount and long-context pricing.
When it pays off: with a 5-minute cache on Opus 5.5 or Sonnet 5.5, sending the same prefix twice costs 1.25 + 0.05 = 1.3× the base price instead of 2×. So caching already saves money on the second request, and every later hit within the lifetime saves about 95% on that prefix.
Limits to know
- The cache lives 5 minutes by default and is refreshed for free each time it is used. A 1-hour TTL is available at the higher write price.
- Prompts shorter than the minimum are silently not cached. For Opus 5.5, Sonnet 5.5 and Haiku 5.5 the minimum is 512 tokens.
- The cache key covers
tools,systemandmessages, in that order, up to the breakpoint. Changing anything before the breakpoint means a new cache entry.
Option 1: automatic caching
Add one cache_control field at the top level. The API places the breakpoint on the last cacheable block and moves it forward as a conversation grows:
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
cache_control={"type": "ephemeral"},
system="You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.",
messages=[
{
"role": "user",
"content": "Analyze the major themes in 'Pride and Prejudice'.",
}
],
)
print(response.usage.model_dump_json())
For a 1-hour lifetime, use {"type": "ephemeral", "ttl": "1h"}.
Option 2: an explicit breakpoint
If the end of your prompt changes on every request (a timestamp, the user's question), automatic caching would put the breakpoint on that changing block. Put cache_control on the last block that stays the same instead:
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
system=[
{
"type": "text",
"text": "You are an AI assistant tasked with analyzing legal documents.",
},
{
"type": "text",
"text": "Here is the full text of a complex legal agreement: [Insert full text of a 50-page legal agreement here]",
"cache_control": {"type": "ephemeral"},
},
],
messages=[
{
"role": "user",
"content": "What are the key terms and conditions in this agreement?",
}
],
)
print(response.usage.model_dump_json())
Check that it worked
Look at usage in the response:
cache_creation_input_tokens: tokens written to the cache on this requestcache_read_input_tokens: tokens read from the cacheinput_tokens: uncached tokens after the breakpoint
If both cache fields are 0, nothing was cached, most often because the prefix was under the minimum length.
To see what cache reads and writes do to your total bill across providers, enter them in the cache fields on the Pricing page.
Sources
- Prompt caching (Anthropic docs)platform
.claude .com (opens in a new tab) · checked 2026-11-11