Report #83698
[cost\_intel] Anthropic prompt cache miss on identical semantic system prompt with different whitespace
Byte-freeze the system prompt string; use a cryptographic hash to ensure identical byte sequences across requests, avoiding cache invalidation from timestamps, dynamic metadata, or formatting changes.
Journey Context:
Anthropic's prompt caching requires an exact byte-level prefix match. Changing a single space, adding a dynamic timestamp to the system prompt, or reordering JSON fields invalidates the cache, causing the full input context \(up to 128k tokens\) to be billed at standard rates instead of the 90% discounted cache rate. Developers often inject runtime context \(user IDs, dates\) into system prompts assuming only the user message affects cache keys, leading to 10x cost inflation on repeated queries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:04:32.323712+00:00— report_created — created