Skip to content

feat(provider): add Kimi Code provider#508

Merged
SantiagoDePolonia merged 8 commits into
ENTERPILOT:mainfrom
weselben:feat/provider-kimi-code
Jul 7, 2026
Merged

feat(provider): add Kimi Code provider#508
SantiagoDePolonia merged 8 commits into
ENTERPILOT:mainfrom
weselben:feat/provider-kimi-code

Conversation

@weselben

@weselben weselben commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Closes #487 (replaces the mixed provider + header-override branch) and implements Kimi Code provider in single PR.

What

Adds a new kimicode provider that routes the Kimi Code OpenAI-compatible API through GoModel, so callers can use kimi-for-coding and bge_m3_embed with the same /v1/chat/completions, /v1/embeddings, and /v1/models endpoints as any other provider.

User-visible behavior

  • Provider type is kimicode. Set KIMICODE_API_KEY in the environment or declare a type: kimicode provider in config.yaml.
  • Default base URL is https://api.kimi.com/coding/v1; override via KIMICODE_BASE_URL or base_url in config.
  • Model IDs are passed through as-is, prefixed with the provider name in the GoModel model list: kimicode/kimi-for-coding and kimicode/bge_m3_embed.
  • Embeddings are returned through the standard OpenAI-compatible /v1/embeddings shape.
  • Streaming chat completions work over SSE and end with data: [DONE].

Design

Kimi Code is exposed as a pure OpenAI-compatible provider, so the implementation reuses the existing openai.CompatibleProvider infrastructure rather than adding a custom protocol adapter. This keeps the provider thin and means any future improvements to the OpenAI-compatible path (e.g., reasoning responses, batch, or image support) automatically apply to Kimi Code as long as the upstream API supports them.

Implementation

  • New package internal/providers/kimicode/ with a ChatCompatible adapter that points at the Kimi Code base URL and provider type kimicode.
  • Registration in run/providers.go so KIMICODE_API_KEY auto-discovers the provider.
  • Unit tests in internal/providers/kimicode/kimicode_test.go covering registration and package-level constructors.
  • Contract tests in tests/contract/kimicode_test.go using recorded replay fixtures for chat, streaming chat, models, and embeddings.
  • Recording support in cmd/recordapi/main.go for the Kimi Code API, including the embeddings endpoint and model capability gating.
  • Documentation: new docs/providers/kimicode.mdx, updated docs/providers/overview.mdx, and docs/docs.json navigation.
  • .env.template updated with KIMICODE_API_KEY, KIMICODE_BASE_URL, and KIMICODE_MODELS.

Verification

  • go build ./... passes cleanly.
  • go test ./internal/providers/kimicode/... ./run/... ./config/... passes.
  • go test -tags=contract ./tests/contract/... -run Kimi passes the Kimi Code replay contract tests (chat, streaming chat, models, embeddings).
  • gofmt -l reports no diffs for the files changed on this branch; only pre-existing benchmark tooling in docs/2026-06-25_aws_gateway_benchmark/ remains unformatted.
  • Built the Docker image locally, started the stack with the provided .env, and verified live calls against the Kimi Code API:
    • /v1/models lists kimicode/kimi-for-coding and kimicode/bge_m3_embed.
    • /v1/embeddings for kimicode/bge_m3_embed returns a 1024-dimensional vector.
    • /v1/chat/completions for kimicode/kimi-for-coding returns a non-streaming completion with provider: kimicode.
    • Streaming /v1/chat/completions returns SSE chunks, a usage block, and terminates cleanly with data: [DONE].
  • Health and readiness probes pass; no errors or warnings were emitted during the run.

Summary by CodeRabbit

  • New Features
    • Added the Kimi Code provider with support for chat, streaming chat, model listing, and embeddings.
    • Enhanced CLI/configuration to recognize embeddings-capable endpoints and apply provider-specific default models (while still honoring explicit -model overrides).
  • Documentation
    • Updated environment template and added provider docs plus an overview entry for Kimi Code, including setup/config examples.
  • Tests
    • Added unit and contract tests with golden fixtures for chat (stream/non-stream), models, and embeddings.
  • Bug Fixes
    • Improved provider request routing for endpoint path handling and default model selection.

weselben added 3 commits July 7, 2026 16:19
Add the `kimicode` provider, a dedicated type for Kimi Code's
OpenAI-compatible membership endpoint at `https://api.kimi.com/coding/v1`.
Kimi Code uses its own API-key realm and a stable `kimi-for-coding` model
alias, so it is exposed as a distinct provider rather than overloading the
general Moonshot platform type.

- Introduce `internal/providers/kimicode/` with `New` and
  `NewWithHTTPClient` factories that wrap the shared
  `openai.ChatCompatible` adapter, forwarding model IDs unchanged.
- Register `kimicode.Registration` in `run/providers.go` so the gateway
  recognizes it on startup.
- Add `KIMICODE_API_KEY`, `KIMICODE_BASE_URL`, and `KIMICODE_MODELS` to
  `.env.template` for environment-based credential discovery.
- Extend `cmd/recordapi` to support `kimicode`: add an embeddings endpoint
  fixture, provider-specific default models (`kimi-for-coding`,
  `bge_m3_embed`), embeddings capability gating, and a path override for
  `/v1/embeddings` so recorded fixtures match Kimi Code's route layout.
Lock in the new `kimicode` provider with unit and contract coverage so
future refactors of the provider factory or chat-compatible adapter cannot
silently break Kimi Code routing.

- `internal/providers/kimicode/kimicode_test.go` — factory behavior for
  the provider, including default and custom base URL resolution.
- `internal/providers/config_test.go` — discover `kimicode` in provider
  configuration parsing.
- `run/lifecycle_test.go` — `TestMain_KimicodeProviderRegistration` pins
  the lifecycle wiring.
- `run/providers_test.go` — assert `kimicode` appears in the registered
  provider types.
- `tests/contract/kimicode_test.go` plus contract fixtures and golden
  files for chat completions, chat completion streaming, embeddings,
  and model listing so the contract suite can replay Kimi Code-shaped
  responses without live credentials.
add Kimi Code docs page, overview table row, navigation entry, and contract README fixture layout; align `/responses` support and cost wording with implementation after review.
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: bebfd1b9-9fe9-4ba4-abdb-8dfa5e2bfeed

📥 Commits

Reviewing files that changed from the base of the PR and between ac2bce3 and a32ace2.

📒 Files selected for processing (1)
  • docs/providers/kimicode.mdx

📝 Walkthrough

Walkthrough

This PR adds a new Kimicode OpenAI-compatible provider, wires it into factory registration and recordapi tooling, and adds unit/contract coverage plus docs and env-template updates.

Changes

Kimicode Provider Integration

Layer / File(s) Summary
Provider implementation and factory registration
internal/providers/kimicode/kimicode.go, run/providers.go, internal/providers/config_test.go
New kimicode package defines Registration, Provider, New, and NewWithHTTPClient; it is registered in defaultProviderFactory and added to discovery test configs.
Provider unit tests and factory registration tests
internal/providers/kimicode/kimicode_test.go, run/lifecycle_test.go, run/providers_test.go
Tests validate provider construction, registration metadata, embeddings round-trip behavior, and factory registration/creation for kimicode.
recordapi CLI support for Kimicode and embeddings
cmd/recordapi/main.go
Adds Kimicode provider config, an embeddings endpoint, capability gating, default-model lookup, and endpoint path overrides in request generation.
Contract tests and fixtures for Kimicode
tests/contract/kimicode_test.go, tests/contract/testdata/kimicode/*, tests/contract/testdata/golden/kimicode/*, tests/contract/README.md
Replay contract tests cover chat completion, streaming, models, embeddings, and error handling with new input and golden fixtures.
Documentation and env template updates
.env.template, docs/providers/kimicode.mdx, docs/providers/overview.mdx, docs/docs.json
Adds Kimi Code environment examples, a provider guide, navigation entry, and overview table/notes.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Poem

I hop through configs, quick and bright,
Kimicode joins the lane tonight. 🐇
Streams, embeddings, docs all shine,
Fixtures hum in tidy line.
A carrot toast to code so neat—
This bunny grins: “review complete!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding the Kimi Code provider.
Linked Issues check ✅ Passed The PR satisfies the Kimi provider objectives in #487, including the OpenAI-compatible integration, default base URL, docs, tests, and recordapi support.
Out of Scope Changes check ✅ Passed All changes support the new Kimi provider or its documentation, tests, fixtures, and tooling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/recordapi/main.go`:
- Around line 132-139: The shared embeddings recording path is being used for
providers that need different request URLs, so add provider-specific overrides
in the record API config instead of changing the common `/embeddings` entry.
Update the embeddings setup in `cmd/recordapi/main.go` so OpenAI and Groq record
against `/v1/embeddings`, while keeping the existing shared path behavior for
Gemini; use the existing embeddings request definition as the reference point.

In `@docs/providers/kimicode.mdx`:
- Around line 34-39: The KIMICODE configuration example currently shows only the
chat model list and omits the embeddings model, which can mislead users into
breaking embeddings support. Update the snippet in the kimicode guide to include
the embeddings model alongside the existing KIMICODE_MODELS example, or
explicitly mark the example as chat-only so it matches the documented embedding
behavior.

In `@tests/contract/kimicode_test.go`:
- Around line 27-94: The new Kimicode replay tests only cover success cases, so
add error-handling coverage for the replay client. Introduce a test around the
existing provider methods like TestKimicodeReplayChatCompletion or a new
TestKimicodeReplay...Error case that configures newKimicodeReplayProvider with a
non-2xx/upstream-error response for /chat/completions (or another endpoint) and
asserts the returned error is surfaced correctly. Keep the same test style and
use the existing replay helpers and provider methods to verify request
translation still happens while the error path is exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e9add091-5d25-420f-88a2-70bf4af278df

📥 Commits

Reviewing files that changed from the base of the PR and between 2c3ab68 and 5b21e6c.

📒 Files selected for processing (21)
  • .env.template
  • cmd/recordapi/main.go
  • docs/docs.json
  • docs/providers/kimicode.mdx
  • docs/providers/overview.mdx
  • internal/providers/config_test.go
  • internal/providers/kimicode/kimicode.go
  • internal/providers/kimicode/kimicode_test.go
  • run/lifecycle_test.go
  • run/providers.go
  • run/providers_test.go
  • tests/contract/README.md
  • tests/contract/kimicode_test.go
  • tests/contract/testdata/golden/kimicode/chat_completion.golden.json
  • tests/contract/testdata/golden/kimicode/chat_completion_stream.golden.json
  • tests/contract/testdata/golden/kimicode/embeddings.golden.json
  • tests/contract/testdata/golden/kimicode/models.golden.json
  • tests/contract/testdata/kimicode/chat_completion.json
  • tests/contract/testdata/kimicode/chat_completion_stream.txt
  • tests/contract/testdata/kimicode/embeddings.json
  • tests/contract/testdata/kimicode/models.json

Comment thread cmd/recordapi/main.go
Comment thread docs/providers/kimicode.mdx
Comment thread tests/contract/kimicode_test.go
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

Safe to merge with low risk.

The new provider delegates to the existing OpenAI-compatible adapter, and the changed registration, discovery, recorder, and contract-test paths are consistent with existing provider patterns. No correctness or security issues were identified in the changed code.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • Validated the PR's general contract proof by running Kimi replay tests and unit/config checks; all Kimi replay tests passed, gomodel/tests/contract returned ok, and gomodel/internal/providers/kimicode, gomodel/run, and gomodel/config returned ok with no severity-bearing findings.

View all artifacts

T-Rex Ran code and verified through T-Rex

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Client
participant GoModel as GoModel OpenAI-compatible API
participant Factory as Provider Factory
participant Kimi as kimicode.Provider
participant Upstream as Kimi Code API

Client->>GoModel: "/v1/chat/completions or /v1/embeddings\nmodel: kimicode/<model>"
GoModel->>Factory: Resolve provider type kimicode
Factory->>Kimi: Create with KIMICODE_API_KEY\nbase URL https://api.kimi.com/coding/v1
Kimi->>Upstream: OpenAI-compatible request\n/chat/completions, /embeddings, or /models
Upstream-->>Kimi: OpenAI-shaped response or SSE stream
Kimi-->>GoModel: Normalized core response
GoModel-->>Client: Standard OpenAI-compatible response
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Client
participant GoModel as GoModel OpenAI-compatible API
participant Factory as Provider Factory
participant Kimi as kimicode.Provider
participant Upstream as Kimi Code API

Client->>GoModel: "/v1/chat/completions or /v1/embeddings\nmodel: kimicode/<model>"
GoModel->>Factory: Resolve provider type kimicode
Factory->>Kimi: Create with KIMICODE_API_KEY\nbase URL https://api.kimi.com/coding/v1
Kimi->>Upstream: OpenAI-compatible request\n/chat/completions, /embeddings, or /models
Upstream-->>Kimi: OpenAI-shaped response or SSE stream
Kimi-->>GoModel: Normalized core response
GoModel-->>Client: Standard OpenAI-compatible response
Loading

Reviews (2): Last reviewed commit: "style(run): apply gofmt to provider regi..." | Re-trigger Greptile

Comment thread cmd/recordapi/main.go
weselben added 4 commits July 7, 2026 18:56
OpenAI and Groq both expose embeddings under /v1/embeddings, but the
recordapi generic endpoint used /embeddings. Add provider-specific
overrides so recordings target the correct upstream path.

Gemini is intentionally left unchanged: its base URL already includes the
/v1beta/openai prefix, so the generic /embeddings path is correct.
The docs example only listed the chat model, while the Embeddings
section and .env.template document both chat and embeddings models.
Update the snippet so users do not accidentally disable embeddings
support by copying the example.
Add TestKimicodeReplayChatCompletionError to exercise the non-2xx
path for the Kimi Code provider via the replay harness. Asserts the
upstream error is surfaced correctly by the OpenAI-compatible adapter.
No functional changes; formatting only.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/providers/kimicode.mdx (1)

28-31: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the provider key and selector in sync.

providers.kimicode is described as arbitrary, but the selector example hard-codes that key. If a user renames the entry, any selector: "kimicode:..." values must change too or virtual routing will break.

♻️ Suggested wording
 <Note>
   The provider `type` is `kimicode` (no hyphen). The config key (`kimicode` in
-  the example above) is arbitrary and only identifies this entry inside your
-  config; it may be changed.
+  the example above) is arbitrary, but any selector strings that reference it
+  must be updated if you rename the entry.
 </Note>

Also applies to: 46-50

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/providers/kimicode.mdx` around lines 28 - 31, The provider entry key and
selector examples are inconsistent: the docs currently say the config key is
arbitrary, but the `kimicodeSelector`/`selector` example hard-codes `kimicode`,
which will break if users rename the provider entry. Update the wording around
the `kimicode` provider example and any selector guidance so it explicitly
states that the selector prefix must match the configured provider key, and
adjust the related `kimicode` references in the doc to stay in sync.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docs/providers/kimicode.mdx`:
- Around line 28-31: The provider entry key and selector examples are
inconsistent: the docs currently say the config key is arbitrary, but the
`kimicodeSelector`/`selector` example hard-codes `kimicode`, which will break if
users rename the provider entry. Update the wording around the `kimicode`
provider example and any selector guidance so it explicitly states that the
selector prefix must match the configured provider key, and adjust the related
`kimicode` references in the doc to stay in sync.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: a1509509-a689-4f5d-a1c9-c618f6272c85

📥 Commits

Reviewing files that changed from the base of the PR and between 5b21e6c and ac2bce3.

📒 Files selected for processing (6)
  • cmd/recordapi/main.go
  • docs/providers/kimicode.mdx
  • run/lifecycle_test.go
  • run/providers.go
  • run/providers_test.go
  • tests/contract/kimicode_test.go

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 33.33333% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/recordapi/main.go 0.00% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

@SantiagoDePolonia

Copy link
Copy Markdown
Contributor

@weselben
One issue to fix before merge:

  1. 🟠 Invalid virtual-model example in docs/providers/kimicode.mdx (docs correctness)

The "Models" section shows:
virtual:
kimi-coding:
selector: "kimicode:kimi-for-coding"
None of this matches the actual config schema (config/virtualmodels.go): the key is virtual_models: (a list, not a name-keyed map), the field is target:/targets: (there is no selector: field), and provider/model selectors use a slash, not a colon. A user copy-pasting this gets a config error. It should read:
virtual_models:

  • source: kimi-coding
    target: kimicode/kimi-for-coding

The Models section used an outdated `virtual`/`selector` map that does
not match the actual config schema. Update it to `virtual_models:`
(list) with `source:` and `target:` using the provider/model slash
selector.
@weselben

weselben commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@SantiagoDePolonia you're right, that example was copy-pasted from the wrong schema. The correct form uses virtual_models: (a list), source: for the virtual name, and target: with a provider/model selector using a slash. I fixed it to:

virtual_models:
  - source: kimi-coding
    target: kimicode/kimi-for-coding

@SantiagoDePolonia SantiagoDePolonia merged commit 4bd78f9 into ENTERPILOT:main Jul 7, 2026
13 checks passed
@SantiagoDePolonia

Copy link
Copy Markdown
Contributor

@weselben Congrats! It was merged! :) If you can double check it by running GoModel main locally, that would be great. The changes will be in GoModel's next release!

@weselben

weselben commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@SantiagoDePolonia
image
I can confirm it works without any issues! For embeddings, it is necessary to set KIMICODE_MODELS (with embedding model and kimi-for-coding) and CONFIGURED_PROVIDER_MODELS_MODE to allowlist, as the model isn't registered otherwise.

KIMICODE_MODELS=kimi-for-coding,bge_m3_embed
CONFIGURED_PROVIDER_MODELS_MODE=allowlist

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.

3 participants