Skip to content

feat(provider): add kimi_coding provider for Kimi Coding Plan - #4464

Merged
Re-bin merged 3 commits into
HKUDS:mainfrom
zpljd258:feat/kimi-coding-provider
Jun 24, 2026
Merged

Re-bin merged 3 commits into
HKUDS:mainfrom
zpljd258:feat/kimi-coding-provider

Conversation

@zpljd258

@zpljd258 zpljd258 commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a dedicated kimi_coding provider for Kimi Coding Plan's Anthropic Messages API endpoint.

Changes

  • Register kimi_coding with the Anthropic backend and default base URL https://api.kimi.com/coding/v1.
  • Add providers.kimiCoding config support with a separate KIMI_CODING_API_KEY, so it does not collide with Moonshot/Kimi's OpenAI-compatible provider.
  • Add provider-level default extra headers and use them from the factory. Kimi Coding now sends the required Claude-compatible User-Agent by default, while user extraHeaders can still override it.
  • Document setup in the configuration reference and provider cookbook.
  • Add regression tests for the default header and override behavior.

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

@chengyongru chengyongru added provider valid documentation Improvements or additions to documentation labels Jun 23, 2026
zpljd258 pushed a commit to zpljd258/nanobot that referenced this pull request Jun 23, 2026
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 chengyongru left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated PR review by nanobot. This is not a human maintainer review or approval.

Side-effect analysis for adding the Kimi Coding Plan provider:

  1. Schema and registry registration — kimi_coding is added as a new ProviderConfig field with default_factory=ProviderConfig, so existing configs without a kimiCoding block are unaffected. The provider spec uses backend="anthropic", routing requests through AnthropicProvider.

  2. Separate env key — Uses KIMI_CODING_API_KEY instead of MOONSHOT_API_KEY, correctly separating the two Kimi/Moonshot platforms (Anthropic Messages API vs OpenAI-compatible). No collision risk.

  3. User-Agent requirement — The endpoint requires extraHeaders.User-Agent set 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 handle extraHeaders. Worth noting in docs that this header is effectively mandatory, not optional.

  4. 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.

  5. 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",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chengyongru chengyongru added enhancement New feature or request new-provider labels Jun 23, 2026
@zpljd258
zpljd258 force-pushed the feat/kimi-coding-provider branch from 059ea84 to 9c71f29 Compare June 23, 2026 12:18
NanoBot and others added 3 commits June 24, 2026 10:31
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.
@Re-bin
Re-bin force-pushed the feat/kimi-coding-provider branch from 9c71f29 to f055c0c Compare June 24, 2026 02:34

@Re-bin Re-bin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Re-bin
Re-bin merged commit f9afc93 into HKUDS:main Jun 24, 2026
4 checks passed
@zpljd258
zpljd258 deleted the feat/kimi-coding-provider branch June 24, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request new-provider provider valid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Support Kimi Coding Plan (kimi-for-coding) for subscription users

3 participants