From 5a4c0cfcc3d6a4dad7de7f3ffc62664d379f70f2 Mon Sep 17 00:00:00 2001 From: "dayuan.jiang" Date: Mon, 10 Aug 2026 17:00:54 +0900 Subject: [PATCH] fix: always send maxOutputTokens; default 16000 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unset does not mean the model's maximum — the provider fills in its own, and Bedrock's is 4096 (measured: converse with no inferenceConfig on us.anthropic.claude-opus-5 returns stopReason=max_tokens at exactly 4096). A 30-cell diagram is ~3000 tokens of XML, so anything larger arrived as truncated JSON and nothing reached the canvas. Small diagrams fitted, which made it look intermittent. --- app/api/chat/route.ts | 6 +++--- env.example | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index c7de122..ca9f723 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -493,9 +493,9 @@ IMPORTANT: The "Current diagram XML" is the SINGLE SOURCE OF TRUTH for what's on const result = streamText({ model, abortSignal: req.signal, - ...(process.env.MAX_OUTPUT_TOKENS && { - maxOutputTokens: parseInt(process.env.MAX_OUTPUT_TOKENS, 10), - }), + // Must be sent: unset means the provider's own default, and Bedrock's is 4096 — + // enough for a small diagram, so larger ones were cut off mid-attribute. + maxOutputTokens: Number(process.env.MAX_OUTPUT_TOKENS) || 16000, stopWhen: stepCountIs(5), // Repair truncated tool calls when maxOutputTokens is reached mid-JSON experimental_repairToolCall: async ({ toolCall, error }) => { diff --git a/env.example b/env.example index da6ed9a..0155036 100644 --- a/env.example +++ b/env.example @@ -11,6 +11,9 @@ AI_PROVIDER=bedrock # Example: AI_MODEL=doubao-seed-1-8-251215,doubao-seed-1-6-flash,doubao-seed-1-6-pro AI_MODEL=global.anthropic.claude-sonnet-4-5-20250929-v1:0 +# Output limit, all providers (default: 16000). Raise it if large diagrams arrive cut off. +# MAX_OUTPUT_TOKENS=16000 + # AWS Bedrock Configuration # AWS_REGION=us-east-1 # AWS_ACCESS_KEY_ID=your-access-key-id