Repository navigation
feat(provider): add kimi_coding provider for Kimi Coding Plan - #4464
Conversation
Kimi Coding's Anthropic-compatible streaming endpoint reuses the same short tool_use id (e.g. grep:3) across multiple parallel tool_use blocks. The old code forwarded these duplicated ids into LLMResponse.tool_calls, which then flowed back into the next request's tool_result messages, triggering Kimi's invalid_request_error: tool call id ... is duplicated. OpenAICompatProvider already had identical deduplication, but AnthropicProvider did not. Apply the same fix here. Also refactor usage cache token writes to use precomputed cache_creation / cache_read variables instead of repeated getattr(..., 0) or 0 calls. Relates-to: HKUDS#4463 Relates-to: HKUDS#4464
chengyongru
left a comment
There was a problem hiding this comment.
Automated PR review by nanobot. This is not a human maintainer review or approval.
Side-effect analysis for adding the Kimi Coding Plan provider:
-
Schema and registry registration —
kimi_codingis added as a newProviderConfigfield withdefault_factory=ProviderConfig, so existing configs without akimiCodingblock are unaffected. The provider spec usesbackend="anthropic", routing requests throughAnthropicProvider. -
Separate env key — Uses
KIMI_CODING_API_KEYinstead ofMOONSHOT_API_KEY, correctly separating the two Kimi/Moonshot platforms (Anthropic Messages API vs OpenAI-compatible). No collision risk. -
User-Agent requirement — The endpoint requires
extraHeaders.User-Agentset to a Claude-compatible value (e.g.claude-code/0.1.0) to avoid HTTP 403. This is left to user configuration rather than hardcoded, which is consistent with how other providers handleextraHeaders. Worth noting in docs that this header is effectively mandatory, not optional. -
Parallel tool call dedup — Since this provider uses the Anthropic backend, the tool_use ID dedup from #4474 applies here. Without #4474 merged, Kimi's parallel tool calls may still collide. The two PRs are complementary but not hard-dependent.
-
README news entries — The diff removes two recent news entries (v0.2.2 release and 2026-06-21 SDK entry) and moves two older entries into the visible section. This appears to be a branch divergence artifact. These README changes should be reconciled with current main before merge.
No blocking concerns on the provider code itself. The README diff may need rebasing.
| # Kimi Coding Plan — Anthropic Messages API at api.kimi.com/coding | ||
| # sk-kimi-* keys; requires User-Agent: claude-code/0.1.0 header. | ||
| ProviderSpec( | ||
| name="kimi_coding", |
There was a problem hiding this comment.
The User-Agent header is effectively mandatory for this endpoint (403 without it). Consider documenting it as required rather than optional, since users who skip it will hit a confusing 403.
059ea84 to
9c71f29
Compare
Add a dedicated provider entry for the Kimi Coding Plan endpoint (api.kimi.com/coding) using the Anthropic Messages API transport. - Register kimi_coding with backend=anthropic - Use KIMI_CODING_API_KEY env key to avoid clashing with MOONSHOT_API_KEY - Default api_base set to https://api.kimi.com/coding/v1 so that AnthropicProvider._normalize_base_url() + the SDK produce the correct /coding/v1/messages request path - Keywords include kimi-coding, kimi_coding and kimi-for-coding Closes HKUDS#4463
Maintainer edit: add the provider reference row and a pasteable cookbook recipe so users know to select kimi_coding and set the required User-Agent header.
9c71f29 to
f055c0c
Compare
Re-bin
left a comment
There was a problem hiding this comment.
LGTM. This adds Kimi Coding as a dedicated Anthropic-backend provider with separate credentials from Moonshot/Kimi, clear configuration docs, and CI coverage.
I also pushed a small follow-up so the required Claude-compatible User-Agent is declared as provider metadata and applied by the factory by default. That keeps WebUI key-only configuration usable while still allowing users to override providers.kimiCoding.extraHeaders.User-Agent when needed.
Summary
Add a dedicated
kimi_codingprovider for Kimi Coding Plan's Anthropic Messages API endpoint.Changes
kimi_codingwith the Anthropic backend and default base URLhttps://api.kimi.com/coding/v1.providers.kimiCodingconfig support with a separateKIMI_CODING_API_KEY, so it does not collide with Moonshot/Kimi's OpenAI-compatible provider.User-Agentby default, while userextraHeaderscan still override it.Usage
{ "providers": { "kimiCoding": { "apiKey": "${KIMI_CODING_API_KEY}" } }, "modelPresets": { "kimiCoding": { "provider": "kimi_coding", "model": "kimi-for-coding" } }, "agents": { "defaults": { "modelPreset": "kimiCoding" } } }If your Kimi account requires a different Claude-compatible User-Agent, override it with
providers.kimiCoding.extraHeaders.User-Agent.Closes #4463