Repository navigation
feat(litellm): pass-through cache_control_injection_points for Anthropic prompt caching - #2610
Conversation
…pic prompt caching Expose LiteLLM's cache_control_injection_points kwarg via the [litellm] section of configuration.toml / .pr_agent.toml, enabling Anthropic prompt caching for self-hosted PR-Agent setups. LiteLLM supports the kwarg natively (https://docs.litellm.ai/docs/tutorials/prompt_caching); PR-Agent did not surface it. Backwards compatible: the default is an empty list, so an absent/empty setting keeps current behavior (no caching). The value is accepted as a native TOML array (Dynaconf yields a Python list) or, for env-var overrides, a JSON string. It is validated in a helper invoked before chat_completion's retry-wrapped body, so a malformed value raises a ValueError config error immediately instead of being wrapped as openai.APIError and retried. Assignment uses setdefault to avoid overwriting a value already in kwargs. Co-authored-by: Mongol Agent <mongol@chifat.ru>
PR Summary by QodoExpose LiteLLM cache_control_injection_points for Anthropic prompt caching
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. Entries not validated
|
… models Address Qodo review on #2610: - _resolve_cache_control_injection_points() only short-circuits on genuinely unset/disabled values (None, "", []); other falsy-but-malformed values (0, False, {}) now fall through to type validation and raise ValueError, per the method's documented contract. - cache_control_injection_points is Anthropic-specific, so injection is gated on Claude models (Anthropic API, Bedrock, Vertex) to avoid passing an unsupported param to other providers when litellm.drop_params is off, mirroring the nearby user-field gating. A debug line is logged when configured but skipped. Tests extended: falsy-malformed values rejected; kwarg not injected for a non-Anthropic model.
|
Code review by qodo was updated up to the latest commit fcc8fec |
Supersedes #2405 (the original PR's branch is on an archived, read-only fork and can no longer be rebased/pushed to). Rebased onto current
main, with all Qodo findings addressed. Original author credited viaCo-authored-by.Summary
Exposes LiteLLM's
cache_control_injection_pointskwarg via the[litellm]section ofconfiguration.toml/.pr_agent.toml, enabling Anthropic prompt caching for self-hosted setups. Backwards compatible — the default is an empty list, so an absent/empty setting keeps current behavior (no caching).Usage
Qodo findings addressed
TypeErroron the natural config spelling — a TOML array is parsed by Dynaconf into a native Python list, andjson.loads(list)used to crash. The value is now accepted as a native list directly, with a JSON-string fallback for environment-variable overrides.chat_completion's retry-wrapped body, so a malformed value raises aValueErrorconfig error immediately instead of being wrapped asopenai.APIErrorand retried.kwargsoverwrite — assignment useskwargs.setdefault(...)to guard against clobbering an existing value.cache_control_injection_points = []) rather than commented example lines.Tests
New
tests/unittest/test_litellm_cache_control_injection_points.py(8 cases: native list, JSON string, absent/empty backwards-compat, invalid JSON not retried, non-list rejected). Full unit suite passes (1720 passed).Co-authored-by: Mongol Agent mongol@chifat.ru