Prompt & Done · CACHEIT

Why Claude's second answer costs less (and how to keep it that way)

I sent Claude Sonnet 5.5 the same ~20-page document (26,979 tokens) three times. Send 1: $0.109. Send 2, same document: $0.007. Send 3, one word changed in the first line: $0.109 again. Costs are API list prices computed from the usage the API returned.

Tested 7 Nov 2026. Prices and cache rules checked the same night on platform.claude.com (pricing + prompt caching docs).

1 The 3-line rule

  1. Stable stuff first: instructions, tool list, long documents, examples. Never put a timestamp, a user name or a random ID up top.
  2. Changing stuff last: the new question, today's date, per-user details go after the cached part.
  3. Don't edit the top: one changed byte early in the prompt and everything after it is read fresh (that's my send 3).

2 Run my test yourself

With Claude Code installed (it calls the API with caching on and prints the raw usage):

Q="In one sentence: what is this document about?"
claude -p "$Q" --system-prompt-file doc.md --tools "" --model sonnet --no-session-persistence --output-format json > run1.json
claude -p "$Q" --system-prompt-file doc.md --tools "" --model sonnet --no-session-persistence --output-format json > run2.json
# change one word in the first line of doc.md, save as doc-changed.md
claude -p "$Q" --system-prompt-file doc-changed.md --tools "" --model sonnet --no-session-persistence --output-format json > run3.json

In each file read usage.cache_creation_input_tokens (written to the cache), usage.cache_read_input_tokens (read from it) and usage.input_tokens (not cached). Use any document of 512+ tokens (the minimum Sonnet 5.5 caches).

On the API directly: add cache_control: {"type": "ephemeral"} at the top level of the request (or on the last block you want cached) and compare the same fields.

3 The numbers (Claude Sonnet 5.5, per million tokens)

Input $2 · cache write $2.50 (5-minute) or $4 (1-hour) · cache read $0.10 · output $10. The cache lives 5 minutes by default and every hit refreshes it; Claude Code writes 1-hour entries.

My sends: 1) 26,979 written + 117 out = $0.109 · 2) 26,314 read + 663 written + 165 out = $0.0069 · 3) 26,977 written + 116 out = $0.109.

platform.claude.com: pricing · platform.claude.com: prompt caching