fix(agent): honor explicit api_mode on fallback chain entries - #80209
Open
kuziTony wants to merge 1 commit into
Open
fix(agent): honor explicit api_mode on fallback chain entries#80209kuziTony wants to merge 1 commit into
kuziTony wants to merge 1 commit into
Conversation
Fallback activation re-derived the wire protocol from provider name /
base URL / model and ignored an `api_mode` the user had declared on the
chain entry, so a fallback could silently come up on a different protocol
than the one configured.
The primary path already honors an explicit value via
`runtime_provider._parse_api_mode`; the fallback path had no equivalent.
`_iter_fallback_entries` already passes the whole entry through, so the
field was present in `fb` all along -- just never read.
Concretely, a self-hosted OpenAI-compatible gateway fronting Claude:
fallback_providers:
- provider: custom
model: claude-opus-4
base_url: http://gateway.internal:3000/v1
api_mode: anthropic_messages
matches none of the anthropic detection branches (provider is not
`anthropic`, the URL neither ends in `/anthropic` nor resolves to
`api.anthropic.com`), so inference fell through to `chat_completions`.
Requests then went out over `/chat/completions`, which drops the
`cache_control` blocks the Anthropic path attaches -- zeroing prompt
caching for the rest of the conversation with nothing logged.
Observed on a self-hosted gateway: once traffic shifted to the fallback,
`session_model_usage` recorded 77 calls with cache_read_tokens = 0, while
the primary model on the same endpoint logged 274 calls / 18.4M
cache_read_tokens.
Reuses `_parse_api_mode` for validation, so invalid or absent values fall
through to the existing inference chain unchanged. Hostname detection
added in NousResearch#32243 / NousResearch#49247 keeps working.
This was referenced Aug 6, 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.
Fallback activation re-derived the wire protocol from provider name / base URL / model and ignored an
api_modethe user had declared on the chain entry, so a fallback could silently come up on a different protocol than the one configured.The primary path already honors an explicit value via
runtime_provider._parse_api_mode; the fallback path had no equivalent._iter_fallback_entriesalready passes the whole entry through, so the field was present infball along -- just never read.Concretely, a self-hosted OpenAI-compatible gateway fronting Claude:
matches none of the anthropic detection branches (provider is not
anthropic, the URL neither ends in/anthropicnor resolves toapi.anthropic.com), so inference fell through tochat_completions. Requests then went out over/chat/completions, which drops thecache_controlblocks the Anthropic path attaches -- zeroing prompt caching for the rest of the conversation with nothing logged.Observed on a self-hosted gateway: once traffic shifted to the fallback,
session_model_usagerecorded 77 calls with cache_read_tokens = 0, while the primary model on the same endpoint logged 274 calls / 18.4M cache_read_tokens.Reuses
_parse_api_modefor validation, so invalid or absent values fall through to the existing inference chain unchanged. Hostname detection added in #32243 / #49247 keeps working.What does this PR do?
Related Issue
Fixes #
Type of Change
Changes Made
How to Test
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
hermes --toolsets skills -q "Use the X skill to do Y"Screenshots / Logs