fix(fallback): preserve provider-specific headers when activating fallback - #6076
Closed
SeeYangZhi wants to merge 3 commits into
Closed
fix(fallback): preserve provider-specific headers when activating fallback#6076SeeYangZhi wants to merge 3 commits into
SeeYangZhi wants to merge 3 commits into
Conversation
…sync clients
When is explicitly set to ,
the custom-endpoint path in creates a plain
client without provider-specific headers. This means sync vision calls (e.g.
) use the generic User-Agent and get rejected by
Kimi's coding endpoint with a 403:
'Kimi For Coding is currently only available for Coding Agents such as Kimi CLI...'
The async converter already injects , and the
auto-detected API-key provider path also injects it, but the explicit custom
endpoint shortcut was missing it entirely.
This patch adds the same injection to the custom endpoint
branch, and updates all existing Kimi header sites to for
consistency.
Fixes <issue number to be filled in>
…ding pool The credential pool seeder (_seed_from_env) hardcoded the base URL for API-key providers without running provider-specific auto-detection. For kimi-coding, this caused sk-kimi- prefixed keys to be seeded with the legacy api.moonshot.ai/v1 endpoint instead of api.kimi.com/coding/v1, resulting in HTTP 401 on the first request. Import and call _resolve_kimi_base_url for kimi-coding so the pool uses the correct endpoint based on the key prefix, matching the runtime credential resolver behavior. Also fix a comment: sk-kimi- keys are issued by kimi.com/code, not platform.kimi.ai. Fixes NousResearch#5561
…lback When _try_activate_fallback() swaps to a new provider (e.g. kimi-coding), resolve_provider_client() correctly injects provider-specific default_headers (like KimiCLI User-Agent) into the returned OpenAI client. However, _client_kwargs was saved with only api_key and base_url, dropping those headers. Every subsequent API call rebuilds the client from _client_kwargs via _create_request_openai_client(), producing a bare OpenAI client without the required headers. Kimi Coding rejects this with 403; Copilot would lose its auth headers similarly. This patch reads _custom_headers from the fallback client (where the OpenAI SDK stores the default_headers kwarg) and includes them in _client_kwargs so any client rebuild preserves provider-specific headers. Fixes NousResearch#6075
This was referenced Apr 9, 2026
Contributor
|
Merged via salvage PR #6754. All three commits cherry-picked onto current main with your authorship preserved in git log. Thank you @SeeYangZhi! |
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
Fixes #6075
When
_try_activate_fallback()swaps to a provider that requires provider-specific HTTP headers (e.g. kimi-coding requiresUser-Agent: KimiCLI/1.x), the returned client fromresolve_provider_client()correctly has the headers baked in. However,_client_kwargswas saved with onlyapi_keyandbase_url, droppingdefault_headers.Every subsequent API call rebuilds the client from
_client_kwargsvia_create_request_openai_client(), producing a bare OpenAI client without the required headers — causing 403s from Kimi Coding and potentially missing auth headers for GitHub Copilot.Changes
The OpenAI SDK stores
default_headerspassed to the constructor inclient._custom_headers, so this correctly round-trips the headers through any client rebuild.Verification
_custom_headers→ passed to new client → headers preservedKimiCLI/1.3in_client_kwargs. Without the fix, turns 2+ fail with 403.Related