AI BENCHNOTES
BENCH NOTE 001Cache tokensContext windows
AI BENCHNOTES
THE COMPLETE WORKBENCHPick a machine part.
12 NOTES / 12 LABS / ZERO INCENSE

Start anywhere. The numbers are a useful route, not homework police.

00Animated bench map
CONCEPT 001mildly spicy

Cache tokens:your model’sdéjà vu.

When a prompt begins the same way as one the model saw recently, that matching beginning can be reused. Less repeated work. Lower latency. A happier invoice.

  • AUTOon eligible requests
  • EXACTprefix matches only
  • 1,024+tokens on OpenAI
REQUEST_002.PROMPT LIVE
INPUT PREFIX4,608 TOKENS
systemrules
toolschemas
repocontext
newtask
CACHE LOOKUPHIT

4,352 tokens skipped the expensive part

09:41:02 prefix hash matched

09:41:02 attention state restored

09:41:02 only fresh tail processed →

01 / THE SHORT VERSION

The model doesn’t remember your answer. It reuses the warm-up.

Prompt caching stores reusable intermediate attention state for a matching input prefix. The model still generates a fresh output. Think mise en place, not reheated leftovers.

REQUEST#1
System prompt800
Tool schemas1,400
Shared context2,200
Task A200
MISSBuilds cache
REQUEST#2
System prompt800
Tool schemas1,400
Shared context2,200
Task B180
HIT4,400 reused
REQUEST#3
System prompt800
Tool schemas1,400
Shared context2,200
Task C240
HIT4,400 reused
In plain English:

“I’ve already read your 40-page instruction manual. Just tell me what today’s question is.”

02 / INTERACTIVE LAB

Build a prompt the cache can love.

Pick a workload, then commit the cardinal sin: move the changing part to the front. Watch one tiny choice nuke the reusable prefix.

PROMPT COMPOSERCoding agent
REQUEST Awarms the cache
01System promptrole, rules, coding standards820 tknREAD
02Tool schemasshell, search, patch, test1,380 tknREAD
03Repository contextrepo map, AGENTS.md, conventions2,250 tknREAD
04Current taskFix the flaky auth test230 tknREAD
REQUEST Btries to reuse it
01System promptrole, rules, coding standards820 tknCACHE
02Tool schemasshell, search, patch, test1,380 tknCACHE
03Repository contextrepo map, AGENTS.md, conventions2,250 tknCACHE
04Current taskAdd CSV export to reports230 tknFRESH
LONGEST MATCHING PREFIX4,450 tokens can be reused

Stable rules, tools, and repository context

95%input cached
cached prefix4,450tokens
fresh tail230tokens
prompt shapestatic → dynamicchef’s kiss
03 / THE ONE WEIRD RULE

A match is a zipper. Break one tooth, lose everything after it.

Cache matching moves left to right. It can reuse the exact prefix before the first difference—never skip a changed bit and resume later.

CACHE-BUSTING GAMEClick any block in Request B to mutate it.
ACACHED
You area precisesupport agent.Follow policy v4.Use JSON.Tools: lookup, refund.Customer #1842asks about returns.
BNEW
REUSABLE PREFIX7 of 8 blocks

Great: the first difference is near the tail, where variable data belongs.

04 / NAPKIN MATH

Now multiply that déjà vu.

The first request does the full read. Similar requests reuse the shared beginning for less. That is the whole trick.

Fixed example: a 6,000-token shared beginning. Cached reads cost 25% of a normal read. Every request also has a fresh 400-token tail.

64%
LESS INPUT COST

in this simplified 12-request example

Excludes output tokens, cache-write premiums, minimum cacheable lengths, and provider-specific pricing. This is intuition math, not a quote.

05 / WHERE IT SLAPS

Look for big, boring beginnings.

The ideal workload repeats a long, identical setup and changes only a small tail. In AI engineering, that pattern is everywhere.

EXCELLENT FIT

Coding agents

Reuse the system prompt, tool definitions, repo map, and coding conventions. Append today’s task at the end.

rulestoolsrepotask
static setup → “fix flaky test”
EXCELLENT FIT

Support copilots

Keep policies, product facts, tone rules, and tool schemas stable. Add the customer conversation last.

policycatalogexampleschat
stable playbook → customer issue
VERY NICE FIT

Batch extraction

Reuse a large extraction schema and worked examples. Put each new document after that fixed instruction set.

schemaexamplesdocument
schema + examples → new document
Cache-shaped
  • Long system prompts
  • Stable tool definitions
  • Repeated few-shot examples
  • Shared reference documents
  • Multi-turn conversations with a stable beginning
Probably not worth obsessing over
  • Short one-off prompts
  • Everything changes every request
  • Personalization injected at the top
  • Randomly reordered tools or examples
  • Traffic too sparse for the cache to stay warm
06 / UNDER THE HOOD

The anatomy of a cache hit.

  1. 1
    ROUTE

    Fingerprint the beginning

    The service hashes an initial prompt prefix and uses it to route similar requests toward the same cache neighborhood.

  2. 2
    LOOK UP

    Find the longest exact prefix

    The cache checks for matching prompt state. If several prefixes match, the longest useful one wins.

  3. 3
    RESUME

    Restore state, process the tail

    Cached attention state is loaded. The model processes only the uncached suffix, then generates a brand-new response.

07 / PIN THIS ABOVE YOUR DESK

Five rules for cache-friendly prompts.

STATICFIRST.DYNAMICLAST.
  1. 01

    Put reusable content first.

    System instructions, tool schemas, examples, and shared context lead the prompt.

  2. 02

    Put user-specific content last.

    Names, timestamps, live data, current tasks, and conversations belong at the tail.

  3. 03

    Keep serialization deterministic.

    Don’t shuffle tools, object keys, examples, or whitespace for fun. Exact serialized stability matters.

  4. 04

    Group related traffic when your API supports it.

    A stable prompt cache key can improve routing for requests that share the same long prefix.

  5. 05

    Measure actual hits.

    Log the cached-token count. A beautifully structured prompt with zero hits is just typography.

08 / SHOW ME THE BYTES

What it looks like in an API response.

You usually don’t “fetch” a prompt cache yourself. Send a stable prefix, then inspect usage metadata to see what was reused.

const response = await client.responses.create({
  model: "your-cache-capable-model",

  // Keep this stable for requests with the same prefix.
  prompt_cache_key: "coding-agent:repo-42:v3",

  input: [
    { role: "system", content: SYSTEM_PROMPT },
    { role: "developer", content: TOOL_SCHEMAS },
    { role: "developer", content: REPO_CONTEXT },

    // The changing part goes last.
    { role: "user", content: currentTask }
  ]
});
09 / PLEASE DO NOT SAY THIS IN STANDUP

Three common wrong ideas.

MYTH #1

“It caches the answer.”

Nope. Prompt caching reuses work done while reading the input. Output generation still happens again.

WRONG
CACHE
MYTH #2

“Semantically similar is close enough.”

Not here. Similar meaning is irrelevant if the prefix differs. This is exact-match territory.

NOPE
MYTH #3

“More cached tokens means lower quality.”

The computation is reused, not approximated. Same prefix, same state—just less repeated prefill work.

NAH
10 / POP QUIZ, HOTSHOT

Where does the cache stop?

Request B changes one character inside the tool schema, then returns to content identical to Request A.

Pick one. Your dignity is not being logged.
KEEP GOING / THE RABBIT HOLE IS WARM

Next bench notes.