How Do You Order a Prompt So Caching Hits?
Why the order of a prompt decides whether the provider's cache hits, what breaks a hit, and how to set it up, explained simply for your AI interview.
In short
Put everything that stays the same at the start of the prompt, in a fixed order: tools, then the system prompt, then reference material. Put the changing parts, such as a timestamp or the user's message, after a cache breakpoint at the end of the fixed part.
12 min readIntermediateCommon · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
A model reads the whole prompt on every call, and the provider can save the start of it, so the next call skips that work. The match runs from the very top, so I put what stays the same first: the tool list, the system prompt, then reference material. The cache breakpoint sits after that block. Anything that changes, like a timestamp or the customer's message, goes last. One timestamp near the top, and the cache misses on every chat.
Caching means the provider keeps the work it already did on the start of your prompt. The match is strict: the saved copy is reused only when the new request starts with the same text, in the same order. So the order question comes down to which parts stay the same from one call to the next.
My rule is fixed first, changing last. Tools come first, then the system prompt, then reference material like a fee table. The cache breakpoint goes at the end of that block. The timestamp, the customer's question and the chat history so far come after it, because they change on every call. If the timestamp sat at the top, every request would miss, and we would process the fee table again and again.
Three things break a hit in practice. Rewriting a tool's description changes the start of the prompt. Summarising old turns in the middle of the prompt does the same. Sending parallel requests before the first one has saved the cache means nothing is there to hit. On a bank's support assistant, with the same tools and fee table on every chat, fixing the order can be one of the cheapest savings to make.
I also check the result, not just the layout. The response usage fields show whether a prompt was cached, so I can see the hit rate on real traffic and not guess.
What is prompt caching, in plain words?
A model reads your whole prompt on every call. Prompt caching lets the provider keep the work it already did on the start of that prompt, so a later call that begins the same way can skip it. The reused part is faster, and it costs less.
The provider checks whether the start of your prompt, up to a marked point, is already saved from a recent call. If it is, it reuses the saved copy. If not, it processes the prompt and saves it for next time.
Think of a hospital triage nurse with a protocol binder. The first pages are the same at the start of every shift, so she keeps her place in them. If someone swaps a page near the front, she has to reread everything after it, including the notes she has written since. A support bot works the same way. A made-up bank's assistant sends the same tool list and fee table on every chat. If a timestamp sits near the top, nothing after it can match a saved copy.
Key words
- Prefix
- The start of the prompt, read in order from the top, and the only part the cache can match.
- Cache breakpoint
- The marked point where the saved part ends. You place it, or the provider does.
- Cache hit
- The new request's start matches a saved copy, so the saved part is reused.
- Cache miss
- Something before the breakpoint changed, so the saved copy is not used.
- Changing part
- Text that differs on each call, such as a timestamp or the user's message.
So the order decides the match. Put what stays the same first, and what changes last.
What order makes the cache hit?
The provider's own docs describe the saved part as a fixed run of blocks, read from the top. Two quotes make the point:
“Prompt caching covers the full prefix: tools, system, and messages (in that order), up to and including the block designated with cache_control”
Anthropic
“If developer instructions or shared material contain timestamps, user-specific content, or other dynamic content, place those at the end rather than the beginning”
OpenAI
Anthropic's guide gives the same advice in plain terms: static content, meaning tool definitions, instructions, context and examples, goes at the start, and the breakpoint goes at the end of that fixed part, not on the block that changes. Some setups place the breakpoint for you: Anthropic's automatic caching puts it on the last cacheable block, so check where it lands.
Fixed parts first, changing parts last
Same on every call
Tool list
same tools, same descriptions
System prompt
role and rules, kept word for word
Fee table
reference data, rarely changes
Cache breakpoint
the saved part ends here
Changes every call
Timestamp
changes on every call
Customer question
the new message, last
Model
reads the saved and new parts
- 1The fixed part is read first and saved as one block.
- 2The saved part stops at the breakpoint.
- 3Next come the parts that change, timestamp first.
- 4The model reads the saved part and the new part together.
- 1
Tools first
The tool list is the same on every call, so it goes at the very top. Change one tool's description and everything after it misses.
- 2
System prompt next
The role, the rules and the house style rarely change. They sit straight after the tools.
- 3
Reference material after that
A fee table or a policy pack that changes rarely goes here, and the breakpoint goes at its end.
- 4
Changing parts last
The timestamp, the customer's question and the chat so far go after the breakpoint, where they cannot break the saved part.
Worked example. A bank's support assistant gets the same 12 tools, a 40-page fee table and its rules on every chat. These are made-up numbers, but the shape is real: the fixed part is large and identical from chat to chat. With the fixed block first and the breakpoint after the fee table, each new chat reuses that block. With the timestamp at the top, each chat writes it again.
What breaks a cache hit?
Anything that changes before the breakpoint stops the match for everything after it. OpenAI's guide says the whole prefix has to match, and that a change before a breakpoint means the prefix after it cannot match the saved entry.
Same lines, two orders, two results
Clock first
Timestamp
changes on every call
System prompt
same text, but after the clock
Clock last
System prompt
same text, first in the prompt
Timestamp
changes on every call, last
Cache miss
the saved copy no longer matches
Cache hit
the fixed part is reused
- 1The first line changes, so everything after it changes too.
- 2The fixed text comes first, so it stays the same.
- 3The second request finds no match and processes it all again.
- 4The second request reuses the fixed part; the clock and the question are new.
Here it is in plain Python, with a made-up bank bot. A hash of the prompt's start stands in for the saved copy, so you can see the match fail.
# A made-up bank support bot. No real model: a hash of the prompt's start stands in for the provider's saved copy.
import hashlib
TOOLS = "lookup_account(card_id), open_dispute(txn_id)"
SYSTEM = "You are the support assistant for a mid-size bank. Quote fees only from the fee table."
FEES = "Fee table 2026: foreign card use 2.5%, late payment 29 pounds."
def saved_copy_key(blocks, breakpoint):
# Everything up to the breakpoint must match, or the saved copy is not reused.
upto = blocks[: blocks.index(breakpoint) + 1]
return hashlib.sha256("\n".join(upto).encode()).hexdigest()[:8]
def clock_first(stamp, question):
return ["Sent at " + stamp, TOOLS, SYSTEM, FEES, question]
def fixed_first(stamp, question):
return [TOOLS, SYSTEM, FEES, "Sent at " + stamp, question]
for name, build in [("clock first", clock_first), ("fixed first", fixed_first)]:
first = build("09:01", "Why was my card charged twice?")
second = build("09:02", "Can I dispute the fee?")
key1 = saved_copy_key(first, FEES)
key2 = saved_copy_key(second, FEES)
result = "hit" if key1 == key2 else "miss"
print(name + ": request 1 key " + key1 + ", request 2 key " + key2 + ", request 2 is a " + result)Output
clock first: request 1 key ea79421d, request 2 key 1dba1780, request 2 is a miss fixed first: request 1 key e11d201b, request 2 key e11d201b, request 2 is a hit
- 1
A timestamp at the top
Dates, times and per-user names belong at the end. OpenAI says so directly, and a changed line up top is enough to lose the hit.
- 2
Tools that change between calls
OpenAI lists tool names, descriptions, schemas and ordering as things that change the tool part of the prefix. Keep them fixed.
- 3
History rewritten in the middle
Summarising, compacting or cutting old turns changes the prefix, so the saved copy resets.
- 4
Parallel calls sent too early
Anthropic's advice: if you need hits on parallel requests, wait for the first response before sending the rest. Nothing is saved until then.
Two more limits to know. A short prompt is not cached at all, even when it is marked. And a cache hit is never a promise: a key helps the provider route related requests together, but it does not guarantee a hit.
How would you cut a support bot's caching bill?
A made-up bank support bot is slow and costly. The logs show almost no cache hits, even though every chat starts with the same 12 tools and fee table. Someone added the current time to the system prompt last month, and nobody noticed that it sat at the top.
- Before
Clock at the top
The system prompt opens with the time, so the saved copy never matches. Every chat pays full price for the tools and the fee table.
- After
Fixed first, clock last
Tools, rules and fees come first, with one breakpoint after them. Each chat reuses them, and only the question and the time are new.
Cache reads cost significantly less than normal input, so the fix pays off on every chat after the first one that writes the cache.
Tip
Check it, don't assume it. Read the usage fields on each response to see whether the prompt was cached. If the hit count stays at zero, the order or the size is still wrong.
What does the interviewer want to hear?
A strong answer covers
- Caching reuses the start of a prompt, and the match is exact from the top.
- Fixed parts first: tools, system prompt, then reference material.
- One breakpoint at the end of the fixed part, with the changing parts after it.
- Named breakers: a timestamp at the top, changed tools, rewritten history.
- Hits checked in the usage fields, not guessed.
- A key helps routing, but nothing guarantees a hit.
Common traps
Trap"Put the user message first, so the model sees it."
BetterThe message changes on every call, so it belongs after the fixed block. The model still sees it.
Trap"Add the date to the system prompt so the model knows it."
BetterPut the date in the last block, after the breakpoint. The model still sees it, and the cache still hits.
Trap"A cache key makes the hit guaranteed."
BetterA key only helps routing. The order of the prompt is what you control.
Can you spot the cache breaker?
Spot the cache breaker
Each chat sends one of these system prompts. Which one misses the cache on every chat?
Quick check
A bank's support assistant sends the same tools and fee table on every chat. Each chat adds a timestamp and the customer's question. Which order caches best?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q095How do you handle very long documents?12 min
- Q096What is compaction (summarising history)?11 min
- Q097What is structured note-taking (external memory)?12 min
- Q098How do you pick and order few-shot examples?12 min
- Q326Prompt cache vs semantic cache vs KV cache?Coming soon
Learn it in depth
Last updated on 26 November 2026
Building a support bot that has to be fast and cheap?
I design and build AI assistants and agents, including the prompt layout and the cost checks behind them. Book a short call and tell me what your bot has to do.