Skip to content

feat(provider): add kimi-for-coding provider#393

Closed
beyond-infra wants to merge 1 commit into
rohitg00:mainfrom
beyond-infra:feat/kimi-for-coding
Closed

feat(provider): add kimi-for-coding provider#393
beyond-infra wants to merge 1 commit into
rohitg00:mainfrom
beyond-infra:feat/kimi-for-coding

Conversation

@beyond-infra
Copy link
Copy Markdown

@beyond-infra beyond-infra commented May 15, 2026

Summary

Add support for Kimi for Coding (Moonshot AI Coding Plan) via their Anthropic-compatible endpoint at https://api.kimi.com/coding.

Key Changes

  • New provider: kimi-for-coding with KIMI_API_KEY env var
  • Shared base class: Extract AnthropicCompatibleProvider to eliminate ~60 lines of duplication with MinimaxProvider
  • User-Agent workaround: Kimi rejects default Anthropic SDK User-Agent with HTTP 429; we pass KimiCLI/1.5
  • describeImage support: Added to both KimiForCodingProvider and MinimaxProvider (was missing)

Env Vars

Variable Required Default
KIMI_API_KEY Yes
KIMI_BASE_URL No https://api.kimi.com/coding
KIMI_MODEL No kimi-k2

Tests

  • test/kimi-for-coding-provider.test.ts — base URL resolution (default + env override)
  • test/kimi-for-coding-e2e.test.ts — mock fetch verifies headers, body shape, and error handling

Compatibility Notes

This PR touches src/types.ts (ProviderType) and src/providers/index.ts (createBaseProvider), which may conflict with other open provider PRs:

If any of these merge first, this PR will need a rebase.

Additionally, #379 (AbortController timeout) adds fetchWithTimeout to minimax.ts. Since this PR extracts a shared AnthropicCompatibleProvider base class, the timeout logic from #379 should ideally be merged into the base class rather than per-provider. Happy to coordinate with #379's author if both PRs are accepted.

Verification

  • npm run build passes
  • New tests pass (11/11)
  • Prettier formatted
  • DCO sign-off

Add support for Kimi for Coding (Moonshot AI Coding Plan) via their
Anthropic-compatible endpoint at https://api.kimi.com/coding.

Key points:
- Requires whitelisted User-Agent (KimiCLI/1.5) to avoid HTTP 429
  "engine overloaded" errors.
- Extracts shared AnthropicCompatibleProvider base class to eliminate
  ~60 lines of duplication with MinimaxProvider.
- Adds describeImage support that MinimaxProvider was missing.

Env vars:
  KIMI_API_KEY  (required)
  KIMI_BASE_URL (optional, default: https://api.kimi.com/coding)
  KIMI_MODEL    (optional, default: kimi-k2)

Tests:
  - test/kimi-for-coding-provider.test.ts — base URL resolution
  - test/kimi-for-coding-e2e.test.ts — request shape + error handling
Signed-off-by: yangyunchao <yangyunchao@tal.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 2026

@yangyunchao-tal is attempting to deploy a commit to the rohitg00's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

📝 Walkthrough

Walkthrough

Introduces AnthropicCompatibleProvider, a reusable base class for Anthropic-compatible APIs with compress, summarize, and image description. Adds KimiForCodingProvider as its first consumer, refactors MinimaxProvider to extend it, and updates the provider registry. Tests cover request/response behavior and environment-driven configuration.

Changes

Anthropic-Compatible Provider Abstraction and Kimi Integration

Layer / File(s) Summary
AnthropicCompatibleProvider base class
src/providers/anthropic-compatible.ts
Defines the reusable AnthropicCompatibleProvider with configurable API key, model, base URL, and headers. Implements compress, summarize, and describeImage methods that delegate to shared request/response handling: posting to /v1/messages, parsing JSON for the first text content block, and throwing formatted errors on non-OK responses.
KimiForCodingProvider and provider registry wiring
src/providers/kimi-for-coding.ts, src/providers/index.ts, src/types.ts
Extends AnthropicCompatibleProvider to support Kimi's coding API with base URL from KIMI_BASE_URL (default: https://api.kimi.com/coding) and whitelisted User-Agent header. Adds kimi-for-coding to the provider type union and extends the factory to instantiate it with the required API key.
MinimaxProvider refactoring to extend AnthropicCompatibleProvider
src/providers/minimax.ts
Removes MinimaxProvider's custom compress, summarize, and private call implementation. Converts the class to extend AnthropicCompatibleProvider, delegating request/response handling to the base class and preserving the existing MINIMAX_BASE_URL default.
KimiForCodingProvider tests
test/kimi-for-coding-e2e.test.ts, test/kimi-for-coding-provider.test.ts
E2e test validates endpoint, headers, payload shape, and error handling (429 responses). Unit tests verify base URL resolution: default behavior and KIMI_BASE_URL override.

Sequence Diagram

sequenceDiagram
  participant Client
  participant KimiProvider as KimiForCodingProvider
  participant BaseProvider as AnthropicCompatibleProvider
  participant KimiAPI as Kimi /v1/messages
  
  Client->>KimiProvider: summarize(systemPrompt, userPrompt)
  KimiProvider->>BaseProvider: super.summarize(...)
  BaseProvider->>BaseProvider: Build headers + body
  BaseProvider->>KimiAPI: POST (auth, model, messages)
  KimiAPI-->>BaseProvider: JSON with content blocks
  BaseProvider->>BaseProvider: Extract first text block
  BaseProvider-->>KimiProvider: text result
  KimiProvider-->>Client: text result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • rohitg00/agentmemory#103: Both PRs modify MiniMax provider behavior—feat: add MiniMax provider and fix ANTHROPIC_BASE_URL not passed to SDK #103 introduces a fetch-based MinimaxProvider and baseURL plumbing, while the main PR refactors src/providers/minimax.ts to extend the new AnthropicCompatibleProvider (removing its prior custom call/parsing logic).
  • rohitg00/agentmemory#150: The main PR adds/rewires MemoryProvider.summarize implementations via AnthropicCompatibleProvider (and new kimi-for-coding/delegating MinimaxProvider), which the retrieved PR's new mem::compress-file tool depends on to generate the compressed Markdown.

Poem

🐰 A rabbit hops with glee so bright,
Anthropic shines in unified light!
Kimi joins the coding quest,
Minimax mirrors follow best—
One base, three providers in sight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(provider): add kimi-for-coding provider' directly and clearly summarizes the main change: adding a new provider for Kimi for Coding.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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