Expand description
Cache breakpoints for Anthropic prompt caching.
§Where to place breakpoints
A cache_control: ephemeral marker tells the server “cache the request
up to and including this block.” Typical strategies:
- Cache system + tools + first user turn. The longest-lived prefix.
Use
CreateMessageRequestBuilder::cache_control_on_system,CreateMessageRequestBuilder::cache_control_on_tools, and eitherCreateMessageRequestBuilder::cache_control_on_last_user(called once before the first send) orContentBlock::text_cachedto mark that user turn at construction time. - Refresh on each turn. For long conversations, place a fresh
ephemeral breakpoint on the most recent user turn each request.
Conversation::with_auto_cache(AutoCacheMode::SystemAndLastUser)does this for you.
TTL choice: the default 5-minute cache is right for nearly all
interactive workloads. "1h" requires the
extended-cache-ttl-2025-04-11 beta header and is meant for batch /
long-running pipelines where the same prefix sees sustained traffic.
Enums§
- Cache
Control - Marks a cache breakpoint on a content block, system prompt, or tool definition.