fix(agent): reapply provider headers after model switch (#61099) - #61347
Closed
AlexFucuson9 wants to merge 1 commit into
Closed
fix(agent): reapply provider headers after model switch (#61099)#61347AlexFucuson9 wants to merge 1 commit into
AlexFucuson9 wants to merge 1 commit into
Conversation
switch_model() rebuilds _client_kwargs from scratch (api_key + base_url) but does not call _apply_client_headers_for_base_url(), so provider- specific headers like OpenRouter HTTP-Referer and X-Title are lost. Subsequent requests show "Unknown" in OpenRouter dashboard logs. Call _apply_client_headers_for_base_url() after rebuilding _client_kwargs and before creating the new client. Fixes NousResearch#61099
teknium1
added a commit
that referenced
this pull request
Jul 10, 2026
teknium1
added a commit
that referenced
this pull request
Jul 10, 2026
Contributor
|
Salvaged and merged in #61732 (rebase-merge — your commit landed on main with full authorship). Root cause was exactly as you diagnosed: switch_model() was the one client-rebuild site that skipped _apply_client_headers_for_base_url(). We added 3 regression tests on top (OpenRouter attribution, Kimi User-Agent sentinel, stale-header clearing) — 2 of 3 fail on the unpatched code, confirming the bug live. Thanks @AlexFucuson9! |
santhreal
pushed a commit
to santhreal/hermes-agent
that referenced
this pull request
Jul 13, 2026
justemu
pushed a commit
to justemu/hermes-agent
that referenced
this pull request
Jul 18, 2026
Gravezzz
pushed a commit
to Gravezzz/hermes-agent
that referenced
this pull request
Jul 21, 2026
leewenjie
pushed a commit
to leewenjie/hermes-agent
that referenced
this pull request
Aug 7, 2026
randlee
pushed a commit
to randlee/hermes-agent
that referenced
this pull request
Aug 11, 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.
Summary
switch_model()inagent/agent_runtime_helpers.pyrebuilds_client_kwargsfrom scratch (onlyapi_key+base_url) but does not call_apply_client_headers_for_base_url(). This drops provider-specific HTTP headers like OpenRouter'sHTTP-RefererandX-Title, causing subsequent requests to show "Unknown" in OpenRouter dashboard logs.Fixes #61099
Root Cause
In
switch_model()(line ~1903),_client_kwargsis rebuilt:But
_apply_client_headers_for_base_url(effective_base)is never called, so headers like:{"HTTP-Referer": "https://hermes-agent.nousresearch.com", "X-Title": "Hermes Agent"}are lost. The client is then created without attribution headers.
During initial agent setup (
__init__),_apply_client_headers_for_base_urlIS called. But after any/modelswitch, the headers are gone.Fix
Add
agent._apply_client_headers_for_base_url(effective_base)after rebuilding_client_kwargsand before_create_openai_client().Impact