Skip to content
Dmitry Golovach
Go back

One prompt, two models, two caches

I wanted to know one thing: if Haiku caches a prompt, can Sonnet use that cache?

What I tested

One Python script, the plain Claude API, no framework. The models are claude-haiku-5-5 and claude-sonnet-5-5. The same long system prompt goes out four times, marked for caching:

  1. Haiku, first time
  2. Haiku again
  3. Sonnet, same prompt
  4. Haiku again

The prompt starts with a random run id, so every run starts with an empty cache. Each call asks for one word, “OK”.

client.messages.create(
    model=model,
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": system_prompt,
        "cache_control": {"type": "ephemeral"},
    }],
    messages=[{"role": "user", "content": "Reply with just the word OK."}],
)

The result

The prompt was 3,485 input tokens on both models. 3,469 of them were cached, and 16 were the rest of the request.

CallModelCache writeCache read
1Haiku3,4690
2Haiku03,469
3Sonnet3,4690
4Haiku03,469

Call 3 is the answer. Sonnet could not read the cache Haiku wrote, so it wrote its own. Haiku’s cache was not lost: call 4 read it again. The default cache lives 5 minutes, and each hit starts the 5 minutes again. My four calls ran one right after another, so call 4 still found it.

So each model has its own cache. If an app switches models in the middle of a conversation, the new model pays the cache write again.

The docs say the same

The Claude Code prompt caching page has a “Cache scope” section. It says two requests share a cache only when their model, speed and prefix match. My lab tests the model part. By the same rule, turning fast mode on or off also starts a new cache. I did not test fast mode.

This is not a new finding. The claude-model-switch-tax repo on GitHub ran the same Haiku to Sonnet test through Claude Code. I wanted to see it on the plain API with my own numbers.

The trap I hit first

My first run cached nothing. I had left the prompt at 3 lines, 176 tokens. That is under the 512-token minimum for both 5.5 models. The minimum is not the same for every model: Sonnet 5 needs 1,024 tokens and Haiku 4.5 needs 4,096. On Haiku 4.5, even my 3,485-token prompt would not cache.

All four calls came back with cache write 0 and cache read 0. Every reply was “OK”. There was no error and no warning.

That is the part I will remember. A cache mark in the request does not mean anything was cached. The only proof is in the usage fields: cache_creation_input_tokens and cache_read_input_tokens. Check them on every call.


Share this post:

If you're working on similar problems, I'm happy to compare notes.

dmitry@dmitrygolovach.com · LinkedIn · GitHub


Next Post
Valid JSON, wrong priority: my first structured output lab