Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions packages/actions/src/prepare-request-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,8 @@ describe("prepareRequestBody - reasoning_effort none", () => {
describe("prepareRequestBody - Moonshot thinking", () => {
async function prepare(options: {
model: string;
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high";
reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "max";
maxTokens?: number;
}) {
return (await prepareRequestBody(
"moonshot",
Expand All @@ -934,7 +935,7 @@ describe("prepareRequestBody - Moonshot thinking", () => {
[{ role: "user", content: "Hello!" }],
false, // stream
undefined, // temperature
undefined, // max_tokens
options.maxTokens, // max_tokens
undefined, // top_p
undefined, // frequency_penalty
undefined, // presence_penalty
Expand Down Expand Up @@ -994,6 +995,33 @@ describe("prepareRequestBody - Moonshot thinking", () => {
});
expect(requestBody.thinking).toEqual({ type: "enabled" });
});

test("forwards reasoning_effort natively for kimi-k3 (no thinking toggle)", async () => {
const requestBody = await prepare({
model: "kimi-k3",
reasoningEffort: "max",
});
expect(requestBody.reasoning_effort).toBe("max");
expect(requestBody.thinking).toBeUndefined();
});

test("collapses disable requests onto the provider default for kimi-k3", async () => {
const requestBody = await prepare({
model: "kimi-k3",
reasoningEffort: "none",
});
expect(requestBody.reasoning_effort).toBeUndefined();
expect(requestBody.thinking).toBeUndefined();
});

test("sends max_completion_tokens instead of max_tokens for kimi-k3", async () => {
const requestBody = await prepare({
model: "kimi-k3",
maxTokens: 4096,
});
expect(requestBody.max_completion_tokens).toBe(4096);
expect(requestBody.max_tokens).toBeUndefined();
});
});

describe("prepareRequestBody - Alibaba thinking", () => {
Expand Down
51 changes: 35 additions & 16 deletions packages/actions/src/prepare-request-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,11 @@ export async function prepareRequestBody(
break;
}
case "moonshot": {
// Kimi K3 has its own parameter surface: output length is capped via
// `max_completion_tokens` (the K2-era `max_tokens` is not documented
// for it), and thinking is configured through the native top-level
// `reasoning_effort` field instead of the binary `thinking` toggle.
const isKimiK3 = usedInternalModel === "kimi-k3";
if (stream) {
requestBody.stream_options = {
include_usage: true,
Expand All @@ -2020,7 +2025,11 @@ export async function prepareRequestBody(
requestBody.temperature = temperature;
}
if (max_tokens !== undefined) {
requestBody.max_tokens = max_tokens;
if (isKimiK3) {
requestBody.max_completion_tokens = max_tokens;
} else {
requestBody.max_tokens = max_tokens;
}
}
if (top_p !== undefined) {
requestBody.top_p = top_p;
Expand All @@ -2031,24 +2040,34 @@ export async function prepareRequestBody(
if (presence_penalty !== undefined) {
requestBody.presence_penalty = presence_penalty;
}
// Moonshot's thinking models don't recognize `reasoning_effort`; they
// take a binary `thinking` parameter (`{ type: "enabled" | "disabled" }`)
// and think by default. Map `none`/`minimal` to an explicit disable and
// every other tier to an explicit enable; when no effort is requested,
// send nothing and keep the provider default (thinking on). Mappings
// that can turn thinking off declare `none` in `reasoningEfforts`;
// always-on models (kimi-k2.7-code*) reject `"disabled"` with a 400, so
// collapse disable requests onto their minimum (thinking stays on).
// Moonshot's K2-era thinking models don't recognize `reasoning_effort`;
// they take a binary `thinking` parameter (`{ type: "enabled" |
// "disabled" }`) and think by default. Map `none`/`minimal` to an
// explicit disable and every other tier to an explicit enable; when no
// effort is requested, send nothing and keep the provider default
// (thinking on). Mappings that can turn thinking off declare `none` in
// `reasoningEfforts`; always-on models (kimi-k2.7-code*) reject
// `"disabled"` with a 400, so collapse disable requests onto their
// minimum (thinking stays on). Kimi K3 instead takes the top-level
// `reasoning_effort` field natively (currently only "max") and always
// thinks, so forward the effort as-is and collapse disable requests
// onto the provider default.
if (supportsReasoning && reasoning_effort !== undefined) {
const wantsThinking =
reasoning_effort !== "none" && reasoning_effort !== "minimal";
const canDisableThinking =
providerMappingForOptions?.reasoningEfforts?.includes("none") ??
false;
if (wantsThinking) {
requestBody.thinking = { type: "enabled" };
} else if (canDisableThinking) {
requestBody.thinking = { type: "disabled" };
if (isKimiK3) {
if (wantsThinking) {
requestBody.reasoning_effort = reasoning_effort;
}
} else {
const canDisableThinking =
providerMappingForOptions?.reasoningEfforts?.includes("none") ??
false;
if (wantsThinking) {
requestBody.thinking = { type: "enabled" };
} else if (canDisableThinking) {
requestBody.thinking = { type: "disabled" };
}
}
}
break;
Expand Down
36 changes: 36 additions & 0 deletions packages/models/src/models/moonshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,40 @@ export const moonshotModels = [
},
],
},
{
id: "kimi-k3",
name: "Kimi K3",
description:
"Kimi's flagship model for long-horizon coding and end-to-end knowledge work with a 1M-token context window.",
family: "moonshot",
releasedAt: new Date("2026-07-16"),
providers: [
{
providerId: "moonshot",
externalId: "kimi-k3",
inputPrice: "3.0e-6",
cachedInputPrice: "0.3e-6",
outputPrice: "15.0e-6",
requestPrice: "0",
contextSize: 1048576,
maxOutput: 1048576,
reasoning: true,
// K3 always thinks; the effort level is set via the native
// top-level `reasoning_effort` field (no K2-era `thinking`
// toggle), which currently accepts only "max".
reasoningEfforts: ["max"],
streaming: true,
vision: true,
tools: true,
jsonOutput: true,
supportedParameters: [
"max_tokens",
"response_format",
"tools",
"tool_choice",
"reasoning_effort",
],
},
],
},
] as const satisfies ModelDefinition[];
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const curatedCategoryModelIds: Record<
"gemini-3.5-flash",
"grok-build-0-1",
"grok-4-3",
"kimi-k3",
"kimi-k2.7-code",
"kimi-k2.7-code-highspeed",
"kimi-k2.6",
Expand Down Expand Up @@ -195,6 +196,8 @@ export const OPEN_SOURCE_MODEL_IDS: ReadonlySet<string> = new Set([
// API-only Muse Spark models alongside the open Llama family)
export const CLOSED_SOURCE_MODEL_IDS: ReadonlySet<string> = new Set([
"muse-spark-1.1",
// API-only at launch; no open weights published (unlike the K2 family)
"kimi-k3",
]);

export function isTextOutput(output: string[] | null | undefined): boolean {
Expand Down
Loading