Skip to content

fix: Kimi /coding/v1 — api_mode detection, API key fallback, User-Agent header - #9664

Closed
xiaoqiang243 wants to merge 6 commits into
NousResearch:mainfrom
xiaoqiang243:main
Closed

xiaoqiang243 wants to merge 6 commits into
NousResearch:mainfrom
xiaoqiang243:main

Conversation

@xiaoqiang243

Copy link
Copy Markdown

Summary

Adds User-Agent claude-code/0.1.0 header for Kimi /coding endpoint requests.

Problem

Kimi's /coding/v1/messages endpoint returns 403 unless the User-Agent header is set to claude-code/0.1.0. The existing _requires_bearer_auth() check matches api.kimi.com/coding before our User-Agent injection code is reached, causing kimi-2.5 and kimi-for-coding models to fail with 404/403 errors.

Solution

  • Add _is_kimi_coding_endpoint() function to detect Kimi coding API base URLs
  • Place Kimi check BEFORE _requires_bearer_auth() in build_anthropic_client() so the User-Agent header is correctly injected
  • kimi-2.5, kimi-for-coding, and kimi-k2.6-code-preview all verified working via SDK

Testing

All three Kimi coding models tested and confirmed working:

  • kimi-2.5: ~0.9s response
  • kimi-for-coding: ~1.0s response
  • kimi-k2.6-code-preview: ~1.7s response

王强 added 2 commits April 14, 2026 21:00
- 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
@xiaoqiang243 xiaoqiang243 changed the title fix: add User-Agent claude-code/0.1.0 for Kimi /coding endpoint fix: Kimi /coding/v1 — auto-detect anthropic_messages + User-Agent header Apr 18, 2026
@xiaoqiang243 xiaoqiang243 changed the title fix: Kimi /coding/v1 — auto-detect anthropic_messages + User-Agent header fix: Kimi /coding/v1 — api_mode detection, API key fallback, User-Agent header Apr 18, 2026
@teknium1

Copy link
Copy Markdown
Collaborator

Merged via #13782 — your commits were cherry-picked onto current main with your authorship preserved in git log (commits de181df, fd40385, bad5471, 46d6801, 2a026eb, 6caf8bd).

Thanks for the fix @xiaoqiang243! I added two follow-up commits on top:

  • KIMI_CODE_BASE_URL needed to drop its /v1 suffix — the Anthropic SDK appends /v1/messages internally, so /coding/v1 + SDK suffix produced /coding/v1/v1/messages (404). Using /coding yields the correct /coding/v1/messages.
  • Preserved the kimi-coding default inference_base_url as api.moonshot.ai/v1 so legacy Moonshot keys still authenticate — only sk-kimi- prefixed keys get redirected (via the existing _resolve_kimi_base_url).

E2E verified both sk-kimi- and legacy sk- paths with real imports and httpx MockTransport.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard provider/kimi Kimi / Moonshot labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown

Likely superseded by #13782 (merged) — same Kimi Coding endpoint fix with broader scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists provider/kimi Kimi / Moonshot type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants