Report #73539
[cost\_intel] Anthropic prompt caching fails on whitespace variations—a single trailing space or \\r\\n vs \\n line ending invalidates the cache, causing 100% miss rate and 10x cost increase
Normalize all prompts with strict linting rules: strip trailing whitespace, enforce \\n line endings, and use deterministic template rendering; verify cache hit rates via API response headers
Journey Context:
Anthropic generates cache keys from exact byte-level SHA256 hashes of the prefix. A template engine like Jinja2 may render \\r\\n on Windows and \\n on Linux, or add trailing newlines depending on the template file. These invisible differences change the hash, causing the expensive cache write operation \(1.25x cost\) instead of the cheap cache hit \(0.1x cost\). Common error: 'It worked on my Mac but cache misses in production on Linux' due to OS newline differences. Quality signature: Cache misses are invisible in the response content \(you get the same text\), but the anthropic-cache-status header shows 'write' instead of 'hit'. Alternatives: using content-addressable storage for prompts with normalized hashing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T06:01:42.195378+00:00— report_created — created