From 76c3b7201b0e2b773a6c912d1635afe3cbecaed6 Mon Sep 17 00:00:00 2001 From: Loongphy Date: Fri, 28 Aug 2026 19:36:21 +0800 Subject: [PATCH] feat: raise max output tokens to 128K (documented upstream ceiling) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Aliyun Model Studio (the upstream behind Qoder's CN catalog) documents Max Output Length = 131072 for every model we expose, in both normal and thinking modes (thinking chain alone goes to 262144): qwen3.8-max/flash, qwen3.7-max/plus/flash — all 131072. The previous 32768 default (copied from qodercli's conservative 32e3) used only 1/4 of the supported output budget. That truncates reasoning chains in thinking mode (where the chain counts against output) and risks cutting long generations / compaction summaries. qodercli caps its own UI at 65536, still below the documented ceiling. - models.ts: introduce MAX_OUTPUT_TOKENS = 131072 as the single source of truth; all 24 staticModels entries + the lazy-loaded CN entry now reference it. Remove the dead max_output_tokens field from the CN placeholder entry. - stream.ts: maxTokens defaults to MAX_OUTPUT_TOKENS; still capped lower by options.maxTokens (e.g. pi compaction passes 40000). Verified against the real CN endpoint: max_tokens=131072 returns 200 / stop (accepted, not rejected); an xhigh reasoning run completes with finish_reason=stop (not truncated). Field placement + reasoning_effort send also confirmed working in the same request. --- src/models.ts | 64 ++++++++++++++++++++++++++++++--------------------- src/stream.ts | 12 ++++++---- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/models.ts b/src/models.ts index de9827a..f13019b 100644 --- a/src/models.ts +++ b/src/models.ts @@ -13,6 +13,19 @@ import { export const ZERO_COST = Object.freeze({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }); +/** + * Maximum output tokens sent per request. Aliyun Model Studio (the upstream + * behind Qoder's CN catalog) documents Max Output Length = 131072 for every + * model we expose (qwen3.8-max/flash, qwen3.7-max/plus/flash), in both normal + * and thinking modes (thinking chain alone goes up to 262144). The Qoder + * /model/list catalog does not return a per-model output cap, so this single + * constant is the source of truth for both static models and request sending. + * qodercli ships a conservative 32e3 default and caps its UI at 65536; we use + * the documented upstream ceiling so reasoning chains and long generations + * are not truncated. + */ +export const MAX_OUTPUT_TOKENS = 131072; + /** Shape of a single entry returned by the Qoder /model/list endpoint. */ export interface QoderModelEntry { key?: string; @@ -67,7 +80,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 180000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "ultimate", @@ -80,7 +93,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "performance", @@ -93,7 +106,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "efficient", @@ -106,7 +119,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 180000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "lite", @@ -119,7 +132,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text"], cost: ZERO_COST, contextWindow: 180000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "qmodel", @@ -132,7 +145,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "cmodel", @@ -145,7 +158,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "qmodel_preview", @@ -158,7 +171,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "qmodel_latest", @@ -171,7 +184,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "dmodel", @@ -184,7 +197,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "dfmodel", @@ -197,7 +210,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "gm51model", @@ -210,7 +223,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "kmodel", @@ -223,7 +236,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 256000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "kmodel_latest", @@ -236,7 +249,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, { id: "mmodel", @@ -249,7 +262,7 @@ export const staticModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }, ]; @@ -265,7 +278,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 200000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN smart routing; fallback context window of 200K.", }, { @@ -279,7 +292,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN qmodel_latest; context options 200K/400K/1M.", }, { @@ -293,7 +306,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN qmodel; context options 200K/400K/1M.", }, { @@ -307,7 +320,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN q36fmodel; context options 200K/400K/1M.", }, { @@ -321,7 +334,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN dmodel; context options 200K/400K/1M.", }, { @@ -335,7 +348,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text"], cost: ZERO_COST, contextWindow: 1000000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN dfmodel; context options 200K/400K/1M.", }, { @@ -349,7 +362,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 200000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN gm51model; live catalog currently displays GLM-5.2 with 200K context.", }, { @@ -363,7 +376,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text", "image"], cost: ZERO_COST, contextWindow: 256000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN kmodel; context option 256K.", }, { @@ -377,7 +390,7 @@ export const staticCnModels: QoderModelDef[] = [ input: ["text"], cost: ZERO_COST, contextWindow: 200000, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, description: "Qoder CN mmodel; live catalog reports 200K context.", }, ]; @@ -465,7 +478,6 @@ export function getCachedModelConfig(modelKey: string, mode?: string): QoderMode return { key: modelKey, is_reasoning: false, - max_output_tokens: 32768, source: "system", }; } @@ -588,7 +600,7 @@ export async function updateQoderModelsCache( input: isVL ? ["text", "image"] : ["text"], cost: ZERO_COST, contextWindow: ctxLen, - maxTokens: 32768, + maxTokens: MAX_OUTPUT_TOKENS, }); } diff --git a/src/stream.ts b/src/stream.ts index f94d068..3bf0022 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -20,7 +20,7 @@ import { getQoderUserEmailFallback, isQoderCNMode, } from "./cosy.js"; -import { getCachedModelConfig } from "./models.js"; +import { getCachedModelConfig, MAX_OUTPUT_TOKENS } from "./models.js"; import { getCachedCredentials } from "./oauth.js"; import { qoderEncodeBody } from "./qoder-encoding.js"; import { stripThinkingTags, ThinkingTagParser } from "./thinking-parser.js"; @@ -161,10 +161,12 @@ export function streamQoder( ? `${stablePart}-${options.sessionId}` : `${stablePart}-${crypto.randomUUID()}`; - // Qoder's catalog exposes no per-model output cap (no max_output_tokens), - // so we default to 32K (matches qodercli's 32e3 fallback) and let pi cap it - // lower when the caller sets options.maxTokens (e.g. compaction at 40K). - let maxTokens = 32768; + // Qoder's catalog exposes no per-model output cap, so we use the + // documented upstream ceiling (MAX_OUTPUT_TOKENS = 131072, see models.ts) + // and let pi cap it lower when the caller sets options.maxTokens (e.g. + // compaction at 40K). This avoids truncating reasoning chains / long + // generations that the 32K default would cut off. + let maxTokens = MAX_OUTPUT_TOKENS; if (options?.maxTokens && options.maxTokens < maxTokens) { maxTokens = options.maxTokens; }