Skip to content

feat(provider): add Kimi Code provider#508

Open
weselben wants to merge 7 commits into
ENTERPILOT:mainfrom
weselben:feat/provider-kimi-code
Open

feat(provider): add Kimi Code provider#508
weselben wants to merge 7 commits into
ENTERPILOT:mainfrom
weselben:feat/provider-kimi-code

Conversation

@weselben

@weselben weselben commented Jul 7, 2026

Copy link
Copy Markdown

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 support for the Kimi Code provider (chat, streaming, models, and embeddings).
    • Expanded CLI/configuration to recognize embeddings-capable endpoints and apply provider-specific default models.
    • Updated environment template and provider documentation with setup details and examples.
  • Tests
    • Added unit and contract coverage for Kimi Code, including golden fixtures for chat (non-stream/stream), models, and embeddings.
  • Bug Fixes
    • Improved request routing for provider/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

📝 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 summarizes the main change: adding the Kimi Code provider.
Linked Issues check ✅ Passed The PR delivers the Kimi Code provider, registration, docs, fixtures, and tests aligned with the linked issue’s provider scope.
Out of Scope Changes check ✅ Passed The changes stay focused on Kimi Code provider support, docs, tests, and fixture generation; no unrelated code paths were added.
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: 4/5

Mostly safe to merge after fixing the recorder regression.

The core Kimi Code provider is a thin adapter over existing OpenAI-compatible behavior. One contained bug affects the contract recording utility for existing embeddings-capable providers.

cmd/recordapi/main.go

T-Rex T-Rex Logs

What T-Rex did

  • Ran a focused Go test harness to verify embeddings URL construction, and observed that OpenAI resolves to /embeddings (no version path) while Kimicode uses /v1/embeddings due to its provider override.
  • Validated Kimicode provider unit tests and contract validations; the unit test run and contract replay commands completed successfully, the build smoke finished with exit code 0, and a validation summary captured the exact commands and sanitized environment.

View all artifacts

T-Rex Ran code and verified through T-Rex

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Client as OpenAI-compatible client
participant Gateway as GoModel /v1 endpoints
participant Factory as provider factory
participant Kimi as kimicode Provider
participant Upstream as Kimi Code API

Client->>Gateway: /v1/chat/completions, /v1/embeddings, /v1/models
Gateway->>Factory: resolve provider type kimicode
Factory->>Kimi: create ChatCompatible adapter
Kimi->>Upstream: Authorization: Bearer KIMICODE_API_KEY
Kimi->>Upstream: /chat/completions or /embeddings or /models
Upstream-->>Kimi: OpenAI-compatible response / SSE stream
Kimi-->>Gateway: normalized core response
Gateway-->>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 as OpenAI-compatible client
participant Gateway as GoModel /v1 endpoints
participant Factory as provider factory
participant Kimi as kimicode Provider
participant Upstream as Kimi Code API

Client->>Gateway: /v1/chat/completions, /v1/embeddings, /v1/models
Gateway->>Factory: resolve provider type kimicode
Factory->>Kimi: create ChatCompatible adapter
Kimi->>Upstream: Authorization: Bearer KIMICODE_API_KEY
Kimi->>Upstream: /chat/completions or /embeddings or /models
Upstream-->>Kimi: OpenAI-compatible response / SSE stream
Kimi-->>Gateway: normalized core response
Gateway-->>Client: standard OpenAI-compatible response
Loading

Reviews (1): Last reviewed commit: "docs(providers): add Kimi Code provider ..." | Re-trigger Greptile

Comment thread cmd/recordapi/main.go
Comment on lines +132 to +134
"embeddings": {
path: "/embeddings",
method: http.MethodPost,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Embeddings path omits version
The new embeddings endpoint defaults to /embeddings, so -provider=openai -endpoint=embeddings sends requests to https://api.openai.com/embeddings instead of the OpenAI-compatible /v1/embeddings route used by the gateway adapter. Because openai, gemini, and groq are marked as supporting embeddings without an override, the recorder now fails for those providers.

Artifacts

Repro: focused Go test harness for recorder embeddings URL construction

  • Contains supporting evidence from the run (text/x-go; charset=utf-8).

Repro: verbose Go test output showing openai uses /embeddings while kimicode uses /v1/embeddings

  • Keeps the command output available without making the summary code-heavy.

View artifacts

T-Rex Ran code and verified through T-Rex

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. I checked the upstream docs: OpenAI and Groq both expose embeddings under /v1/embeddings, so I added overrides for both. Gemini doesn't need one because its base URL already ends in /v1beta/openai, and the docs show embeddings at .../v1beta/openai/embeddings. Kimi was already covered.

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

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.

1 participant