Prompt caching reuses the processed state of the start of a prompt that is shared across multiple requests. This shared start is called the prefix. OpenAI explains that the state stored for a matching prefix can be used in a subsequent request. New input that comes after the prefix is processed normally.
Anthropic lists prompts with many examples, large context, repeated tasks with consistent instructions, and long multi-turn conversations among the cases where prompt caching can be useful. What these cases have in common is content that can be reused in later requests.
What is reused?
According to OpenAI, while processing input tokens the model computes intermediate states called key-value (KV) states. These states let the model refer to earlier tokens when processing later input and generating output tokens. The prompt cache stores these KV states rather than the original prompt text.
When a matching cache entry is found, the model can use the stored state instead of reprocessing the prefix covered by that entry. The portion of the new request that follows the prefix still has to be processed separately. A cache hit does not mean the entire request is served from a previously generated response.
OpenAI notes that the prefix presented to the model can include parts such as developer instructions, tool definitions, and conversation history. For this reason, matching is not only about the latest user message. Earlier content and the order in which it is presented to the model are also part of the shared start.
What does a cache breakpoint determine?
A cache breakpoint marks the point where the prefix that can be written to the cache ends. In Anthropic's Messages API approach, cache_control can be added at the top level of the request or placed on specific content blocks. The top-level field enables automatic caching. The block-level marker creates an explicit cache breakpoint.
Automatic caching applies the breakpoint to the last block that can be cached. As the conversation grows, the point moves forward in subsequent requests. Content up to and including the last marked block is part of the prefix. When a later request contains the same prefix, the cached content can be reused.
An explicit breakpoint gives finer control over which section is cached. Anthropic says this approach is useful when sections that change at different frequencies need to be cached. For example, you can use an explicit breakpoint for the system prompt while using automatic caching for the conversation.
Anthropic describes placing static tool definitions, system instructions, context, and examples at the start of the prompt. The end of the content to be reused is marked with cache_control. The prefix order is tools first, then system, then messages. Each level builds on the content before it.
A breakpoint does not cover only the marked block. All content up to that point, including the marked block, becomes part of the prefix. The position of the breakpoint therefore also determines which content must stay the same in the next request.
How is a match found?
According to Anthropic, the cache write happens at the breakpoint. For a block marked with cache_control, an entry is written that carries the hash of the prefix ending at that block. The same operation does not create a separate entry for each earlier block. If any block at or before the breakpoint changes, the hash computed in the next request changes as well.
During a cache read, the system first looks for a matching entry for the prefix at the current breakpoint. If there is no match, it moves backward through earlier blocks and looks for entries written by previous requests. This lookup does not write static content to the cache by itself; it only searches for an entry that was written earlier.
In Anthropic's example, static system content is followed by a block that changes with every request. If the breakpoint is at the end of the changing block, the written prefix includes that block too. When the block changes in the next request, the prefix hash changes. If no separate entry was written at the end of the earlier static blocks, the backward lookup finds no entry for those blocks.
In the same example, the breakpoint is moved to the end of the static section. Subsequent requests can then read the shared prefix. For prompts with a static prefix and a changing final section, Anthropic recommends placing the breakpoint on the last block that stays the same across requests. Request-specific context and the incoming user message are examples of the changing final section.