fix: fallback header preservation, kimi credential pool, TUI stale model display - #6754
Merged
Conversation
…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 #6075
…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 #5561
…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>
The status bar reads self.model from the CLI class, which is set once at init and never updated when _try_activate_fallback() switches to a backup provider/model in run_agent.py. This causes the TUI to display the original model name while context_length_max changes, creating a confusing mismatch. Read the model name from agent.model (live, updated by fallback) with self.model as fallback before the agent is created. Remove the redundant getattr(self, 'agent') call that was already done above.
This was referenced Apr 9, 2026
Closed
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
Salvage of PRs #6076, #6399 by @SeeYangZhi (PR #5797 superseded by #6076).
Three related fallback fixes:
1. Fallback drops provider-specific headers (from #6076)
_try_activate_fallback()saved_client_kwargswith onlyapi_keyandbase_url, droppingdefault_headers. Every subsequent API call via_create_request_openai_client()rebuilt a headerless client, causing 403s from providers like Kimi that requireUser-Agent: KimiCLI/x.x.Fix: Extract
_custom_headersfrom the fallback client and include them in_client_kwargs.2. Auxiliary client custom endpoint missing headers (from #6076/#5797)
resolve_provider_client()created bareOpenAI()clients in the custom endpoint branch without header injection. Also bumps all KimiCLI version strings from 1.0 to 1.3. Adds kimi-coding base_url resolution in credential pool seeding.3. TUI status bar shows stale model after fallback (from #6399)
_get_status_bar_snapshot()readself.model(CLI instance, set at init) instead ofagent.model(updated live by fallback). Fix: readagent.modelfirst, fall back toself.model.Files changed
run_agent.py— preserve fallback client headers in_client_kwargsagent/auxiliary_client.py— KimiCLI 1.0→1.3, header injection in custom endpoint branchagent/credential_pool.py— kimi-coding base_url resolution in pool seedinghermes_cli/auth.py— comment fix (platform.kimi.ai → kimi.com/code)cli.py— status bar reads live agent.modelTest results
TestCLIUsageReportmock gap)Attribution
All commits cherry-picked from @SeeYangZhi with original authorship preserved.