What this is about
Every time you send a model a question, it first has to read all of the text. That reading takes work. If the beginning of your next message is exactly the same as the beginning of your last one, a program can keep the work it already did on that beginning, and skip it. That kept work is the prompt cache.
The catch is the word "beginning". The saving only applies to a part at the start that did not change. Change one early line and everything after it must be read again.
Why it matters
In a chat, most of each message is a repeat. The instructions at the top are the same every turn. The earlier messages are the same. Only the last message is new. So a lot of the reading can be saved, and on a hosted service the saved part is billed at a lower rate.
We read a receipt for the pricing we use. It says a cached read costs about 0.1 times the base rate, after the first write. So a repeated block costs about a tenth of what it cost the first time. That is a big discount, if you protect it.
How it works
Think of reading a long contract. On Monday you read pages 1 to 40 and take notes. On Tuesday someone hands you the same 40 pages plus 2 new ones. If you kept your notes, you only read the 2 new pages.
Now suppose someone changed a sentence on page 1. Your notes on pages 2 to 40 may depend on it. You have to start again from page 1. A model's cache works the same way. It stores the model's working state after reading each part of the prompt. That state depends on everything before it. So the cache can only reuse a stretch from the start up to the first change.
This gives three rules.
- Put what never changes first. Rules and instructions at the top, in the same order every time.
- Put what changes last. Your new question goes at the end.
- Do not edit the early lines. A timestamp or a changing tool list near the top breaks the cache for everything below it.
Our context proxy, ctxd, has to change old messages when it folds them into a summary, so it works to keep the cache alive: after a fold it puts the cache marker back, so the prompt cache can still hit.
A cut we cannot put a number on
On 20 September we removed a file that every run under our home directory had loaded twice. Our panel noted the saving as "about 7k tokens per request". We have not measured that number. It is an estimate. We want to say so plainly, because it is easy to repeat a figure like this as fact.
Here is the arithmetic we can do. Forty skill descriptions in our setup come to about 4,600 tokens, and they ride in the system prompt of every request. A 7,000-token duplicate would be bigger than that whole list. If the duplicate sat in the cached part, each request after the first paid about 700 token-equivalents for it (7,000 times 0.1). That is a real bill, but a small one.
The bigger cost is room. A cached token still takes up space in the context window on every request. Caching makes the tokens cheaper. It does not give the space back. Every token spent on a duplicate rule is a token not spent on the file the model is working on. We have no source that says whether that changes the quality of the answers.
To really measure it, you would replay the same set of recorded requests before and after the cut, and count the input tokens and the cached-read tokens per request. We do not have that log. So the honest summary is: worth doing, not yet proven.
What counts as a saving
Compare these, because they get mixed up.
- Counted before and after on the same payload. This is a measurement.
- A guess from a note. This is an estimate. Say so.
- A cache hit with no input size. A cache hit tells you the work was reused, not how much text it was.
- A smaller prompt made by changing the task. That is not a saving. It is a different question.
Also keep in mind that a saving shown on one stretch of requests may not hold on another. One of our filters saved 525 bytes over a 40-prompt sample and nothing on a different 40-prompt window that had no such block. Both results were true.
For local models
The same idea works on your own machine, in engines that keep the stored working state between requests. Our engine has per-message checkpoints and a route that copies a session's state to a second engine. We did not measure a cache saving for it in this article, so we make no claim. What we can say is that the same rule holds: keep the start of the prompt stable.
Words you may not know
- Prompt: the whole text sent to the model for one turn.
- Prompt cache: kept work on the start of a prompt, reused if the start repeats.
- Prefix: the part at the beginning of the prompt.
- System prompt: the standing instructions that begin every request.
- Cache hit: a request that reused kept work. A miss had to do it all.
- Context window: the fixed amount of text a model can read at once.
- Token-equivalent: a cost expressed as if it were tokens at the full rate.
Try it
- See how ctxd keeps the cache marker when it folds a chat on the ctxd project page.
- Look at your own chat program's usage numbers. If it shows cached reads, send two similar messages in a row and compare. Then move one line near the top and send again.
- When you write instructions for a model, put the part that stays the same at the top, and never put a clock or a counter there.
Read next
- A 7k-Token Prefix We Have Not Measured, the full account of the cut and the missing log.
- The Cache Is Not the Only Token Budget, about not sending repeated blocks at all.

Commenti
Ancora nessun commento.
Accedi per commentare.