fix(credential-pool): resolve kimi-coding base URL from API key prefix - #7554
Closed
victorGPT wants to merge 1 commit into
Closed
fix(credential-pool): resolve kimi-coding base URL from API key prefix#7554victorGPT wants to merge 1 commit into
victorGPT wants to merge 1 commit into
Conversation
…x in _seed_from_env _seed_from_env() had a special case for zai provider to resolve the correct base URL based on the API key, but kimi-coding was missing the same treatment. This caused sk-kimi- prefixed keys (from platform.kimi.ai subscriptions) to always route to api.moonshot.ai/v1 instead of api.kimi.com/coding/v1, resulting in HTTP 400 errors. Also strip terminal escape sequences (ESC[B, etc.) from env var tokens before persisting to the credential pool. Pasted API keys can pick up invisible control characters that break prefix detection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Thanks for the contribution, @victorGPT! This fix was already merged to Automated hermes-sweeper review found:
The escape-sequence stripping of env var tokens (the bonus item) is not yet on |
2 tasks
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.
What does this PR do?
_seed_from_env()resolves provider-specific base URLs when seeding the credential pool from environment variables. It already handles thezaiprovider via_resolve_zai_base_url(), butkimi-codingwas missing the equivalent_resolve_kimi_base_url()call. This causedsk-kimi-prefixed API keys (issued by platform.kimi.ai subscriptions) to always route toapi.moonshot.ai/v1instead of the correctapi.kimi.com/coding/v1, resulting in persistent HTTP 400 errors.Additionally, pasted API keys can pick up invisible terminal escape sequences (e.g.
ESC[B,ESC+TAB) that get persisted into the credential pool, breaking thestartswith("sk-kimi-")prefix detection. This PR strips such sequences before persisting tokens.Related Issue
No existing issue — discovered during debugging of Kimi subscription key routing failures.
Type of Change
Changes Made
agent/credential_pool.py: Added_resolve_kimi_base_urlimport fromhermes_cli.authagent/credential_pool.py: Addedkimi-codingbranch in_seed_from_env()alongside existingzaihandling (line ~1090)agent/credential_pool.py: Strip terminal escape sequences from env var tokens before use (line ~1081)How to Test
KIMI_API_KEYto ask-kimi-prefixed keyhermeswithkimi-codingprovider andkimi-k2.5modelhttps://api.kimi.com/coding/v1(notapi.moonshot.ai/v1)~/.hermes/auth.jsoncredential pool entry has the correctbase_urlBonus (escape sequence test):
KIMI_API_KEYto a value with leading escape chars:export KIMI_API_KEY=$'\x1b[Bsk-kimi-testkey'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/A