Skip to content

🤖 feat: add native Kimi K3 support via a new Moonshot AI provider#3737

Merged
ibetitsmike merged 4 commits into
mainfrom
mike/kimi-k3-openrouter
Jul 21, 2026
Merged

🤖 feat: add native Kimi K3 support via a new Moonshot AI provider#3737
ibetitsmike merged 4 commits into
mainfrom
mike/kimi-k3-openrouter

Conversation

@ibetitsmike

@ibetitsmike ibetitsmike commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds Kimi K3 as a first-class built-in model backed by a new moonshotai direct provider (official @ai-sdk/moonshotai package), with aliases, token/cost metadata, a fixed thinking policy, and reasoning options matching what the model actually accepts. OpenRouter routing for Moonshot models keeps working as a gateway route.

Background

Kimi K3 is Moonshot AI's flagship open-weight reasoning model (released July 16, 2026). The first iteration of this PR registered it as an OpenRouter gateway model; per review direction it now uses the AI SDK's official Moonshot provider directly (MOONSHOT_API_KEY, api.moonshot.ai), which types K3's reasoningEffort as the literal "max".

Implementation

  • New moonshotai provider: registered in PROVIDER_DEFINITIONS (direct, createMoonshotAI), providers config schema, MOONSHOT_API_KEY env wiring, Settings key URL, provider icon, and OpenRouter routes so openrouter:moonshotai/... still canonicalizes and routes correctly.
  • KIMI_K3 registry entry is now moonshotai:kimi-k3 (aliases kimi, k3, kimi-k3); tokenizer falls back to moonshotai/kimi-k2 until K3 lands in ai-tokenizer.
  • Metadata keyed as moonshotai/kimi-k3: 1M context / 128K output, $3/M in, $15/M out, $0.30/M cache read, vision + reasoning + function calling.
  • Reasoning: exact-match isKimiK3Model() predicate; fixed ["max"] thinking policy; buildProviderOptions sends { moonshotai: { reasoningEffort: "max" } } for direct requests and the explicit OpenRouter effort: "max" payload when routed through OpenRouter (Codex round-1 fix; enabled: true alone falls back to OpenRouter's default medium effort).
  • Regenerated docs/config/models.mdx, docs/config/providers.mdx, and built-in skill content.

Validation

  • Full suite green (10023 pass; 2 unrelated WorkspaceStore timing tests flaked under load and pass in isolation); make static-check green.
  • Behavioral tests: alias resolution, direct + legacy-gateway stats/capability lookups, gateway-to-direct canonicalization, fixed policy (variant ids excluded), and exact provider-options payloads for direct vs OpenRouter-routed K3.
  • Runtime smoke test: createMoonshotAI instantiates kimi-k3 (spec v4) under our ai@7 stack.

Risks

Low-to-moderate. Registering moonshotai as a direct provider changes canonicalization of openrouter:moonshotai/* strings (they now normalize to the direct provider for metadata, and stay on OpenRouter only via explicit gateway routing). Covered by routing/normalization tests; the non-K3 OpenRouter payload path is unchanged.


Generated with mux • Model: anthropic:claude-fable-5 • Thinking: xhigh • Cost: $19.36

@mintlify

mintlify Bot commented Jul 17, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
Mux 🟢 Ready View Preview Jul 17, 2026, 5:55 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd15daa74b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/common/utils/ai/providerOptions.ts Outdated
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 9c6cf78177

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike ibetitsmike changed the title 🤖 feat: add native support for Kimi K3 via OpenRouter 🤖 feat: add native Kimi K3 support via a new Moonshot AI provider Jul 17, 2026
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 9c234f928a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike force-pushed the mike/kimi-k3-openrouter branch from 9c234f9 to eef38f9 Compare July 17, 2026 18:45
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: eef38f90f4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ibetitsmike
ibetitsmike added this pull request to the merge queue Jul 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 17, 2026
@ibetitsmike
ibetitsmike force-pushed the mike/kimi-k3-openrouter branch from eef38f9 to 2e26ea4 Compare July 21, 2026 22:59
@ibetitsmike

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e26ea4625

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

* branches key off this predicate.
*/
export function isKimiK3Model(modelString: string): boolean {
return stripModelProviderPrefixes(modelString) === "kimi-k3";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Filter Kimi reasoning-only history before replay

Because Kimi K3 is introduced here as an always-reasoning model, a turn that is interrupted after Moonshot has written only reasoning parts can leave a reasoning-only assistant entry in chat.jsonl. prepareProviderRequestMessages currently calls transformModelMessages with providerForMessages === "moonshotai", which falls into the unknown-provider branch instead of the OpenAI-compatible/Anthropic filtering that drops reasoning-only assistant messages; the next request is therefore serialized as an empty assistant message and can be rejected by Moonshot/OpenRouter. Please route Moonshot through the same reasoning-only filtering path before sending history.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Valid finding, thanks. A fix is prepared locally (route moonshotai through the same filterReasoningOnlyMessages path as OpenAI in transformModelMessages, plus a regression test), but this PR is currently in the merge queue, so the branch cannot be updated. It will be pushed here if the PR is dequeued, or land as an immediate follow-up if this merges first. Leaving this thread open until the fix is on a pushed head.

Response from Mux, an AI coding agent acting on Mike's behalf.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR merged from the queue before the fix could be pushed. The fix now lives on branch mike/kimi-k3-reasoning-history-filter (commit 98e990f): moonshotai routes through the same filterReasoningOnlyMessages path as OpenAI in transformModelMessages, with a regression test. It will be submitted as a follow-up PR.

Response from Mux, an AI coding agent acting on Mike's behalf.

@ibetitsmike
ibetitsmike added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit d6886e9 Jul 21, 2026
20 of 21 checks passed
@ibetitsmike
ibetitsmike deleted the mike/kimi-k3-openrouter branch July 21, 2026 23:23
mux-bot Bot added a commit that referenced this pull request Jul 22, 2026
…ions

The isKimiK3Model docstring already explains that Kimi K3 always reasons
and supports only the max reasoning effort, and that the provider-options
branches key off the predicate. #3737 restated that same sentence verbatim
in both the Moonshot and OpenRouter branches of buildProviderOptions, so
trim the duplicated lead sentence and keep only each branch's site-specific
"send it explicitly" rationale. Comment-only; behavior-preserving.
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