Raphael Friedmann
← Understanding AI

Prompt caching: why the second call is cheaper

A long prompt that starts the same way every time can be cached, so later calls skip that work and pay a fraction of the input price. How it works, what it costs, when it does nothing.

Agents, chat apps and RAG pipelines send the same long beginning over and over: tool definitions, a system prompt, a document, the conversation so far. Only the last part changes. Every turn, the whole conversation goes back in, and without caching the model processes all of it again on every call. Prompt caching lets the provider keep the work done on that beginning and reuse it. On Claude Sonnet 5.5, a cached read costs 5% of the normal input price as of November 2026.

What is actually cached#

Before a model writes its first token, it runs the prefill: it reads the whole prompt and computes, for every token in every layer, a key and a value for attention. That store is the KV cache. Prefill is compute-bound work that grows with the prompt length (prefill vs decode), and it is what you wait for before the first output token appears.

Prompt caching keeps that KV cache after the request has finished. The next request that starts with exactly the same tokens loads it instead of computing it again, and only prefills what comes after. In imp the engine keeps the KV blocks of a prefix and hands them to the next request that starts the same way. I can’t look inside a hosted provider, but their documented rules match that mechanism: the match is on the beginning, it must be exact, and it expires.

Caching does not change the answer. Anthropic’s prompt caching docs state: “The response you receive is identical to what you would get if prompt caching were not used.” Output tokens cost the same either way.

The rule: the prefix must match exactly#

The cache is looked up by prefix, everything from the first token up to some point. Anthropic again: “Cache hits require 100 percent identical prompt segments, including all text and images up to and including the block marked with cache control.” One different character early in the prompt and everything after it misses, because the key and value of every token depend on all the tokens before it.

So order decides. Stable content goes first, changing content last:

  1. Tool definitions
  2. System prompt and instructions
  3. Reference documents
  4. Conversation history, which grows at the end, so earlier turns stay part of the prefix
  5. The new question

Anthropic builds its prefix in this order, “tools, system, then messages”, and changing a tool definition invalidates the entire cache. OpenAI’s prompt caching guide and Google’s caching page give the same advice: large, shared content first. OpenAI adds that timestamps and user-specific content belong at the end. The classic mistake is the current date and time at the top of the system prompt: it changes on every call, so no call ever hits.

Same prefix, cache hit; changed first line, miss
prefix: identical on every callsuffix1st calltoolssystemdocumenthistoryquestioncomputed, then written to the cache2nd calltoolssystemdocumenthistorynew q.read from the cache, only the new question is computed2nd call,date on topdatetoolssystemdocumenthistorynew q.first block differs, so nothing after it matches: full prefill, full price
Highlighted blocks are written to or read from the cache, plain blocks are computed. A timestamp at the top changes the first block on every call and turns every request into a cache write.

How long the cache lives#

A cached prefix doesn’t stay forever. Anthropic’s default is 5 minutes, “refreshed for no additional cost each time the cached content is used”, with a 1-hour option. OpenAI’s GPT-5.6 and later models, GPT-6 included, default to 30 minutes, with a 12-hour option in the Responses API. An explicit Gemini cache lives as long as the TTL you set, “If not set, the TTL defaults to 1 hour”, and you pay storage for that time. A chat where someone replies every two minutes stays warm on a 5-minute cache. A batch job that calls once an hour does not.

What providers charge#

All figures from the providers’ own pages as of November 2026: Anthropic pricing, OpenAI pricing, Google pricing and explicit caching.

How it turns on Cached read vs. normal input Cache write Lifetime
Anthropic cache_control on a block, or once at the top level 0.1x; 0.05x on Opus 5.5 and Sonnet 5.5; 0.025x on Fable and Mythos 5.1 and 5.2 1.25x (5 min), 2x (1 h) 5 min, refreshed on use; 1 h option
OpenAI, GPT-5.6 and later on by default GPT-6.1-terra: $0.05 vs. $1.00 per MTok (0.05x) 1.25x (30 min), 2.5x (12 h) 30 min; 12 h option
OpenAI, GPT-5.5 on by default $0.50 vs. $5.00 per MTok (0.1x) no extra charge typically about 30 min, up to 24 h
Google Gemini implicit on by default for 2.5 and newer; explicit on Gemini 3 and 2.5 only 3.8 Flash: $0.075 vs. $0.75; 3.1 Pro Preview: $0.20 vs. $2.00 (0.1x) explicit: storage, $0.50 per MTok per hour on 3.8 Flash explicit: your TTL, default 1 h

The Gemini 3.8 Flash prices on that page apply through 31 December 2026 and double on 1 January 2027. Across all three, a cached read costs a tenth of normal input or less, and on Anthropic and GPT-5.6 and later writing the cache costs more than normal input. Caching is a bet that the prefix gets read again.

One example, with the arithmetic#

Claude Sonnet 5.5 on Anthropic’s pricing page: $2 per million input tokens, $2.50 for a 5-minute cache write, $0.10 for a cache read. Take a 50,000-token prefix (tools, instructions, a long document) and a 500-token question. Output is left out because it costs the same with or without caching.

  • Without caching, every call: 50,500 × $2 / 1M = $0.101
  • Call 1, writing the cache: 50,000 × $2.50 / 1M = $0.125, plus 500 × $2 / 1M = $0.001, total $0.126
  • Call 2 within 5 minutes, reading: 50,000 × $0.10 / 1M = $0.005, plus $0.001, total $0.006
Input cost per call, 50,000-token prefix on Claude Sonnet 5.5
no caching, any call$0.1011st call, cache write$0.1262nd call, cache read$0.006
50,000 prefix tokens plus 500 question tokens. Prices: $2 input, $2.50 5-minute cache write, $0.10 cache read per million tokens (Anthropic pricing page, November 2026). Output not included.

The first call costs about 25% more than an uncached one, every following hit 94% less ($0.006 / $0.101 = 5.9%). Ten calls inside the window: 10 × $0.101 = $1.010 without caching, $0.126 + 9 × $0.006 = $0.180 with it. One hit already pays for the write: the write adds $0.025, each hit saves $0.095. With the 1-hour write at $4 per million, call 1 costs 50,000 × $4 / 1M + $0.001 = $0.201, $0.100 more than an uncached call, so it takes two hits to come out ahead.

When it does nothing#

  • The prompt is too short. Anthropic needs 512 to 4,096 tokens depending on the model, and below that “no error is returned”. OpenAI needs 1,024 for GPT-5.6 and later, Gemini’s implicit caching 4,096 on its newest models.
  • The beginning changes. A timestamp, the user’s name or a request ID at the top, tools in a different order, or retrieved RAG snippets placed before the instructions. Every call becomes a write.
  • Calls are further apart than the lifetime. Then you pay the write price every time, which on Anthropic is 1.25x and therefore more than not caching at all.
  • Most of the bill is output. Caching only touches input. On Sonnet 5.5 output costs $10 per million tokens, five times the input price, so a job that writes long reports from short prompts saves little.

Check instead of assuming: Anthropic reports cache_read_input_tokens in the usage of every response. If it stays at zero across repeated calls, something at the start of the prompt changes.

On your own hardware#

imp serves Anthropic’s /v1/messages and accepts cache_control, so the same request format works against a local card. There is no price discount locally. What you save is GPU time: the prefix’s KV blocks are reused and only the new tokens go through prefill, which shortens the wait for the first token. The cost is memory: a kept prefix occupies KV cache space that other requests can’t use, and on a 32 GB card that space is the scarce resource. The rules don’t change: exact prefix, stable content first.

Bottom line#

Prompt caching keeps the processed beginning of a prompt so the next call that starts the same way skips that work. As of November 2026 a cached read costs a tenth of normal input or less at all three providers. The prefix must match to the character: tools, instructions and documents first, anything that changes last. It pays when the same prefix is read again within minutes, and does nothing for short, one-off or output-heavy calls.