The same prompt can cost two very different prices. Send it once, pay full freight. Send the identical prefix again, and every major API bills the repeated part at a steep discount — as little as a tenth of the fresh input price, sometimes far less. Most teams treat this as a line-item discount. It is more than that. Prompt caching is compute reuse, and compute reuse rewards a specific application shape. Teams that internalize this redesign their prompt assembly, their agent loops, and their job pipelines — and cut their bills by an order of magnitude without changing models.
This article is the mental model, the architecture it implies, and the ways it silently fails.
What a prompt cache actually is
When a model processes your input, it computes an attention key and value for every token — the KV cache. That computation is a large share of what you pay for on input. A prefix cache stores those computed tensors, keyed by the exact bytes of the prompt prefix. Send a request whose opening bytes match a stored prefix, and the provider skips recomputing that entire stretch: you get the same output, faster, at the cached-read price.
The operative word is prefix. Not “the parts that didn’t change.” Not “the system prompt.” Everything before the first changed byte. If byte 40 of your prompt differs from the cached run — a timestamp, a reordered JSON key, a freshly generated request ID — then bytes 40 onward are recomputed and rebilled, no matter how static they are.
The cached result is not “the model remembering you.” The model itself is untouched. It is cheaper because the provider did less arithmetic, and they pass some of that saving to you. That framing matters, because it tells you the discount is a mechanical consequence of your prompt’s byte layout — which means you can engineer for it.
The one rule, and everything it implies
Put static content first and volatile content last. That is the entire discipline. Everything else in this article is consequence or corollary.
A well-laid prompt has three temperature layers:
- Cold — never changes. System prompt, tool definitions, few-shot examples, output schema. This layer should be byte-identical across every request your app sends.
- Warm — changes slowly. Session history, retrieved documents that persist across a task, user profile. Stable within a conversation.
- Hot — changes every request. The user’s new message, a timestamp, the item to classify.
Cold first, warm second, hot last. A prompt assembled in this order lets every request reuse the entire cold layer — and, in an agent loop, the entire prior conversation.
The classic cache killers
Before the patterns, the anti-patterns. Every one of these appears in production code:
- Injected “current date” at the top. A
System: today is 2026-10-10line placed above the tool definitions invalidates everything after it, once per day minimum. Put dynamic metadata last. - Generated IDs and nonces in the system block. Same mechanism: a fresh UUIDUUIDA 128-bit identifier generated to be practically unique without coordination, most commonly in version-4 (fully random) form. in byte 60 quietly rebills a 40K-token prompt every call.
- Non-deterministic serialization. Iterating a set or an unordered map when building JSON emits keys in a different order per run. Your prompts differ bytewise while looking identical to a human. Sort your keys.
- Tool reordering. Tool definitions live in the prefix. Reordering them per request — or “helpfully” prioritizing tools by predicted relevance — flips bytes deep in the cold layer. Keep a fixed order.
latestmodel aliases. The cache is keyed per model version. An alias that silently advances invalidates every cached prefix the day the vendor ships. Pin versions when cost matters.
Diagnosing these is straightforward: every major API reports cache-hit
tokens in the usage object (cached_tokens, cache_read_input_tokens, and
kin). If your hit rate is zero and you expected reuse, diff two of your
prompts bytewise. It is nearly always a stray hot byte in the cold layer.
Architecture change #1: the agent loop stops being quadratic
An agent converses by re-sending its whole history every turn. Turn n carries all n−1 prior turns as input. Sum that over a session and the naive input volume grows with the square of the conversation length. Twenty turns averaging 5K new tokens each bills about a million input tokens before caching — most of it repetitions of turns you already paid for.
With a stable-prefix layout, each turn’s prompt extends the previous one by exactly the new tokens. The cold layer and every prior turn are cached reads. Marginal cost per turn collapses from “the whole conversation” to “the new tokens, at full price, plus the conversation at cached price.” This is not a 20% trim; it is the difference between long-running agents being a research demo and being a line item you can afford. The 2025–2026 wave of hour-long agent sessions is downstream of this arithmetic.
The corollary: anything that rewrites history breaks the chain. Conversation summarization that replaces old turns with a compressed recap saves fresh-input tokens but discards the cached history. Whether that trade wins depends on your vendor’s ratio of cached-read price to fresh-input price — and on how much window you were paying for in the first place (the companion piece on what a context window really costs does that math). Measure, don’t assume.
Architecture change #2: fan-out jobs get a shared trunk
Consider a job that classifies 10,000 support tickets. Naive shape: one request per ticket, each carrying the full instructions. You pay for the instructions 10,000 times.
Cache-aware shape: a shared cold trunk — instructions, label taxonomy, few-shot examples — identical across every request, with the ticket body as the hot tail. The first request pays full price; the rest read the trunk from cache. At a tenth-of-input cached price, the instructions become close to free. The same trunk pattern applies to bulk extraction, review scoring, and translation sweeps.
One TTL wrinkle: most cache entries live on the order of minutes, and the clock refreshes on each hit. A 10,000-item fan-out needs pacing or batching that keeps the trunk warm — a steady stream, not bursts separated by idle lunches. Plan the pipeline around the window, not the other way round.
Architecture change #3: multi-tenancy splits the prefix
Per-user customization — “you are assisting {name}, who works at {company}” — is usually injected right after the system prompt. That makes every tenant’s prefix unique, and a global cache buys you nothing across users.
The salvage is layering: a global cold layer (instructions, tools, examples) shared by every tenant, then the per-user warm block, then the hot content. You lose caching on the user block but keep it on everything above it — and the global block is typically the bulk of the tokens. For workspaces with many users hitting the same workspace-scoped context, cache per workspace instead of per user wherever the semantics allow.
Some vendors also let you mark explicit cache breakpoints — positions where everything up to that point should be cached — which lets you split one prompt into separately cacheable segments. Choosing where those fall is a small optimization problem all its own; CosmoDev’s cache-breakpoint-planner exists exactly for it, and the cache-savings-calculator turns “should we restructure this prompt” into a number.
The pricing picture, briefly
Vendors differ in the details more than the mechanism. Common shape: cached input reads run from ~2% to 25% of fresh input price (about a tenth is the current frontier norm); some providers bill cache writes at a premium over fresh input (so a prefix read once is a net loss — reuse it or don’t cache it); TTLs run minutes by default with extended windows on offer; and most vendors apply caching automatically above a minimum prefix length, while at least one requires opt-in breakpoints. The companion piece in this series, how tokens are priced, carries the per-vendor tables with sources.
The mental shift
Without caching, a prompt is a stateless string: you assemble it, send it, forget it. With caching, a prompt is layers with heat. The cold layer is an asset — deployed once, read cheaply forever. The hot layer is where your per-request money goes. Cost engineering stops being “which model is cheapest” and becomes layout engineering: what is static, what is volatile, and in which order they meet the tokenizer.
Apps that get this wrong pay full price for the privilege of sending the same 40K tokens ten thousand times. Apps that get it right treat their system prompt like a deployed artifact — versioned, diffed, and laid out with the same care as a database schema.
Drafting and verifying prompts for cache-friendliness is easier with tools: system-prompt-builder for the cold layer, token-estimator for sizing, and the two cache planners linked above for breakpoints and savings.