Datadog Troubleshooting Prompt Cache Misses: Four Silent Code-Level Traps
Datadog engineers documented the troubleshooting process of locating individual request discrepancies from aggregate cost anomalies, discovering four specific causes—Go map iteration order, missing request body control parameters, unpassed SDK options, and API route incompatibility—that prevented prompt caching from actually taking effect despite appearing enabled.
The AI applications team at Datadog encountered a counterintuitive phenomenon while investigating LLM costs: multiple internal applications had enabled prompt caching options, yet there were zero cache hits in actual requests. Each request contained over 180,000 input tokens, with single-request costs ranging from $0.74 to $0.82. Once caching took effect, the cost for the same task could drop to between $0.02 and $0.14. The gap was so significant that finding the cause seemed impossible.
Staff Engineer Bruno Volpato and his team recorded the complete troubleshooting process. Their methodology was to first use Cloud Cost Management to view overall spending, then use Agent Observability to trace down to individual model calls, and finally compare the differences between the first call and subsequent calls within the same task. An agent might call the model multiple times to complete one task, repeating system instructions, tool definitions, and conversation history each time. If caching worked correctly, subsequent calls should read these repeated contents from the cache.
The investigation revealed four categories of silent failure modes. The first category involved mutable content mixed into reusable prefixes. A chat service concatenated system instructions with current time, organization details, feature flags, and incident context. Prompt caching relies on byte-by-byte matching of request prefixes—if a timestamp appears before the instructions, even if the subsequent instructions are identical, the cache cannot hit. Their fix was to place stable instructions first and request-specific details last, using cache boundary markers to denote the end of the reusable portion where supported.