What is prompt caching, and how much does it save on an LLM API?
Letting the API keep the processed start of a prompt for a few minutes, so later requests that begin the same way are cheaper and quicker.
intermediate · Also called Context Caching, Cache Control
Most requests an app sends begin the same way: the same instructions, the same examples, the same tool definitions, then a different question at the end. Prompt caching lets the API keep the work it did on that shared beginning, so the next request that starts identically skips it. You pay less for those tokens and the answer starts sooner.
How it works
You mark a point in the prompt with cache_control. The API stores everything from the start of the prompt up to that point, in a fixed order: tools first, then the system promptSystem PromptInstructions the builder of an AI app gives the model before you type anything. It sets the role, the tone and the rules, and it outranks what users say., then the messages. A later request whose prompt is identical up to that point reads it from the cache instead of processing it again.
Identical means identical. Change one character anywhere before the marked point and it is a different prompt and a new cache entry. That is why the fixed part of a prompt templatePrompt TemplateA prompt kept as a file with placeholders filled in at run time, so it can be versioned, reviewed and tested like the rest of your code. goes first and the variable part, the customer's email or the user's question, goes last, after the marked point. A timestamp or a user's name near the top of the system prompt quietly turns caching off.
What it costs and saves
On Claude, writing to the 5-minute cache costs 1.25 times the normal input price, and reading from it 10% of the input price, or 5% on Claude Opus 5.5 and Claude Sonnet 5.5. A 1-hour cache costs 2 times the input price to write. The 5-minute cache pays for itself the first time it is read, and each read refreshes its 5 minutes at no cost, so a steady stream of requests keeps it warm.
Use the prompt caching calculator to price your own traffic.
Traps
- Too short to cache. On the current Claude models the cached part must be at least 512 tokens. A shorter prompt is processed normally, with no error, so a short system prompt never caches.
- Check, do not assume. Every response reports
cache_creation_input_tokensandcache_read_input_tokensin its usage. If both are 0, nothing was cached. - Gaps longer than the lifetime. With a request every 20 minutes, a 5-minute cache is written and never read. The 1-hour cache, or batching requests closer together, fits that pattern better.
- Each workspace has its own cache. On the Claude API, caches are kept apart between organizations and between workspaces, so 2 workspaces sending the same prompt each pay to write it.
Prompt caching stores the model's internal working for those tokens, the KV cacheKV CacheWork a model saves from the text it has already read, so it is not redone for every new token. Prompt caching keeps that work between requests and charges less for it., not the answer. Every request still gets a freshly written reply.
Sources