fix(agent): enable prompt caching for LiteLLM OpenAI-compatible wire (#84506) - #84550
Closed
Enough1122 wants to merge 2 commits into
Closed
Enough1122 wants to merge 2 commits into
Enough1122 wants to merge 2 commits into
Conversation
…n unrelated hosts (NousResearch#84506) The LiteLLM detection granted cache_control when 'litellm' appeared anywhere in the full base URL, including a path segment on an unrelated host (e.g. https://api.corp.example.com/v1/litellm-failover). A strict OpenAI-wire host that rejects unknown keys would then fail with HTTP 400. Switch to base_url_hostname so only a 'litellm' substring in the actual host grants the marker, matching how every other host check in this function works (OpenRouter/MiniMax/Anthropic). Added a regression test for the path-segment false positive. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Enough1122
force-pushed
the
fix/84506-litellm-prompt-caching
branch
from
August 13, 2026 07:26
d3e6881 to
c60f7b6
Compare
This was referenced Aug 14, 2026
Author
This was referenced Aug 16, 2026
Merged
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.
Fixes #84506
Root cause
anthropic_prompt_cache_policy()granted Anthropiccache_controlmarkers only on the native Anthropic wire (api_mode == "anthropic_messages"). LiteLLM deployments exposing the OpenAI-compatible surface (/v1/chat/completions) matched no branch → fell through to(False, False)→ zero cache hits, full prompt re-billed every turn.Fix
Detect LiteLLM by provider id substring (
custom:litellm,litellm) or base-URL host substring (litellm), combined with Claude model detection: grant cache_control on the OpenAI-compatible wire exactly like OpenRouter. Anthropic-wire LiteLLM keeps the existing(True, True)behavior; non-Claude models on LiteLLM stay uncached.Tests
custom:litellm→ (True, False); barelitellm→ (True, False); barecustom+ litellm host → (True, False); LiteLLM on anthropic wire → (True, True); non-Claude on LiteLLM → (False, False)tests/run_agent/test_anthropic_prompt_cache_policy.py: 39/39 passanthropicpackage in shared venv; fail identically with changes stashed)