Skip to content

Commit 740c580

Browse files
author
Roo Code
committed
fix: resolve moonshotai/kimi-k2-instruct max_tokens limit issue
- Update moonshotai/kimi-k2-instruct maxTokens from 8192 to 16384 to match API limit - Add validation in BaseOpenAiCompatibleProvider to ensure max_tokens never exceeds model limits - Prevent 400 error when users set modelMaxTokens above API constraints Fixes #5729
1 parent 8a3dcfb commit 740c580

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/types/src/providers/groq.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export const groqModels = {
8989
description: "DeepSeek R1 Distill Llama 70B model, 128K context.",
9090
},
9191
"moonshotai/kimi-k2-instruct": {
92-
maxTokens: 8192,
92+
maxTokens: 16384,
9393
contextWindow: 131072,
9494
supportsImages: false,
9595
supportsPromptCache: false,

src/api/providers/base-openai-compatible-provider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
6969
): ApiStream {
7070
const {
7171
id: model,
72-
info: { maxTokens: max_tokens },
72+
info: { maxTokens: modelMaxTokens },
7373
} = this.getModel()
7474

7575
const temperature = this.options.modelTemperature ?? this.defaultTemperature
7676

77+
// Ensure max_tokens doesn't exceed the model's configured limit
78+
// Users can override with modelMaxTokens, but it should not exceed the model's actual API limit
79+
const userMaxTokens = this.options.modelMaxTokens
80+
const max_tokens = userMaxTokens ? Math.min(userMaxTokens, modelMaxTokens) : modelMaxTokens
81+
7782
const params: OpenAI.Chat.Completions.ChatCompletionCreateParamsStreaming = {
7883
model,
7984
max_tokens,

0 commit comments

Comments
 (0)