BigPizzaV3/CodexPlusPlus · error · Error
API 输出达到长度上限,本批未提交;请使用输出容量更大的模型
Error message
API 输出达到长度上限,本批未提交;请使用输出容量更大的模型
What it means
completionText() inspects the Chat Completions response; finish_reason==='length' means the model hit its max output tokens, so the generated batch is incomplete. The script refuses to commit a truncated batch and asks the user to pick a model/output budget with larger capacity.
Solutions
- Switch to a model with a larger output token limit
- Reduce the batch size / number of messages per organize request so output fits
- If provider-side max_tokens is configurable, raise it
- Re-run the organize after changing the model; the batch was not committed
Example fix
// before model: 'gpt-3.5-turbo' // 4k output, truncates // after model: 'gpt-4o' // larger output capacity
Defensive patterns
Strategy: try-catch
Validate before calling
// check after response: body?.choices?.[0]?.finish_reason !== 'length'
Try / catch
try{ await organizeLong(...) }catch(e){ if(e.message.includes('长度上限')){ switchToLargerOutputModel(); retry(); } } Prevention
- Pick models with ≥16k output for large batches
- Keep batches small
- Raise provider max_tokens limits
When it happens
Trigger: An organize batch request returns body.choices[0].finish_reason==='length' — the model stopped because max_tokens/output limit was reached before finishing the JSON batch.
Common situations: Large batch of long messages with a small-output model (e.g. 4k output limit); user set a low max_tokens in provider dashboard; model tends to verbosity and truncates the JSON payload.
Related errors
- API 未能生成本批整理结果
- API 输出达到长度上限,本批未提交;请使用输出容量更大的模型
- API 未返回有效的 choices[0].message.content,请确认兼容 Chat Completions
- 历史轮次分页游标重复
- 历史轮次接口返回格式无效
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/9597956b86b14401.
Report an issue: GitHub.
Appendix: source
Thrown at tools/conversation-canvas/public/canvas.user.js:697
const part=await waitForApi(reader.read(),signal);if(part.done)break;
size+=part.value.byteLength;if(size>4*1024*1024)throw Object.assign(Error('API 响应超过大小限制'),{canvasApiLocal:true});
const text=decoder.decode(part.value,{stream:true});
if(!sse){raw+=text;if(/^\s*(data:|:)/.test(raw)){sse=true;buffer=raw;raw='';}}
else buffer+=text;
if(sse){let end;while((end=buffer.indexOf('\n'))>=0){consume(buffer.slice(0,end).replace(/\r$/,''));buffer=buffer.slice(end+1);}}
progress({bytes:size,chars:content.length});if(done)break;
}
const tail=decoder.decode();if(sse){buffer+=tail;if(buffer.trim())consume(buffer.replace(/\r$/,''));
if(!done&&!finish)throw Object.assign(Error('API 流式连接提前结束,本批未提交'),{canvasApiLocal:true,retryable:true});
return {choices:[{finish_reason:finish,message:{content}}]};
}
try{return JSON.parse(raw+tail);}catch{throw Object.assign(Error('API 返回的不是 JSON,请检查 API 地址'),{canvasApiLocal:true});}
}finally{void reader.cancel().catch(()=>{});try{reader.releaseLock();}catch{}}
}
function completionText(body){
const choice=body?.choices?.[0];
if(choice?.finish_reason==='length')throw Error('API 输出达到长度上限,本批未提交;请使用输出容量更大的模型');
if(choice?.finish_reason==='content_filter'||choice?.message?.refusal)throw Error('API 未能生成本批整理结果');
const content=choice?.message?.content;
const value=typeof content==='string'?content:Array.isArray(content)?content.filter(p=>p?.type==='text').map(p=>p.text||'').join(''):'';
if(!value.trim())throw Error('API 未返回有效的 choices[0].message.content,请确认兼容 Chat Completions');
return value;
}
function waitForApi(promise,signal){
signal?.throwIfAborted();
if(!signal)return promise;
return new Promise((resolve,reject)=>{
const abort=()=>{signal.removeEventListener('abort',abort);reject(signal.reason||new DOMException('Aborted','AbortError'));};
signal.addEventListener('abort',abort,{once:true});
promise.then(value=>{signal.removeEventListener('abort',abort);resolve(value);},error=>{signal.removeEventListener('abort',abort);reject(error);});
});
}
function createApiOrganizer({request,timeoutMs=300000,maxRetries=2,retryDelayMs=2000}){View on GitHub (pinned to b1ed92e5e4)