If you have ever wondered how an AI chatbot "remembers" the first message you sent it twenty minutes ago, the answer is a technique called prompt caching — and understanding it will save you serious money on your AI API bill.
The Problem: LLMs Have No Memory
A large language model has no memory of its own. Every time you send a message, your application resends the entire conversation — system prompt, all previous messages, all previous tool outputs — as one long block of text (the "prompt"). The model re-reads everything from scratch each turn.
For long conversations this gets expensive fast. If your system prompt plus conversation history is 50,000 tokens and you have exchanged 40 messages, you have sent the model millions of tokens — mostly identical content repeated over and over.
How Prompt Caching Works
Prompt caching lets the provider remember the expensive intermediate work (the KV cache — a set of internal computations the model does while reading your prompt) and reuse it on the next request.
When your new request shares the same beginning — same system prompt, same earlier messages — the provider checks: "I have already computed this prefix." Instead of recomputing it, it loads the saved computation and only processes the new tokens.
Key facts:
- Caching is prefix-based. The match must start at the very beginning of the prompt. If you change the system prompt, the cache is invalidated for everything after it.
- Caches expire. Most providers evict cached prompts after 5 minutes to a few hours of inactivity.
- Cached tokens are dramatically cheaper. Typically 50% to 90% off the normal input price — and faster, too, because reading a cache is quicker than recomputing.
A Simple Analogy
Imagine reading a 500-page book aloud to someone, then getting interrupted. On return, you could either start from page 1 again, or keep a bookmark and a summary of everything so far. Prompt caching is the bookmark. It only works if the book is the same book in the same order — which is why prompt structure matters.
What Breaks the Cache
The most common ways developers accidentally waste money:
- Dynamic content early in the prompt. A timestamp, random ID, or "current date" placed at the top invalidates everything downstream.
- Reordering messages. Cache matching is exact; a swapped message order is a different prompt.
- Changing the system prompt mid-conversation. Even one word change kills the whole cache.
- A/B testing tool definitions. Tools are part of the prompt; altering their order or descriptions between requests prevents reuse.
The fix: put static content first (system prompt, tools, reference documents), dynamic content last (the newest user message), and keep everything in between byte-identical across turns.
Why You Should Care as a Developer
On high-volume applications — coding assistants, chatbots, RAG pipelines with large injected context — prompt caching routinely cuts input costs by 70–90%. Some modern models are explicitly architected around it: DeepSeek V4 Flash, for example, advertises aggressive KV-cache reuse as the core of its economics, which is part of why its effective input price on Qubax sits at a fraction of a cent per million tokens.
Quick Checklist
- Keep your system prompt stable and at the top.
- Never inject per-request variables before the stable prefix.
- Send tool definitions in a fixed order.
- Batch related requests close together in time (caches expire).
- Track cache-hit rates in your provider dashboard — anything below ~80% on chat workloads means your prompt structure is leaking money.
Prompt caching is one of those rare optimizations that is free to implement and compounds across every request you make. Structure your prompts like a book with stable chapters, and the provider's bookmark does the rest.
Want to see real prices with caching-friendly economics? Browse frontier models at [Qubax AI](https://qubax.ai/models) — an open market where compute providers compete on price — and check the [API docs](https://qubax.ai/docs) for integration examples.
FAQ
Does prompt caching change model quality?
No. Cached prefixes produce identical results to recomputed ones — the computation is the same, just reused.
Do I need to enable caching explicitly?
It depends on the provider. Some cache automatically above a minimum prompt length; others require a cache-control marker on a content block. Check the model's documentation.
How much does prompt caching save?
Typically 50–90% on cached input tokens versus uncached input, plus a meaningful latency reduction. Savings scale with how much stable context you reuse.