Prompt Cache: 2,688 of 2,896 Tokens Hit, One Line Kills It

🔧 AI Tools 2026-11-28 7 min read
Prompt Cache: 2,688 of 2,896 Tokens Hit, One Line Kills It

A prompt cache is supposed to cut the cost of a repeated system prompt by an order of magnitude, and it does, until a logging layer puts a request id or a timestamp on the first line.

📜 Table of Contents

📖 Keep reading

A repeated prompt is billed twice over unless the front of it is byte-identical to the last request. I put a 2,201-word house handbook in the system message and asked eight questions against it. Seven of those calls billed 207 input tokens instead of 2,896. Then I put a twelve-token request-id line above the handbook, and seven calls out of seven paid the full 2,912.

Both outcomes come from the same mechanism, and the rules around it are stricter in one place and looser in another than the documentation suggests. Stricter: anything new at the top of the prompt wipes the whole prefix, even a date. Looser: a sentence appended at the end costs only its own twenty tokens, and editing a clause seven-tenths of the way in costs only what follows it.

How the run was set up

What a hit is worth at 2,896 tokens

callprompt tokenscache hitcache missms
warm (prefix not seen before)2,89602,896686
22,8952,688207661
32,8952,688207644
42,8972,688209678
5 to 82,894 to 2,8962,688206 to 208635 to 764

Steady state is 2,688 cached of 2,895 prompt tokens, 92.8 per cent, and the 207 that still bill are the question plus the tail of the handbook that never fits into a full cache block. Every hit figure in this post is a multiple of 64, because the cache is accounted in 64-token blocks: 256, 1,792, 2,688, 19,328. Two consequences follow. The last partial block of a prompt is always billed, and a prompt shorter than one block is never cached at all.

That also explains the small arm: a 300-word prefix of 425 tokens returned 256 cached, four blocks, 60 per cent of the prompt. Caching works at small sizes, it just cannot reach the tail.

One line at the top kills the whole prefix

Arm B prepends the string Request 2026-11-28-02, run id 7002. and changes nothing else. Seven follow-up calls: zero cached, 2,911 to 2,914 billed. Not a partial hit, not a smaller hit, zero every time. The prefix behind the line is identical to arm A, character for character, and it does not matter, because matching starts at the first token.

This is the expensive part of ordinary middleware. A request id, a session stamp, a clock, or a run counter is exactly what a logging layer puts at the top of the system prompt, and each of those turns a 92.8 per cent discount into nothing. The same line placed at the bottom of the prompt would have cost twelve tokens.

An edit in the middle costs only the tail

Arm C changes one clause seventy per cent into the handbook, 30 days becomes 45 days, and appends a six-word amendment. The first call after that edit: 1,792 cached, 1,110 billed. 1,792 is twenty-eight blocks of 64, which is where the edit falls. Everything before it was reused.

Calls three through eight in that arm went back to 2,688 cached, because the edited prefix had itself become the cached one by then. Which is the second rule worth internalising: the cache does not hold your original prompt, it holds whichever prefix it saw last. Rotating between two long versions of a handbook on alternate calls is the worst case, since neither version survives to the next call.

The end of the prompt is nearly free

armchange to the prefixcache hit, first call after the changemiss tokens
Anone2,688207
Bone request-id line prepended02,912
Cone clause edited 70% in1,7921,110
Da trailing space added2,688208
Fa 20-token sentence appended2,688227
E, 425-token prefixnone256168

Appending a space changed nothing. Appending a twenty-token circular cost twenty tokens. Both are obvious once the block accounting is clear, and both are useful: anything that has to change per request should sit at the end, not the beginning.

The hierarchy that follows is worth writing into the prompt builder rather than remembering. Stable rules first, then stable reference material, then the tool schemas, then the per-request fields, then the question. Anything that rotates goes below everything that does not.

Cost per thousand calls

1,000 calls, prefixno cachecache warmsaved
2,896 tokens$0.434$0.03991%
19,519 tokens$2.93$0.08797%

Arithmetic, so it can be checked: hit tokens times $0.003 per million plus miss tokens times $0.15 per million, output excluded because it does not change. At 2,896 tokens the saving is 91 per cent; at 19,519 tokens it is 97 per cent, because the fixed part grows while the per-request tail stays the same size. A batch job that reuses one long instruction set a thousand times a day is where this shows up as real money rather than a rounding difference.

Latency did not move

Mean wall clock across the forty-two calls: 614 to 904 milliseconds, with the uncached warm calls at 633 to 686 milliseconds and cached calls in the same range. At 19,519 tokens the five calls ran 633, 738, 865, 904 and 734 milliseconds, cached from the second call on. If prefill were the bottleneck the cached calls would be visibly faster, and they are not, because generation of the answer dominates at these sizes and this model prefills quickly anyway.

So treat the cache as a bill discount, not a speed feature. Anyone quoting a time-to-first-token win from caching is describing a much larger prompt or a slower prefill than this one.

The recipe

def build_messages(rules, reference, tools, request_fields, question):
    # every element above the question is stable across calls
    system = rules + chr(10) + reference
    return [
        {"role": "system", "content": system},
        {"role": "user", "content": request_fields + chr(10) + question},
    ]

Three habits do the work. Keep the volatile fields below the stable ones. Never put a date, a request id or a run counter at the top, put it in the user turn. Do not alternate between two versions of the same reference document on consecutive calls unless the second version is the one you intend to keep.

What this does not show

One provider, one model, one evening. The cache lifetime was not tested, so the hour-scale expiry in the documentation is unverified here. Concurrency was not tested, and parallel workers sharing one prefix may evict each other in ways a serial run cannot reveal. The handbook is synthetic and highly repetitive, so its token boundaries are tidier than a real policy document. And nothing here says whether a cache hit changes the answer: temperature was zero, so there was no answer variance to measure.

Four numbers to keep: 2,688 of 2,896 tokens cached on a stable prefix, 0 of 7 after a single request-id line was prepended, 1,792 recovered after an edit at seventy per cent depth, and 91 to 97 per cent off the input bill at 2.9k and 19.5k tokens. Where the same accounting bites from the other direction is in the 8,038 tokens four MCP servers spend on tool schemas, in the difference between JSON and CSV tool results, and in six codebases that overflow a 200k window; the tokenizer side of the same bill is in twelve sentences counted four ways.

Related Articles
2026-08-16
Best AI Scheduling Assistant for Clinics 2026: 6 Tools That Fill Your Calendar
2026-08-02
Text to SQL 2026: 5 Tools That Turn Plain English Into Working Queries
2026-07-27
Claude Code vs Cursor 2026: Which AI Coding Assistant Is Better?
2026-08-14
Free AI Flowchart Generator 2026: 6 Tools From Text to Flowchart
2026-07-24
Best Free AI Email Assistants 2026
2026-08-20
Best AI Product Photo Generator for Wholesale in Guangzhou 2026: 6 Tools for E-commerce Exporters

Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.

💬 Comments (0)

No comments yet. Be the first!

Login to comment