Back to Blog
EnglishTutorial

Claude Prompt Cache Not Working? A Four-Request Usage Test

Reproduce four native Claude requests with a stable prefix and explicit breakpoint. Observe cache writes, one read and an unexpected changed-question miss.

S
Sophie M
October 11, 2026 / 385 views
Share:
Claude Prompt Cache Not Working? A Four-Request Usage Test

If Claude prompt caching appears broken, inspect cache-write and cache-read usage, then compare the complete prefix and cache breakpoint. Keep an unexpected miss visible: a successful hit on one request does not establish that later requests share the same cache state.

Crazyrouter is the AI API gateway used in this four-request native Claude test: the first request wrote 7,225 cache tokens, and the identical repeat read 7,225. A changed final question then reported another write with zero reads, even though the tested system prefix was unchanged.

By Sophie M · Tested November 3, 2026

Claude prompt cache not working: check usage first#

The Claude prompt-cache documentation explains explicit breakpoints, prefix matching, supported models and cache lifetimes. These details are model- and interface-dependent. For this experiment we used an explicit cache_control block with type: ephemeral; we did not test one-hour retention or wait for expiration.

The relevant response fields are cache_creation_input_tokens, cache_read_input_tokens, input_tokens, and output_tokens. Keep them distinct. An HTTP 200 or a fast response does not tell you which input was reused.

What changed in the four-request sequence?#

On November 3, 2026, Python 3.10.2 sent four requests to host https://api.crazyrouter.com, endpoint /v1/messages, model claude-sonnet-4-6. A random run marker plus 450 synthetic records formed a 28,856-character system prefix. Each response had to end with end_turn and return CACHE-1461.

CaseNew cache writesCache readsOrdinary inputSeconds
first72250132.934
repeat07225132.378
changed question72250172.053
changed prefix72300132.337

Observed response IDs (successful responses only):

text
msg_011CgfqrbDjc6mE9yTCEdCu7
msg_011CgfqrmJxeWXkb2C8wmnGY
msg_011CgfqruEhMxuf9c9bzmdzw
msg_011Cgfqs6W7ugWPVk6ZWDD74

Claude cache-write counters in the four-request sequence

The first three requests had the same recorded SHA-256 system-prefix digest. The changed-question request nevertheless reported 7,225 newly written tokens and zero cache reads. We did not inspect upstream routing or internal normalization, so neither can be stated as the cause. The final case prepended “Revised records.” and reported a new 7,230-token write.

Run the complete native probe#

Install requests, set CRAZYROUTER_API_KEY in the process environment, save this as claude_cache_probe.py, and run it. It prints the usage counters, prefix digest, response ID and validated answer for each request. Each execution uses a new run marker.

python
"""Four native Messages requests with explicit prompt-cache controls."""
import hashlib
import json
import os
import time
import uuid
import requests

def main():
    session=requests.Session();session.trust_env=False
    session.headers.update({'Authorization':'Bearer '+os.environ['CRAZYROUTER_API_KEY'],'anthropic-version':'2023-06-01'})
    endpoint='https://api.crazyrouter.com/v1/messages';model='claude-sonnet-4-6'
    prefix='Synthetic cache fixture '+uuid.uuid4().hex+'\n'
    prefix+='\n'.join(f'Record {i:04d}: synthetic item, approved status, no customer data.' for i in range(450))
    rows=[]
    cases=[('first',prefix,'Reply only CACHE-1461'),('repeat',prefix,'Reply only CACHE-1461'),('changed question',prefix,'Using the records, reply only CACHE-1461'),('changed prefix','Revised records.\n'+prefix,'Reply only CACHE-1461')]
    for label,system,question in cases:
        payload={'model':model,'max_tokens':32,'system':[{'type':'text','text':system,'cache_control':{'type':'ephemeral'}}],'messages':[{'role':'user','content':question}]}
        start=time.perf_counter();response=session.post(endpoint,json=payload,timeout=90)
        response.raise_for_status();data=response.json()
        answer=''.join(x.get('text','') for x in data['content'] if x['type']=='text')
        assert data['stop_reason']=='end_turn' and answer.strip()=='CACHE-1461'
        rows.append({'label':label,'response_id':data['id'],'http':response.status_code,'seconds':round(time.perf_counter()-start,3),'output':answer,'usage':data.get('usage',{}),'prefix_sha256':hashlib.sha256(system.encode()).hexdigest(),'finished':True})
    print(json.dumps({'endpoint':endpoint,'model':model,'prefix_chars':len(prefix),'requests':rows}))

if __name__=='__main__':main()

This is a diagnostic sequence, not an automated repair. It does not change routing, alter the TTL or retry a miss until it looks successful. The bounded retry guide covers transient request failures separately.

A diagnosis order that preserves evidence#

CheckEvidence to retainWhat it can establish
Correct native interfaceEndpoint and request shapeWhether the cache directive was placed in the tested protocol
Complete responseStop reason and expected outputWhether the generation completed
Prefix identitySerialized prompt or safe digestWhether your application changed the tested input
Cache countersWrites, reads and ordinary inputWhat the route reported
Crazyrouter route behaviorRequest IDs and timestampsA traceable case for investigation, not an inferred upstream cause

Only the identical repeat reported cache-read tokens in this sequence

Tool definitions and system content can affect the reusable prefix. Preserve the actual tool invocation and result sequence when compacting history; the tool-use ID guide shows the pairing checks. A broken conversation and a cache miss are different failures.

For OpenAI-compatible Chat Completions, inspect the appropriate cached_tokens field instead of renaming Claude fields. See the separate three-request prompt-cache experiment and the protocol comparison.

Report limits without losing the useful result#

This result replaces neither a production hit-rate study nor account billing reconciliation. We tested one synthetic prefix and one selected Claude model. The four wall times were 2.934, 2.378, 2.053 and 2.337 seconds; a miss was faster than the observed hit, illustrating why timing alone is inadequate.

The earlier October 11 experiment in this article used a different prefix and regional origin. Its 5,424-token counters must not be relabeled as this new run. Current conclusions use the November evidence above. Store request metadata using purpose-limited telemetry, without retaining customer prompts unnecessarily.

FAQ#

Why did the first request have zero cache reads?#

It reported a new cache write for this run's unique prefix. The response still completed successfully.

Why did the unchanged prefix miss after changing the question?#

The test did not identify the cause. We retained the shared prefix digest and usage to make the observation traceable.

Should I switch to a one-hour TTL?#

Not on this evidence alone. No expiration or one-hour retention test was performed here.

Can I prove a cache hit from response speed?#

No. In this sequence a request reporting a miss was faster than the request reporting a hit.

Does the cached prefix include my whole conversation?#

Do not assume it does. Follow the documented breakpoint and prefix rules, and inspect the counters for the actual request.

Do cache reads remove output charges?#

No such billing claim was tested here. Reconcile input, cache categories and output under your actual billing rules.

Implementation Guides

Podcast

AI Dev Tools: The Crazyrouter Podcast

Short episodes for developers on AI APIs, gateways, cost control and coding tools.

Latest episodes

  • EP196 · Oct 29, 2026 · 6:53

    AI API Security Posture — Turn Controls Into Continuous Evidence

    A practical guide to AI API security posture: inventory exposure, verify controls continuously, protect keys and data, constrain tools, and turn security assumptions into evidence that operators can act on.

  • EP195 · Oct 28, 2026 · 7:21

    AI API Policy Drift — Detect When Production Rules Stop Matching Intent

    A practical guide to policy drift in AI APIs: version routing and safety rules, detect stale enforcement, compare intended and observed behavior, and restore control before small gaps become incidents.

Episodes with written show notes →

Related Articles

Model Distillation in Python: Fit a Tiny Student to Soft Teacher LabelsTutorial

Model Distillation in Python: Fit a Tiny Student to Soft Teacher Labels

An executable two-parameter student learns probabilities from a synthetic teacher. Nine training inputs, four held-out points and four checks illustrate distillation without claiming an LLM was trained.

Mar 30
Function Calling Across Providers: OpenAI and Claude Tool Round TripsTutorial

Function Calling Across Providers: OpenAI and Claude Tool Round Trips

Compare native tool message formats and run verified Python round trips for GPT-4.1-mini and Claude Sonnet 4.6, with argument validation and result correlation.

Mar 18
Can Claude Code Build a World Cup 2026 Match Predictor? A Real Crazyrouter API TestTutorial

Can Claude Code Build a World Cup 2026 Match Predictor? A Real Crazyrouter API Test

We built a reproducible World Cup 2026 match predictor demo with Claude Code-style workflow, Elo/Poisson probabilities, charts, and real Crazyrouter API calls through https://cn.crazyrouter.com/v1.

Jun 12
How to Get a Claude API Key: Step-by-Step GuideTutorial

How to Get a Claude API Key: Step-by-Step Guide

"Step-by-step guide to getting a Claude API key from Anthropic or through Crazyrouter. Includes setup instructions, code examples, and pricing comparison."

Feb 15
CC-Switch + Crazyrouter: Claude Code Base URL Setup GuideTutorial

CC-Switch + Crazyrouter: Claude Code Base URL Setup Guide

Set up Crazyrouter in CC-Switch for Claude Code-style workflows, with base URL notes, model routing tips, and compatibility caveats for current tool versions.

Feb 15
Codex CLI Installation Guide 2026: Windows, macOS, Linux, Proxies, and CI SetupTutorial

Codex CLI Installation Guide 2026: Windows, macOS, Linux, Proxies, and CI Setup

If you searched for **codex cli installation**, you probably do not need another shallow feature list. You need to know what Codex CLI is, how it compares with alternatives, how to use it in a develop...

May 26