Most production prompts are mostly the same. A support bot sends its instructions, its tool definitions, a few worked examples and a reference document on every call, and only the user's question changes at the end. The model is stateless, so without help it reprocesses that whole prefix for every request, and you pay for all of it. Prompt caching keeps the processed prefix on the provider's side for a few minutes, so a later request that starts with the same tokens can read it back instead.
The film records it for real. The prompt is a support assistant for a fictional bike-share: 1,411 tokens of system instructions, 1,573 of tool definitions, 996 of few-shot examples and 1,917 of a fare and station handbook, 5,897 tokens in all, followed by a rider's question of about 18 tokens. Every call went to `anthropic/claude-sonnet-5` through OpenRouter on 11 September 2026, with the provider pinned to Anthropic, temperature 0 and streaming on, and each block ended with a cache_control breakpoint. The whole sequence was recorded three times, and the numbers on the board are the usage fields the API returned, OpenRouter's billed cost and the measured time to the first streamed token, as medians.
The machine is a tree. The trunk is the stable prefix, stacked in prompt order from the root, each block as tall as its token count, and the branches are the questions that change on every call. Each request is a bead that climbs the trunk and leaves along a branch. Beside the trunk, the cache vault has a drawer per block. On the first call the bead processes every block and writes each one into its drawer, which costs a quarter more than a plain read: 1.5 cents. On the next call, with a different question, every block lights gold as it is read back, only the question's 18 tokens are processed fresh, and the call costs 0.17 cents. That held for all 24 different questions.
The part that is easy to miss is that the cache matches from the very first token. It is not a lookup of blocks by content: it is a match on the exact prefix. So order matters. Put the question in front of the instructions and nothing after it can ever match, because every call now starts differently: 18 calls out of 18 read nothing. Stable blocks first and the changing input last is not a style preference, it is what makes reuse possible at all.
The failure mode follows from the same rule. Add a timestamp, a user's name or a request id to the top of the system prompt, which is the most natural place to put it, and the prefix changes on every call. Nothing after the change matches, and all 5,915 tokens are written again at the write price, every time. Move the same edit lower and you lose only what comes after it: a stamp at the top of the tools kept the 1,411 tokens of instructions, one in the examples kept 2,984, and one in the handbook kept 3,980. The API's cache reads land exactly on the block boundaries, which is how the block sizes here were measured rather than estimated.
The saving is money more than speed, at least here. The first streamed token arrived in about a second whether the prefix was cached or not, because network and queueing dominate at this size. With the handbook grown to a 49,947-token prefix, a hit's median time to first token was 1.23 s against 1.44 s for a miss, about a fifth of a second, and the ranges overlapped. The price gap was the same tenfold as before: 1.0 cent against 12.4 cents per call.
The practical rules are short. Order a prompt from most stable to least: instructions, then tools, then examples and documents, then the conversation, then the new input. Keep anything that changes per request, such as dates, names, ids and retrieved snippets, below the last cached block. Watch the cache fields in the usage report, because a prompt that silently stops hitting costs nearly ten times as much and nothing else will tell you.
The honest caveats. This is one model, one provider and one prompt, with explicit breakpoints. OpenAI and Gemini cache automatically, with their own minimum sizes and granularity, but they match prefixes in the same way. The cache here lives for five minutes after its last use, so a quiet endpoint pays the write price again. Providers also refuse to cache a prefix below a minimum length, typically a thousand tokens or more, so a short system prompt may never cache at all; the shortest prefix cached here was the 1,411-token system block. The times were measured from a laptop over the public internet, so they include network variation that a server in the same region would not see, and a much longer prefix would show a larger prefill saving than the one recorded here.
The maths
- The cache matches an exact prefix
The prompt is four blocks of 1,411, 1,573, 996 and 1,917 tokens. A change at the start of block k keeps every block before it and invalidates the rest, which is exactly what the API reported: 0 tokens cached with a stamp in the system prompt, 1,411 with one in the tools, 2,984 in the examples and 3,980 in the handbook.
- What a call costs
R tokens read from the cache, W written to it, U input tokens neither read nor written (the question), and O output tokens, at the list prices for Claude Sonnet 5 on OpenRouter in dollars per million. The formula predicts every recorded prompt cost within two percent: 1.5 cents for the first call, 0.17 cents for a hit.
- The write premium pays back on the first hit
Writing a prefix of P dollars costs a quarter more than sending it plain, and every later read costs a tenth. Two calls inside the cache lifetime (five minutes here) already cost less than two uncached calls, and every call after that saves nine tenths of the prefix.
- Time to first token
Caching removes only the prefill of the cached tokens. Through OpenRouter the other terms dominated: about a second either way at 5,897 tokens, and at 49,947 tokens a median of 1.23 s on a hit against 1.44 s on a miss, with the two ranges overlapping.
Related terms
- Prefix cacheA prefix cache lets a provider reuse the unchanged front of your request instead of reprocessing it, so repeated prefixes are cheaper and faster. It is the main reason keeping the start of your prompt stable pays off.
- Cache tokensCache tokens are input tokens served from the prefix cache at a reduced rate. They are how prompt caching shows up as a separate line in your usage numbers.
- Input tokensInput tokens are the tokens you send in a request: the system prompt, the conversation history, loaded files, and tool definitions. You are billed for them, and they count against the context window.
- Output tokensOutput tokens are the tokens a model generates in its response, including any hidden reasoning. They are usually priced higher than input tokens, and turning up effort produces more of them.
- Context windowThe context window is the maximum amount of text, measured in tokens, that a model can consider for a single request. It is a hard ceiling, and it is the main resource you manage when working with an agent.
- InferenceInference is the act of running a trained model to get an answer: text goes in, a prediction comes out. Every message you send to a coding agent is an inference. It is the opposite end of the lifecycle from training.