Anthropic Prompt Caching TTL & Cost Guide: 5-Minute Cache Window Math
A deep-dive technical guide on Anthropic Prompt Caching Ttl And. Learn how top engineering teams architect high-throughput AI pipelines while maintaining strict unit economic control.
Anthropic Prompt Caching Architecture: 5-Minute TTL & 90% Cost Reduction
Anthropic's Prompt Caching for Claude 3.5 Sonnet and Claude 3.5 Haiku is one of the most powerful cost-reduction features in modern AI engineering. When an input prompt exceeds 1,024 tokens and includes a `cache_control: {"type": "ephemeral"}` breakpoint, Anthropic writes the Key-Value (KV) cache tensors to high-speed memory across their inference cluster.
Subsequent API requests that match the exact prefix reuse the cached KV state, receiving a 90% discount on input tokens ($0.30 per 1M tokens on Sonnet instead of $3.00) while reducing Time to First Token (TTFT) by up to 80%.
Anthropic Prompt Cache Pricing Matrix (March 2026)
| Model | Base Input Rate | Cache Write (Initial Call) | Cache Read (Hits within TTL) | Net Savings on Cache Hit |
|---|---|---|---|---|
| Claude 3.5 Sonnet | $3.00 / 1M | $3.75 / 1M (+25% write premium) | $0.30 / 1M | 90% Discount |
| Claude 3.5 Haiku | $0.80 / 1M | $1.00 / 1M (+25% write premium) | $0.08 / 1M | 90% Discount |
| Claude 3 Opus | $15.00 / 1M | $18.75 / 1M (+25% write premium) | $1.50 / 1M | 90% Discount |
The 5-Minute TTL Sliding Window Gotcha
Anthropic's ephemeral prompt cache operates on a 5-minute Time-to-Live (TTL) window. Every time a new request hits the cache, the 5-minute timer resets. However, if your application experiences an idle traffic gap of 5 minutes and 1 second, the cache expires, forcing the next request to pay the 1.25x Cache Write penalty. For low-traffic internal tools or background queues, scheduling a lightweight keep-alive ping every 4.5 minutes maintains continuous cache residency, saving money overall.
Frequently Asked Questions: Anthropic Prompt Caching
How does the Anthropic Prompt Caching pricing structure work?
The initial prompt that establishes a cache breakpoint incurs a 25% write surcharge over base token pricing (e.g. $3.75/1M tokens on Claude 3.5 Sonnet instead of $3.00/1M). All subsequent requests that read from the cached prefix receive a 90% discount ($0.30/1M tokens). If an application achieves at least 2 cache reads per write, prompt caching delivers immediate net savings.
What causes prompt cache misses in multi-turn chat applications?
Cache misses occur when the prompt prefix is altered before the cache breakpoint. Placing dynamic values—such as current UTC timestamps, variable user IDs, or randomly ordered few-shot examples—at the top of the prompt invalidates the prefix hash, forcing Anthropic to re-compute and re-bill the entire prompt at cache creation rates.
How long does the ephemeral prompt cache stay alive?
Anthropic's ephemeral prompt cache has a 5-minute Time-To-Live (TTL). Every successful cache read automatically refreshes the 5-minute timer. For workloads with bursty traffic gaps exceeding 5 minutes, running a minimal keep-alive ping every 4.5 minutes maintains continuous cache residency.
How many cache breakpoints can be defined in a single request?
Anthropic permits up to 4 explicit `cache_control` breakpoints per API call. This allows developers to cache separate layers independently: for example, breakpoint 1 on system instructions and tools, and breakpoint 2 on a large reference codebase or PDF documentation corpus.
Does prompt caching impact Time to First Token (TTFT) latency?
Yes, dramatically. On a 50,000-token prompt, traditional prefill computation takes 3 to 6 seconds before the first token appears. When hitting a warm prompt cache, TTFT drops by up to 85% (under 600ms) because KV activation tensors are loaded directly from memory rather than re-computed.
Related Optimization Guides
Anthropic Python Client Prompt Caching Implementation
import anthropic
client = anthropic.Anthropic()
# Inject cache_control breakpoint on large codebase context (>1024 tokens)
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
system=[
{
"type": "text",
"text": "You are an expert systems engineer with full access to repository code...",
"cache_control": {"type": "ephemeral"} # 5-minute sliding TTL cache write
}
],
messages=[{"role": "user", "content": "Analyze database migration script"}]
)
print(f"Tokens - Write: {response.usage.cache_creation_input_tokens}, Read: {response.usage.cache_read_input_tokens}")
Anthropic Prompt Caching Operational Checklist
- Minimum Token Threshold: Prompts must contain at least 1,024 tokens on Sonnet/Opus and 2,048 tokens on Haiku to trigger caching; smaller prompts are billed at standard non-cached rates.
- Order Context Deterministically: The cached prefix must match character-for-character from token 0. Never place variable user IDs or timestamps before the cache breakpoint.
- Maintain Keep-Alive Pings: For internal admin tools or periodic queues, dispatch a minimal 1-token query every 4.5 minutes to refresh the 5-minute TTL without paying the 1.25x write penalty.
- Monitor Cache Hit Telemetry: Log `cache_read_input_tokens` vs `cache_creation_input_tokens` in Datadog or Prometheus to ensure cache hit ratios stay above 70%.
Multi-Turn Agent Conversation Prefix Architecture
In multi-turn autonomous coding agents (such as Cline, Roo Code, and Claude Code), the context window grows with every command execution. Placing the `cache_control` breakpoint on the static system prompt and the static project file tree (rather than the dynamic conversation history) ensures that every subsequent turn hits the cached prefix, reducing input costs by 90% across long 30-turn developer sessions.