Prompt Caching Explained: Where the Savings Come From
Every time you send the same system prompt, few-shot examples, and reference documents to a language model, you pay to process them again. Prompt caching changes that economics by letting the model reuse what it already computed, and understanding exactly where the savings come from is the difference between a real cost cut and a missed one. This guide breaks the mechanism down so you can design for it.
What Prompt Caching Actually Does
A language model reads your prompt token by token, and for each token it builds an internal representation called a key-value cache that later tokens attend to. Prompt caching lets a provider store that computed representation for a prefix of your prompt, such as your system instructions and standing reference material. On the next request that begins with the same prefix, the model loads the stored cache instead of recomputing it, and the provider bills those cached tokens at a lower rate than freshly computed input.
The mechanism is simple in concept but powerful in practice. Any content you send repeatedly, unchanged, is a candidate for caching. The larger and more stable that shared prefix, and the higher your request volume, the more computation you avoid paying for twice, which is why caching reshapes the cost profile of exactly the applications that lean hardest on long context.
Where the Savings Come From
The savings come from the input side of inference, not the output. Generating each new token is cheap relative to reading a long prompt, but reading a long prompt is itself expensive because every token must be processed against every earlier token. When a 4,000-token policy document or a 10,000-token codebase is prepended to every call, that reading cost is paid on every single request, whether or not the user's new message is short.
Caching removes the repeated reading of the stable prefix. The model still computes the new user message and still generates the response, but it no longer re-derives the attention state for the part you already sent. In high-volume applications where the prefix dwarfs the new input, the avoided recomputation is the dominant source of savings, which is why caching rewards exactly the workloads that send the most repeated context on each turn.
A Cost Model You Can Use
Use this five-step model to estimate whether caching will help:
- Measure your stable prefix — count tokens in the system prompt, instructions, and reference material that rarely change.
- Estimate daily request volume that shares that exact prefix without alteration.
- Price the repeated input at the standard input rate across that volume for a baseline.
- Price the same tokens at the cached rate to see the recurring reduction.
- Subtract cache storage or TTL costs if your provider charges them, then compare the net difference.
The break-even point depends on volume. A low-traffic prototype may not send the prefix often enough for caching to matter, while a busy assistant or agent that reuses the same knowledge base on every turn can see the repeated-input cost fall to a fraction of its original level once the cache is warm and consistently hit.
A Step-by-Step Implementation
Here is a practical rollout:
- Move stable content, such as system instructions and reference text, to the very start of the prompt.
- Place a cache breakpoint at the end of that stable block using your provider's cache-control marker.
- Keep the cached prefix byte-for-byte identical across calls; any change invalidates it.
- Send one warm-up request before traffic arrives so the cache is populated.
- Monitor cache hit rate and watch for evictions when the prefix ages out.
- Trim the prefix to the minimum that stays stable, since cached tokens still cost something.
Common Pitfalls
The most common mistake is altering the prefix. Even appending a timestamp, a request identifier, or a trailing space before the cached section breaks the match and forces a full-price recompute. The second is caching volatile content: if the reference text changes every call, nothing is reused and you pay storage for no benefit. The third is assuming caching helps at low volume, when the occasional cold start dominates and the saving never accumulates into a meaningful total.
Example Scenario
Consider an example scenario: a customer support assistant prepends a 4,000-token policy document to every reply so the model stays on-brand. Without caching, each of thousands of daily tickets reprocesses that document. With caching, only the new customer message is computed after the first call; the policy is reused from cache. Across a busy day the repeated-input cost drops to a small fraction of the uncached baseline, while answer quality and consistency stay identical because the instructions are the same.
Cache Lifetime and Refresh
Caches are not permanent. Providers hold a cached prefix only for a limited window, after which it is evicted and the next matching request pays full price until the cache is rebuilt. Plan for that cold start: a quiet overnight period can empty the cache before morning traffic, so a warm-up call at the start of the day keeps savings flowing. Also decide how you refresh content. If the reference text changes, break the cache deliberately at a controlled moment rather than letting mismatched versions linger. Treat the cache as a managed resource with a clear write strategy, not something you set once and forget about. Most teams first notice the gap as a sudden cost spike on Monday morning, which is the classic signature of an evicted cache after a quiet weekend. Document the prefix and its lifetime alongside the rest of your runbook so on-call engineers can rebuild it without guessing.
In summary, prompt caching saves money by eliminating the repeated computation of a stable prompt prefix, and the savings live entirely on the input side. Architectures that send the same long context on every request gain the most, while volatile or low-volume prompts gain little. Design your prompt so the unchanging part leads, stays identical, and gets reused.
Frequently Asked Questions
What exactly gets cached in prompt caching? The cached portion is the prefix of your prompt, typically your system instructions, standing examples, and reference documents that remain identical across requests. The provider stores the computed internal state for those tokens so later calls with the same prefix skip recomputation. The new user message and the generated response are not cached; only the stable leading context is reused, which is where the cost saving originates.
Does prompt caching change the model's output quality? No. Caching reuses a previously computed representation of the same tokens, so the result is mathematically the same as processing them again. You trade recomputation for a stored cache, not accuracy for speed. The only quality risk comes indirectly, if a stale cached prefix is left in place after the underlying instructions or reference material should have changed and the cache was not refreshed.
When is prompt caching not worth it? Caching pays off when a stable prefix is reused at meaningful volume. It is weak when every request changes the prefix, when traffic is too low for savings to accumulate, or when the cached content is short enough that the recomputation was never expensive. If your prompt is mostly unique per call, the overhead of caching and the risk of stale matches outweigh the benefit you would gain.
Frequently asked questions
**What exactly gets cached in prompt caching?**
The cached portion is the prefix of your prompt, typically your system instructions, standing examples, and reference documents that remain identical across requests. The provider stores the computed internal state for those tokens so later calls with the same prefix skip recomputation. The new user message and the generated response are not cached; only the stable leading context is reused, which is where the cost saving originates.
**Does prompt caching change the model's output quality?**
No. Caching reuses a previously computed representation of the same tokens, so the result is mathematically the same as processing them again. You trade recomputation for a stored cache, not accuracy for speed. The only quality risk comes indirectly, if a stale cached prefix is left in place after the underlying instructions or reference material should have changed and the cache was not refreshed.
**When is prompt caching not worth it?**
Caching pays off when a stable prefix is reused at meaningful volume. It is weak when every request changes the prefix, when traffic is too low for savings to accumulate, or when the cached content is short enough that the recomputation was never expensive. If your prompt is mostly unique per call, the overhead of caching and the risk of stale matches outweigh the benefit you would gain.
Related articles
Personalization at Scale with AI: Architecture and Pitfalls
Personalization at scale is an architecture problem: capture signals, decide at the right time, keep a crawlable core, and guard against pitfalls.
Multimodal Search: How Image and Video Understanding Changes Discovery
Multimodal search makes images and video queryable; optimise media with clear descriptions, transcripts, and consistent naming to be cited.
Small Language Models: When Smaller Beats Bigger
Small language models beat larger ones for narrow, latency-sensitive, private, or offline tasks. Choose by fit, not by benchmark size.