π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(moonshot): drop unsupported reasoning_effort values for Kimi K3 (#17272)
YuTengjing00067ddcb5a0
diff --git a/packages/model-runtime/src/providers/moonshot/index.test.ts b/packages/model-runtime/src/providers/moonshot/index.test.tsindex a270d1a41a1..8c67ce6d583 100644--- a/packages/model-runtime/src/providers/moonshot/index.test.ts+++ b/packages/model-runtime/src/providers/moonshot/index.test.ts@@ -413,6 +413,22 @@ describe('LobeMoonshotOpenAI', () => {expect(payload.reasoning_effort).toBe('max');});+ it.each(['low', 'medium', 'high'])(+ "should drop a non-'max' reasoning_effort (%s) for kimi-k3",+ async (effort) => {+ await instance.chat({+ messages: [{ content: 'Hello', role: 'user' }],+ model: 'kimi-k3',+ reasoning_effort: effort,+ } as any);++ const payload = getLastRequestPayload();+ // K3 only accepts reasoning_effort 'max' (also the server default); other values+ // would be rejected, so they are dropped instead of failing the request.+ expect('reasoning_effort' in payload).toBe(false);+ },+ );+it('should force reasoning_content on assistant messages for kimi-k3', async () => {await instance.chat({messages: [diff --git a/packages/model-runtime/src/providers/moonshot/index.ts b/packages/model-runtime/src/providers/moonshot/index.tsindex 974be3efd4e..409cdc05593 100644--- a/packages/model-runtime/src/providers/moonshot/index.ts+++ b/packages/model-runtime/src/providers/moonshot/index.ts@@ -204,21 +204,25 @@ const buildMoonshotOpenAIPayload = (const moonshotTools = appendSearchTool(tools, enabledSearch);// K3+ replaced the `thinking` param with the top-level OpenAI-style `reasoning_effort`- // (currently only 'max', which is also the server default β passed through from the- // payload as-is) and fixes temperature/top_p/n/penalties server-side; the docs advise- // not to send them. `max_tokens` is documented as `max_completion_tokens` (default- // 131072, up to 1048576). https://platform.kimi.ai/docs/guide/kimi-k3-quickstart+ // and fixes temperature/top_p/n/penalties server-side; the docs advise not to send+ // them. `max_tokens` is documented as `max_completion_tokens` (default 131072, up to+ // 1048576). https://platform.kimi.ai/docs/guide/kimi-k3-quickstartif (isKimiReasoningEffortModel(model)) {const {frequency_penalty: _frequencyPenalty,max_tokens,presence_penalty: _presencePenalty,+ reasoning_effort,top_p: _topP,...effortRest} = rest;return {...effortRest,+ // K3 currently only accepts reasoning_effort 'max' (also the server default);+ // a saved generic effort (the UI offers low/medium/high) would be rejected, so+ // drop anything else instead of failing the whole request+ ...(reasoning_effort === 'max' ? { reasoning_effort } : {}),...(max_tokens === undefined ? {} : { max_completion_tokens: max_tokens }),messages: normalizedMessages,model,diff --git a/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts b/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.tsindex d0054c29a05..92c0d8580e9 100644--- a/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts+++ b/packages/model-runtime/src/providers/opencodeCodingPlan/index.test.ts@@ -177,7 +177,7 @@ describe('buildOpenAIPayload Kimi thinking semantics', () => {});describe('native-thinking K3 models (kimi-k3)', () => {- it('should drop a saved thinking:disabled and keep reasoning_effort + forced reasoning_content', async () => {+ it("should drop a saved thinking:disabled and keep reasoning_effort 'max' + forced reasoning_content", async () => {await instance.chat({messages: [{ content: 'Hello', role: 'user' },@@ -185,7 +185,7 @@ describe('buildOpenAIPayload Kimi thinking semantics', () => {{ content: 'Follow-up', role: 'user' },],model: 'kimi-k3',- reasoning_effort: 'high',+ reasoning_effort: 'max',thinking: { type: 'disabled' },} as any);@@ -193,12 +193,26 @@ describe('buildOpenAIPayload Kimi thinking semantics', () => {// K3 rejects the `thinking` param entirely: no key must be emitted.expect('thinking' in payload).toBe(false);- // disabled is ignored for native-thinking models, so reasoning_effort passes through.- expect(payload.reasoning_effort).toBe('high');+ // disabled is ignored for native-thinking models; K3 accepts reasoning_effort 'max'.+ expect(payload.reasoning_effort).toBe('max');// assistant messages still get reasoning_content forced (fallback ' ').expect(findAssistantMessage(payload)?.reasoning_content).toBe(' ');});+ it("should drop a non-'max' reasoning_effort for kimi-k3", async () => {+ await instance.chat({+ messages: [{ content: 'Hello', role: 'user' }],+ model: 'kimi-k3',+ reasoning_effort: 'high',+ } as any);++ const payload = getLastRequestPayload();++ // K3 only accepts reasoning_effort 'max' (server default); other values are dropped+ // rather than sent and rejected.+ expect('reasoning_effort' in payload).toBe(false);+ });+it('should not emit thinking even when thinking:enabled is provided', async () => {await instance.chat({messages: [{ content: 'Hello', role: 'user' }],@@ -232,6 +246,19 @@ describe('buildOpenAIPayload Kimi thinking semantics', () => {expect('thinking' in payload).toBe(false);expect(findAssistantMessage(payload)?.reasoning_content).toBe(' ');});++ it("should pass through a non-'max' reasoning_effort unchanged (non-K3 model)", async () => {+ await instance.chat({+ messages: [{ content: 'Hello', role: 'user' }],+ model: 'kimi-k2.7-code',+ reasoning_effort: 'high',+ } as any);++ const payload = getLastRequestPayload();++ // Only K3+ (isKimiReasoningEffortModel) drops non-'max' efforts; k2.7-code keeps full passthrough.+ expect(payload.reasoning_effort).toBe('high');+ });});describe('toggleable K2.x model (kimi-k2.6)', () => {diff --git a/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts b/packages/model-runtime/src/providers/opencodeCodingPlan/index.tsindex 2096827dd50..889806fed94 100644--- a/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts+++ b/packages/model-runtime/src/providers/opencodeCodingPlan/index.ts@@ -385,7 +385,13 @@ const buildOpenAIPayload = (messages,response_format,tools,- ...(!thinkingExplicitlyDisabled && reasoning_effort ? { reasoning_effort } : {}),+ // Kimi K3+ only accepts reasoning_effort 'max' (also the server default) β drop+ // any other saved effort instead of sending a value the API rejects+ ...(!thinkingExplicitlyDisabled &&+ reasoning_effort &&+ (!isKimiReasoningEffortModel(model) || reasoning_effort === 'max')+ ? { reasoning_effort }+ : {}),// K3+ models configure reasoning via top-level reasoning_effort only and// reject the K2.x-only `thinking` param; native-thinking models never get// `disabled` re-emitted (the toggle does not exist for them).