Providers cache the model's computed state (the KV cache) for a repeated prompt prefix such as a system prompt, tool definitions or RAG context. Later requests skip the recompute, which cuts cost and latency. Examples are Anthropic prompt caching, OpenAI automatic prompt caching and Gemini context caching.

Prefix order decides the cache hit

Provider-Level Prompt CachingDiagram with these labels, in reading order: cache setup; cache hit; dynamic content follows; return cached response; return full response; Stable Content; (Prefix); Cache Breakpoint; (cache_control); Cache Hit; (Reuse KV Cache); Dynamic Content; (Request); Response; (Returned Output).cache setupcache hitdynamic content followsreturn cached responsereturn full responseStable Content(Prefix)Cache Breakpoint(cache_control)Cache Hit(Reuse KV Cache)Dynamic Content(Request)Response(Returned Output)
Provider-Level Prompt Caching Flow

Put stable content at the front of the prompt: the system prompt, tool definitions or retrieval-augmented generation (RAG) context. Then mark a cache breakpoint, which tells the system where it may reuse previously computed state. Anthropic uses a cache_control directive. OpenAI caches eligible prefixes automatically; the minimum prefix length depends on the model (1,024 tokens on current models), so check the provider's documentation.

The cache key is the exact token prefix. A one-character change, or a variable placed too early, invalidates the cache and forces full recomputation. Dynamic content therefore has to come after the cached prefix. A CDN or memoization layer behaves similarly, but the key here must match token for token.

Cache key sensitivity A single character change in the prefix causes a miss and full recomputation.

Read cost, write premium and a short TTL

On a hit, you pay for the cached tokens at about 10% of the normal input price (Anthropic and OpenAI both list 0.1 times for most models). The request that writes the cache pays a premium: Anthropic charges 1.25 times the base input price for its 5-minute cache. Responses come back faster because the model skips the cached prefix. A chatbot with the same system prompt and definitions can then handle many user queries while processing only the dynamic part of each.

The time-to-live is short (Anthropic's default is 5 minutes, refreshed each time the cache is used), so caching helps most under sustained traffic. Savings of up to 90% apply to the cached portion of the prompt, and the exact figures depend on the provider and model.

Order matters in the other direction too. If dynamic elements sit before the stable block, the prefix never matches, the cache is not hit, and the request pays for recomputation and added latency.

Workloads that benefit, and workloads that do not

  • Good fit: a large stable prefix with high request volume, as in chatbots, agents and document question-and-answer systems.
  • Poor fit: one-off queries or highly variable prompts. The write premium can then exceed the savings.

Without caching, each request resends a large static preamble and you pay full price to process it every time. With caching, the model still sees the full context, and you pay the reduced cached rate for the repeated prefix.

Example scenario: latency climbs when the cache stops hitting

Suppose latency rises 30% after prompt caching stops working. The figure is illustrative. A spike in unique prompts or a prefix that changed can make the provider recompute the KV cache for each request.

Provider-Level Prompt CachingDiagram with these labels, in reading order: check cache performance; prefix issue; invalidation issue; stabilize the prefix; correct invalidation logic; Latency Increase > 30%; Cache Miss Rate > 15%; Prefix Changes Between Calls; Invalid Cache Invalidation; Keep Static Content; In The Prefix; Fix Cache Invalidation; Logic.check cache performanceprefix issueinvalidation issuestabilize the prefixcorrect invalidation logicLatency Increase > 30%Cache Miss Rate > 15%Prefix Changes Between CallsInvalid Cache InvalidationKeep Static ContentIn The PrefixFix Cache InvalidationLogic
Debugging prompt caching issues
  1. Check cache hit rate metrics over time for trends.
  2. Log the number of unique prompts to see whether it spiked.
  3. Confirm that variable content still sits after the cached prefix and that traffic gaps are shorter than the TTL.

The fix is to restore a stable prefix and move changing content behind it. Monitor the cache hit rate afterwards.

Back to the knowledge baseRequest an assessment