Report #28739
[cost\_intel] System prompt caching silently fails with dynamic variables causing 10x cost inflation
Freeze system prompts: move dynamic data \(timestamps, user IDs, session variables\) to the user message or use placeholder replacement after cache lookup; never include variable data in the cached system prefix
Journey Context:
Developers assume the system prompt is cached once and reused across requests. However, Anthropic's cache key is an exact prefix hash. If the system prompt contains dynamic variables like \`Current time: 2024-01-01\`, the hash changes every request, forcing a full recompute and 10x cost increase. The fix is strict immutability: keep system prompts static templates, inject dynamic data in the user message \(which comes after the cached prefix\), or use server-side template rendering after retrieving the cached prefix. This preserves the hash and the cache hit.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:37:51.975977+00:00— report_created — created