A change invalidates its own level of the prompt and every level after it, in the order tools, system, messages. Changing a tool definition invalidates everything, while changing tool_choice or adding an image invalidates only the message blocks.
The invalidation order
The cache is a prefix match over tools, then system, then messages. Changing tool definitions, including their order, invalidates all three. Toggling web search or citations, or changing the speed setting, keeps the tools cache but invalidates system and messages. Changing tool_choice or adding or removing images keeps tools and system cached and invalidates only messages.
Thinking and effort settings always invalidate message blocks. Whether they also invalidate the tools and system cache depends on the model.
Common silent causes
A timestamp or request ID interpolated into the system prompt changes the prefix on every call, so each request writes a new entry and never reads one. Move that value into the first user message, after the breakpoint.
A tools array built by iterating a hash map can arrive in a different order after a restart, or with schema keys in a different order. Send the same tools in a fixed order and serialize schemas with sorted keys.
Rebuilding messages from a database can re-serialize earlier assistant turns or tool_result blocks slightly differently. Treat history as append-only and send earlier content back exactly as it came.
Finding the cause with cache diagnostics
Include a diagnostics object on every request, with previous_message_id set to null on the first turn and to the previous response id after that. The response then reports a cache_miss_reason such as system_changed, tools_changed or messages_changed, naming the first point where the two requests diverged. previous_message_not_found is not evidence your prompt changed. It usually means the earlier request did not include the diagnostics object. Diagnostics reports the earliest divergence only, so fix that one first.
Where the exam catches people
Believing a tool_choice flip rebuilds the whole cache: tools and system stay cached and only messages are invalidated.
Believing reordering tools is harmless: tools come first in the prefix, so any change there invalidates the entire cache.
Believing a longer TTL fixes a timestamp in the system prompt: the prefix differs on every request, so no TTL helps.
Believing cache diagnostics needs a beta header: the diagnostics object is the opt-in, and the old header is no longer required.