fix(kimi): make sk-kimi- Kimi Code keys usable natively in Hermes - #13782
Merged
Merged
Conversation
- Add _is_kimi_coding_endpoint() to detect Kimi coding API - Place Kimi check BEFORE _requires_bearer_auth to ensure User-Agent header is set - Without this header, Kimi returns 403 on /coding/v1/messages - Fixes kimi-2.5, kimi-for-coding, kimi-k2.6-code-preview all returning 403
…on for /coding endpoint
Follow-ups after salvaging xiaoqiang243's kimi-for-coding patches: - KIMI_CODE_BASE_URL: drop trailing /v1 (was /coding/v1). The /coding endpoint speaks Anthropic Messages, and the Anthropic SDK appends /v1/messages internally. /coding/v1 + SDK suffix produced /coding/v1/v1/messages (a 404). /coding + SDK suffix now yields /coding/v1/messages correctly. - kimi-coding ProviderConfig: keep legacy default api.moonshot.ai/v1 so non-sk-kimi- moonshot keys still authenticate. sk-kimi- keys are already redirected to api.kimi.com/coding via _resolve_kimi_base_url. - doctor.py: update Kimi UA to claude-code/0.1.0 (was KimiCLI/1.30.0) and rewrite /coding base URLs to /coding/v1 for the /models health check (Anthropic surface has no /models). - test_kimi_env_vars: accept KIMI_CODING_API_KEY as a secondary env var. E2E verified: sk-kimi-<key> → https://api.kimi.com/coding/v1/messages (Anthropic) sk-<legacy> → https://api.moonshot.ai/v1/chat/completions (OpenAI) UA: claude-code/0.1.0, x-api-key: <sk-kimi-*>
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.
Salvages #9664 onto current main, with follow-ups for the Anthropic SDK URL joining semantics.
Summary
sk-kimi-keys from platform.kimi.com now work as a first-class Hermes provider — no more routing through OpenRouter to get Kimi. The/codingendpoint speaks Anthropic Messages, is gated on a 'coding agent' User-Agent, and Hermes now identifies itself correctly.Root cause: Kimi's
/codingendpoint rejects any request whose UA isn't whitelisted (Claude Code, Kimi CLI, Roo Code, etc.) with "Kimi For Coding is currently only available for Coding Agents". Hermes was sendingKimiCLI/1.30.0against the Moonshot OpenAI-compat endpoint — wrong UA, wrong endpoint, wrong wire protocol.Changes (salvaged from #9664 by @xiaoqiang243)
agent/anthropic_adapter.py: new_is_kimi_coding_endpoint()check runs BEFORE_requires_bearer_auth(); setsdefault_headers={"User-Agent": "claude-code/0.1.0"}agent/auxiliary_client.py,run_agent.py: all 6 Kimi UA sites switchedKimiCLI/1.30.0→claude-code/0.1.0hermes_cli/providers.py,hermes_cli/runtime_provider.py,hermes_cli/model_switch.py,tools/delegate_tool.py: auto-detectanthropic_messagesapi_mode forapi.kimi.com/codingacross 5 resolution pathshermes_cli/auth.py: addKIMI_CODING_API_KEYas secondary env var fallbackFollow-up fixes (mine, on top)
KIMI_CODE_BASE_URL: drop/v1suffix (was/coding/v1). Anthropic SDK appends/v1/messagesviabase_url.raw_path + /v1/messages, so/coding/v1produces/coding/v1/v1/messages(404)./codingproduces/coding/v1/messages(correct).kimi-codingProviderConfig.inference_base_url = api.moonshot.ai/v1— reverts the PR's default change so legacy Moonshot keys still authenticate. Onlysk-kimi-prefixed keys get redirected (via existing_resolve_kimi_base_url).doctor.py: update Kimi UA toclaude-code/0.1.0and rewrite/codingbase URLs to/coding/v1for/modelshealth check.tests/hermes_cli/test_api_key_providers.py::test_kimi_env_vars: accept the newKIMI_CODING_API_KEYfallback.scripts/release.pyAUTHOR_MAP: map @xiaoqiang243's personal email.Validation
sk-kimi-key on Hermesapi.kimi.com/coding/v1/v1/messagesor worseapi.kimi.com/coding/v1/messagesKimiCLI/1.30.0claude-code/0.1.0sk-moonshot keysapi.moonshot.ai/v1preserved)E2E tested with real imports + httpx MockTransport. Targeted tests: 374/374 pass (auxiliary_client, credential_pool, api_key_providers, doctor, overlay_slug_resolution, model_switch_custom_providers, base_url_hostname, provider_parity).
Closes #9664, #8779 (the
_default_headersbug is moot once we're on the correct endpoint with the correct UA).