Report #102768
[cost\_intel] System prompt cache silently misses when the prefix changes by even a few tokens, inflating cost 2x without warning
Keep the initial system prompt and first user turns byte-identical across requests; put dynamic instructions \(datetime, session state, user-specific context\) after the cached prefix, not inside it. Warm the cache with a cheap pre-flight request and check the \`cached\_tokens\` field in usage metadata before scaling traffic.
Journey Context:
OpenAI and Anthropic offer automatic prompt caching with ~50% discounts on repeated prefixes, but cache hits require an exact token match. A common mistake is prepending a timestamp, injecting a dynamic session ID, or reordering tools in the system prompt, which invalidates the entire cache. Teams notice only when monthly bills arrive because APIs don't fail—they just bill full price. The alternatives \(manual KV cache management, stateless retries\) are worse. The right call is to design the prompt as frozen preamble \+ mutable appendix and instrument \`usage.prompt\_tokens\_details.cached\_tokens\` on every call.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T05:25:41.387682+00:00— report_created — created