fix(custom provider): enable prompt caching and accurate context window for custom endpoints serving Claude#50946
Open
Xiaochengzi2048 wants to merge 2 commits into
Conversation
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.
Problem
Two related issues affect users running Claude through a custom OpenAI-compatible endpoint (LiteLLM, Bedrock proxies, local gateways):
1. Prompt caching disabled
anthropic_prompt_cache_policy()returns(False, False)forprovider=custom, even when the model name clearly identifies it as Claude. Every request re-bills the full prompt with no cache hits.2. Context window reported as 200k
lookup_models_dev_context()returnsNoneforprovider=custom(not inPROVIDER_TO_MODELS_DEV), so hermes falls back to the 200k default. Claude Opus 4 users see 200k instead of the real 1M window.Both issues share the same root cause: hermes does not recognise
customas a provider with known model metadata.Fix
agent/agent_runtime_helpers.py
Add a branch for
provider=custom + is_claudethat enables caching with envelope layout (same as the existing openrouter branch):agent/models_dev.py
When
provider=customhas no mapping, fall back to the canonical provider based on model name:This gives Claude Opus 4 its real 1M context window and Sonnet its real 200k — instead of both hitting the 200k fallback.
Related
Closes #50939 (skill delete PermissionError is a separate issue, already in #50940).