feat(model): enable Anthropic prompt caching by default#404
Merged
Conversation
Add cache_control_injection_points to every Anthropic model_list entry
LiteLLM emits (both the anthropic/* wildcard and explicit per-model
entries). Pinning the system message as the cache breakpoint makes
LiteLLM auto-attach cache_control: {type: ephemeral} on every request
to an Anthropic upstream, the canonical "prompt caching by default"
pattern. Non-anthropic providers (openai, ollama, custom) are
unaffected.
https://claude.ai/code/session_012FTDF8ofWWCLwU8GEN2SFh
OisinKyne
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cache_control_injection_points: [{location: message, role: system}]to every Anthropicmodel_listentry LiteLLM emits — both theanthropic/*wildcard and explicit per-model entries.cache_control: {type: ephemeral}on the system message of every request to those entries, the canonical "prompt caching by default" pattern.openai,ollama,custom) are intentionally untouched —cache_controlis Anthropic-specific and thepaid/*route proxies to arbitrary upstreams via the buyer sidecar.Why
Token cost on Anthropic models is dominated by repeated system / tool / RAG prefixes. Enabling prompt caching by default cuts that cost without any per-call changes on the agent or skill side. Closes a parity gap with Franklin (which advertises Anthropic prompt caching enabled by default).
Test plan
go build ./...go test ./internal/model/TestBuildModelEntries:anthropic_entries_inject_system-message_cache_breakpoint— both wildcard and explicit anthropic entries carry exactly one{Location: "message", Role: "system"}injection point.non-anthropic_entries_do_not_inject_cache_control— openai and ollama entries have emptyCacheControlInjectionPoints.obol model setup anthropicthenkubectl get configmap litellm-config -n llm -o jsonpath='{.data.config\.yaml}'— entries foranthropic/*and any explicit claude models should showcache_control_injection_points.https://claude.ai/code/session_012FTDF8ofWWCLwU8GEN2SFh
Generated by Claude Code