Prompt Caching
Most production prompts open with the same few thousand tokens every single time — a system prompt, a style guide, a product manual. The model re-reads all of it on every request, and you pay for every word. Prompt caching is the serving trick that stops that waste.
What is actually cachedAs a model processes a prompt, each token produces key and value vectors in every attention layer — the KV cache. Those vectors depend only on the tokens before them, so for an identical prefix they come out identical every time. Prompt caching keeps the computed blocks for that prefix in GPU memory and reuses them, skipping the prefill arithmetic entirely. vLLM exposes this as automatic prefix caching; the hosted APIs expose it as a discount on cached input tokens.
What it changes- Latency: time-to-first-token on a long shared prefix drops sharply, because prefill is the part that scales with prompt length.
- Cost: cached input is billed at a fraction of fresh input, which dominates the bill for a chat assistant that resends a long history every turn.
- Throughput: the prefill compute you no longer spend goes to other requests in the batch.
The match is prefix-only and exact: one changed character near the top — a timestamp, a user name, a reordered document — invalidates everything after it. That makes prompt layout an engineering decision, with static instructions first and volatile content last. Caches also expire within minutes and are scoped to a model and deployment, so a quiet endpoint gets no benefit at all.
Prompt caching stores the key-value attention state computed for a prompt's unchanging prefix — a system prompt, an attached document — and reuses it on later requests instead of recomputing it. This cuts time-to-first-token and the price of input tokens for any application that resends the same opening on every call. The match must be an exact prefix, so one edited character near the top discards the saving.
Imagine a lawyer who re-reads a thick contract from page one every time you ask a question about it. Slow — and you are paying by the hour. Prompt caching lets an AI keep its reading of the fixed material and carry on from there. The unchanging part of what you send, such as the standing instructions or an attached handbook, gets processed once and held for a short while, so your next question only costs the reading of the new bit. Answers come back faster and cheaper. The catch is that changing anything in those early pages sends it back to page one.