From cfbdf0604735cdd009a99d79d55a91c36b601b9e Mon Sep 17 00:00:00 2001 From: whale9820 Date: Thu, 9 Jul 2026 15:04:14 +0700 Subject: [PATCH] fix(volcengine-ark): clamp Kimi max_tokens to 32768 endpoint cap VolcEngine Ark caps the Kimi family at max_tokens <= 32768, but the model's advertised ceiling is far higher (Kimi-K2.7-Code resolves to maxOutput 262144), so clampToModelMaxOutput alone leaves it uncapped and the request 400s. Add a Kimi-scoped rule with an explicit maxOutputCap of 32768, combined with the model ceiling via min(). Covers max_tokens, max_completion_tokens, max_output_tokens. Co-Authored-By: Claude Opus 4.8 (1M context) Co-authored-by: Cursor --- open-sse/translator/concerns/paramSupport.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/open-sse/translator/concerns/paramSupport.js b/open-sse/translator/concerns/paramSupport.js index e165c949..7f7283b3 100644 --- a/open-sse/translator/concerns/paramSupport.js +++ b/open-sse/translator/concerns/paramSupport.js @@ -15,6 +15,12 @@ const STRIP_RULES = [ // Cloudflare Workers AI: content must be plain string, rejects OpenAI content-part array (#1926) { provider: "cloudflare-ai", flattenContent: true }, { provider: "volcengine-ark", match: /glm-5/i, clampToModelMaxOutput: true }, + // VolcEngine Ark caps the Kimi family at max_tokens <= 32768, but the model's + // advertised ceiling is far higher (Kimi-K2.7-Code resolves to maxOutput 262144), + // so clampToModelMaxOutput alone leaves it uncapped and the request 400s with + // "integer above maximum value, expected <= 32768". Pin an explicit endpoint cap; + // min() with the model ceiling still applies if a variant's own limit is lower. + { provider: "volcengine-ark", match: /kimi/i, maxOutputCap: 32768, clampToModelMaxOutput: true }, ]; // Test a rule's match (regex or predicate) against the model id. @@ -48,9 +54,17 @@ export function stripUnsupportedParams(provider, model, body) { } } } - if (rule.clampToModelMaxOutput) { - const ceiling = getCapabilitiesForModel(provider, model).maxOutput; - if (Number.isFinite(ceiling) && ceiling > 0) { + if (rule.clampToModelMaxOutput || Number.isFinite(rule.maxOutputCap)) { + const modelCeiling = getCapabilitiesForModel(provider, model).maxOutput; + const candidates = []; + if (rule.clampToModelMaxOutput && Number.isFinite(modelCeiling) && modelCeiling > 0) { + candidates.push(modelCeiling); + } + if (Number.isFinite(rule.maxOutputCap) && rule.maxOutputCap > 0) { + candidates.push(rule.maxOutputCap); + } + if (candidates.length > 0) { + const ceiling = Math.min(...candidates); clampNumber(body, "max_tokens", ceiling); clampNumber(body, "max_completion_tokens", ceiling); clampNumber(body, "max_output_tokens", ceiling);