Blog

GPT prompt caching: how to improve cache hit rates

· updated · by

TL;DR. Treat prompt caching as a request-shape problem, not a cache-key problem. On GPT-5.6 and later, a cache hit requires exact rendered bytes from byte 0 through an eligible breakpoint. In a 39-round production trace (401K to 515K tokens), a changing tail collapsed cache reads to 0.66% while rewriting 99.34% of the prompt at 1.25x input cost. Switching to explicit dual breakpoints lifted controlled-probe caching 37.7x (from 1,215 to 45,786 of 45,805 tokens, 99.96%) and moved production hit rates to 9.86% while exposing a remaining turn-boundary miss.

Multi-turn agent loops look append-only at the message level, yet still miss the cache when each round appends a disposable runtime block right before the default breakpoint. We hit this in production, isolated it with paid live probes, and measured the production follow-up after shipping explicit breakpoints.

Video: Why GPT-5.6 prompt caching drops to 1% in agent loops (and how to fix it)

Production trace, controlled probes, and follow-up

Our initial production trace came from one 39-round session on GPT-5.6 Luna through OpenRouter (identifiers and prompt text removed; prompt range rounded to the nearest thousand). System instructions and tools were byte-stable, rounds ran about 10 seconds apart, and the context window was not full, yet nearly every round paid to rewrite the entire prompt (about $0.218 on a representative 437K-token round, reading 3,467 or 0 cached tokens).

We then ran paid controlled probes against the same live endpoint, changing one variable at a time, and later pulled a 20-round postdeployment production trace on August 24 to measure the real impact.

GPT-5.6 prompt-cache results: controlled probes jumped from 1,215 to 45,786 cached tokens (99.96%, 37.7x); production hit rate rose from 0.66% on August 22 to 9.86% on August 24 while average model cost fell from $0.243 to $0.188 per round.GPT-5.6 prompt-cache results: controlled probes jumped from 1,215 to 45,786 cached tokens (99.96%, 37.7x); production hit rate rose from 0.66% on August 22 to 9.86% on August 24 while average model cost fell from $0.243 to $0.188 per round.
Controlled probe reuse (top) and production follow-up traces before and after explicit breakpoints (bottom).

Controlled probes (live billed calls)

Probe Request shape Result
Broken shape Same key, diverged before prior cached boundary 1,215 cached tokens (common head stub only)
Optimized shape Same key, strict extension with explicit dual breakpoints 45,786 / 45,805 cached tokens (99.96%)
Repeat control Second strict extension of its seed request 45,731 / 45,753 cached tokens (99.95%; ~1/12th cold cost)
Key control Byte-identical prompt with a different prompt_cache_key 0 cached tokens

The optimized shape returned 37.7x as many cached tokens as the broken replay. That is a cached-token ratio, not a blanket bill reduction: output tokens, images, uncached suffixes, gateway fees, and long-context pricing tiers still apply.

Production follow-up: improved, not fixed

Production metric (model cost only) Before deploy (Aug 22) After deploy (Aug 24)
Model rounds 39 20
Prompt size 401K to 515K 441K to 469K
Token-weighted cache hit rate 0.66% 9.86%
Cache writes / reported prompt tokens 99.34% 40.66%
Upstream-reported model cost per round $0.243 $0.188

Because the postdeployment trace has 20 rounds instead of 39, this is not a like-for-like closure, and one failure remains open: the turn boundary. During the first 14-call turn on August 24, cache reads and writes were each 14.26% of reported prompt tokens. The next six calls each started a new turn, read zero cached tokens, and rewrote 99.9% of their prompts. Explicit breakpoints fixed reuse inside a multi-call turn, but our runtime still drops the reusable boundary when a new turn begins.

What GPT-5.6 actually matches

Treat every prompt-cache lookup as four conditions that must all hold together: same model and provider route, same prompt_cache_key, exact rendered bytes from byte 0 through a cache breakpoint, and a live cache entry. Tool definitions, structured-output schemas, images, and files are part of that rendered prefix, so unstable tool ordering invalidates the cache even when message text never changes.

OpenAI's prompt-caching guide draws a sharp boundary starting at GPT-5.6:

Behavior GPT-5.6 and later Earlier cache-capable GPT models
Match behavior Exact matching at eligible breakpoints Automatic best-effort prefix reuse
Default breakpoint Latest user or tool message Managed automatically
Fallback to earlier unmarked prefix No Best-effort matching may reuse earlier prefix
Explicit breakpoints Supported Not supported
Minimum cacheable prefix 1,024 tokens 1,024 to 2,048 tokens, model-dependent
Cache write rate 1.25x uncached input No separate write rate

Because GPT-5.6 does not search backward for the longest unmarked match, putting a fresh timestamp or regenerated runtime block inside the latest user message makes the default breakpoint miss and pay the 1.25x write rate again.

The transient-tail trap in agent loops

Step through the four measured request shapes below to see why implicit breakpoints break when a disposable tail (T1, T2) changes each round, and why you must keep both the previous durable breakpoint (for reading) and the current durable breakpoint (for writing the next round):

Interactive prefix simulator · GPT-5.6 caching

Transient tail T1 breaks exact-prefix match on round 2

1,215 / 45,805 cached (2.7%)

Round 1 (writes cache entry)

Stable A (sys + tools + history)Transient T1Implicit BP

Round 2 (lookup against Round 1)

Head stub onlyStable A + B rewritten (1.25x)Transient T2Implicit BP
Measured outcome: 1,215 cached tokens (only common head stub)

Because T1 is absent from round 2, round 1's cached entry is not a prefix of round 2. On GPT-5.6, the default implicit breakpoint does not search backward for an unmarked match at A.

Compare broken implicit breakpoints, explicit dual breakpoints, key changes, and production turn-boundary behavior (PLO-82 / PLO-155 measurements).

Keeping only a moving current breakpoint fails on round 2 because no earlier request wrote that new boundary. On round 1, mark the current durable boundary to seed the cache; from round 2 onward, keep the previous boundary for the read and place the new boundary at the end of the extended durable history.

Choose the caching mode and prefix layout

  • Implicit mode fits strictly append-only conversations where future requests repeat the whole tail.
  • Hybrid mode (implicit on plus an explicit marker) protects a shared static prefix while still caching recent history, though the implicit tail can still trigger writes on changing suffixes.
  • Explicit-only mode (prompt_cache_options.mode: "explicit" with at least one prompt_cache_breakpoint) fits agent loops with disposable tails. Omitting markers in explicit mode disables caching for that request.
Six-layer request order for GPT-5.6 explicit prompt caching: keep instructions, sorted tools, shared files, and durable history before the explicit breakpoint, and place timestamps, request IDs, and live state after it.Six-layer request order for GPT-5.6 explicit prompt caching: keep instructions, sorted tools, shared files, and durable history before the explicit breakpoint, and place timestamps, request IDs, and live state after it.
Keep byte-stable layers before the explicit breakpoint and isolate changing runtime data after it.

Minimal Chat Completions request for GPT-5.6 explicit caching:

{
  "model": "gpt-5.6",
  "prompt_cache_key": "conversation:7f3c...",
  "prompt_cache_options": {
    "mode": "explicit",
    "ttl": "30m"
  },
  "messages": [
    {
      "role": "system",
      "content": [
        {
          "type": "text",
          "text": "Stable instructions and reference material...",
          "prompt_cache_breakpoint": { "mode": "explicit" }
        }
      ]
    },
    {
      "role": "user",
      "content": "Request-specific input..."
    }
  ]
}

Every prefix through a marker must render to at least 1,024 tokens. In the Responses API, attach markers to supported input_text, input_image, or input_file blocks; because top-level instructions cannot carry a breakpoint, move reusable instructions into a developer message. Canonicalize maps and sets inside tool schemas, never embed live timestamps in system prompts, and assign a new cache family after context compaction or truncation instead of treating compacted history as an extension of old bytes.

Through a gateway, confirm that cache fields pass through unchanged. The OpenRouter caching guide documents prompt_cache_key, prompt_cache_options, block-level breakpoints, and session_id for provider stickiness; other gateways may drop or translate them.

Scope cache keys and pin provider affinity

Use one deterministic hash per shared prefix (session-scoped or template-versioned) and never put raw account IDs, emails, or prompt text in the key. Rotating the key resets the cache cleanly after prompt, tool-schema, or compaction changes; minting a random UUID per round breaks reuse.

OpenAI recommends keeping traffic per key near 15 requests per minute; partition heavier workloads with a deterministic bucket suffix rather than random sharding. On multi-provider gateways, pin provider affinity first (session_id) because a matching prefix cannot hit a cache entry on another provider.

Measure reads and writes separately

Log cached_tokens and cache_write_tokens from usage.prompt_tokens_details (Chat Completions) or usage.input_tokens_details (Responses), alongside total input tokens, model, hashed key bucket, template version, and segment hashes (system, tools, durable prefix) so you can spot byte drift without logging raw prompts.

Pattern Likely meaning
High reads, small writes Healthy append-only extension
Low reads, near-full writes Breakpoint includes changing content, wrong key, cold entry, or provider drift
Reads and writes both zero Below 1,024-token minimum, explicit mode with no marker, or dropped fields
Reads and writes both nonzero Earlier prefix read and later prefix written (normal in implicit or dual-marker mode)
Hits drop only at high volume Key traffic above ~15 rpm or lost provider affinity

Track token-weighted hit rate (sum(cached_tokens) / sum(input_tokens)) rather than the share of requests with nonzero hits (reading 3,467 tokens out of 500,000 is under 1%). On GPT-5.6, pair it with write amplification (sum(cache_write_tokens) / sum(input_tokens)): low reads next to high writes means paying the 1.25x write premium without collecting the 0.1x read discount.

Debug with a five-request probe

Before editing production prompts, run five small live calls above the 1,024-token minimum and within the 30-minute TTL against your real model and gateway route, changing one variable at a time:

  1. Send prefix A with a stable key (expect a cache write).
  2. Send prefix A again with the same key (expect a cache read).
  3. Send A plus a new suffix with the same key (expect A to be read).
  4. Send a strict append-only extension and confirm the new boundary writes.
  5. Resend identical bytes with a different key (expect 0 reads from key 1).

If step 2 misses, diff the serialized bytes before the breakpoint, then check key, route, TTL, and gateway forwarding. If step 2 hits while step 3 misses, your breakpoint sits inside changing content.

Cost math and limits

On GPT-5.6 and later, OpenAI bills cached reads at 0.1x uncached input and cache writes at 1.25x total (not 1.25x added on top of 1.0x), making writes 12.5x more expensive than reads. Calculate each segment separately using the serving endpoint's actual tier rates (including long-context rates, which accounted for the $0.218 cost on our 437K-token round):

input cost =
    cached_read_tokens * cached_read_rate
  + cache_write_tokens * cache_write_rate
  + ordinary_uncached_tokens * uncached_input_rate

Caching does not make outputs deterministic, does not exclude tokens from rate limits, and does not guarantee indefinite retention (GPT-5.6 TTL is 30 minutes, refreshed on reuse, but cold misses can still occur). When early bytes genuinely vary on every call, keep the cacheable prefix honest rather than distorting the prompt for a higher ratio.

Sources and measurement note

  • OpenAI prompt caching guide, checked 2026-08-22 for GPT-5.6 matching, breakpoints, pricing ratios, TTL, and metrics.
  • OpenRouter prompt caching guide, checked 2026-08-22 for gateway field support and session stickiness.
  • Measurements come from 2026-08-22 and 2026-08-24 production traces plus paid controlled probes (identifiers and prompt text removed). No publishable latency benchmark was collected, so this post makes no latency claim.