Mark stable context
Cache only the repeated portion: system rules, immutable documentation, or a long reference. A user question and changing data need to remain separate.
The cache_control marker is a compatible-contract preference. Check support in the selected model catalogue before exposing the optimization.
Reusable context marker
json
{
"model": "anthropic/claude-sonnet-5",
"messages": [{"role": "system", "content": "Stable product context..."}],
"cache_control": {"type": "ephemeral"}
}Invalidate deliberately
- Change the context version when rules or source material change.
- Do not put secrets or short-lived permissions into a reusable block.
- Keep a hash or version of a cacheable source in your own trace.
Verify the effect
Measure latency and usage on comparable requests with the same context.
Do not infer cost from one response: caching depends on model, context size, and request lifetime.