feat(llm): add configurable prompt cache TTL with 1-hour Claude variant#3123
Merged
feat(llm): add configurable prompt cache TTL with 1-hour Claude variant#3123
Conversation
Extends the Claude provider with an optional `prompt_cache_ttl` config
field ("ephemeral" | "1h") that controls Anthropic prompt cache duration.
When set to "1h", the provider injects the
`anthropic-beta: extended-cache-ttl-2025-04-25` header and emits
`CacheTtl::OneHour` in all CacheControl blocks, reducing re-encode
cost for long-running sessions with stable system prompts.
Default behaviour (Ephemeral) is byte-identical to pre-feature output.
Closes #3096
ea1fd76 to
643a0cb
Compare
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
CacheTtlenum (Ephemeral|OneHour) tozeph-llmwith serde support and exhaustive match armsCacheControlwith an optionalttl: Option<CacheTtl>field; omitted on the wire whenNone/Ephemeral— default output is byte-identical to pre-featurebuild_cache_control(ttl)helper used at all cache construction sites incache.rsand replaces the JSON-literal tool hint inmod.rswith a typed pathbeta_header()appendsextended-cache-ttl-2025-04-25when TTL isOneHoursplit_system_into_blockscall sites and bothapply_cache_breakpointcall sites propagate TTLProviderEntry.prompt_cache_ttl: Option<CacheTtl>field wired throughprovider_factory.rs; TOML:prompt_cache_ttl = "ephemeral" | "1h"migrate_claude_provider()— copies"1h", suppresses"ephemeral", idempotent on re-runLLM Serialization Gate
This PR touches
claude/mod.rs,cache.rs,types.rs, andCacheControlserialization. A live API session test with a stable system prompt is required before merge per project rules.Test plan
cargo nextest run --workspace --lib --bins— 8207 passed, 20 skippedcargo clippy --workspace -- -D warnings— cleancargo +nightly fmt --check— cleanprompt_cache_ttl = "1h"in config (required before merge)anthropic-beta: extended-cache-ttl-2025-04-25header appears in debug dumpCloses #3096