Skip to content

feat(model): add built-in kimi-for-coding provider - #15

Closed
yan-ad wants to merge 3 commits into
Blankeos:mainfrom
yan-ad:feat/kimi-for-coding-provider
Closed

feat(model): add built-in kimi-for-coding provider#15
yan-ad wants to merge 3 commits into
Blankeos:mainfrom
yan-ad:feat/kimi-for-coding-provider

Conversation

@yan-ad

@yan-ad yan-ad commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Kimi For Coding as a built-in, drop-in provider. Kimi For Coding is a separate product from Moonshot's general API and speaks the Anthropic Messages protocol at https://api.kimi.com/coding/v1. The previous 401 was caused by crabcode routing the Moonshot provider through the OpenAI-compatible path against the wrong endpoint.

This change registers a static provider extension so users only need to add an auth.json key — matching OpenCode's behavior:

"kimi-for-coding": { "type": "api", "key": "sk-kimi-..." }

No provider URL or custom-provider config required. Run /refreshmodels after adding the key.

Details

  • src/model/extensions/kimicode.rs: static provider with npm: @ai-sdk/anthropic, api: https://api.kimi.com/coding/v1, and models kimi-for-coding, kimi-for-coding-highspeed, k3, k3-256k. Routes through the Anthropic transport (base URL normalized to .../coding, /v1/messages appended).
  • Registered in src/model/extensions/mod.rs PERSISTENT_EXTENSIONS.
  • Declares header: [("User-Agent", "KimiCLI/1.5")] so requests carry the UA Kimi whitelists (avoids the 429 seen otherwise).

User-Agent handling (refactor)

The Kimi User-Agent requirement is not hard-coded in the generic Anthropic provider. Instead:

  • The catalog Provider gained a header field (src/model/extensions/mod.rs, src/llm/client.rs).
  • src/aisdk/providers/anthropic.rs builds request headers generically and applies any provider-declared extra_headers.
  • src/llm/client.rs (create_anthropic_provider) threads the catalog provider's declared headers into the Anthropic client.

This keeps vendor-specific knowledge (the Kimi UA) entirely inside the kimicode extension and the generic Anthropic provider unaware of any vendor.

Verification

  • cargo build clean.
  • 12 related tests pass, including build_anthropic_request_headers_applies_extra_headers and create_anthropic_provider_applies_provider_headers.

🤖 Generated with Claude Code

yan-ad added 3 commits August 5, 2026 10:31
Adds Kimi For Coding as a drop-in provider routed through the Anthropic
transport (api.kimi.com/coding/v1). Users only need to add an auth.json
key 'kimi-for-coding' with their sk-kimi-... key — no URL/config needed,
mirroring OpenCode's setup.
Keep the Anthropic transport generic; vendor-specific headers now live in
the catalog provider (kimicode declares User-Agent: KimiCLI/1.5). The
Anthropic provider applies any provider-declared headers, mirroring how
OpenCode whitelists the kimi-cli UA to avoid 429 rate-limit tiers.
@Blankeos

Blankeos commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Hi @yan-ad have you tested this with your kimi sub? I don't have one so I can't test.

@yan-ad

yan-ad commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@Blankeos not yet, still waiting the whishlist approved tho. I just find the implementation inside the opencode, will test immediately if the sub succeed / approved

@Blankeos

Blankeos commented Aug 6, 2026

Copy link
Copy Markdown
Owner

I bought a $19 moderato Kimi sub just now and it works I think... even without this PR. idk what happened haha.

image image

We can close this PR I think.

EDIT: Scratch that.. I noticed a different problem.. {"error":{"type":"invalid_request_error","message":"an assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: edit:18"},"type":"error"}

@Blankeos

Blankeos commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Alright fixed the problem in 6322075

I think we can close this now.

@yan-ad yan-ad closed this Aug 6, 2026
@Blankeos

Blankeos commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Btw I also fixed prompt caching for this... Noticed my sub burned to 20% in the 5 hr limit with Kimi k3 low w/ just 3 prompts. That was weird. I think that was definitely bad prompt caching. I fixed them here 0e10b43

I can confirm prompts are getting cached when I check cc --emit-logs. But yeah the sub still burns kinda quick. But I'm only burning like 0.8% every prompt with Kimi K3. The $19/m plan is kinda bad I think lol.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants