From 10b4c6983657210997330c580e7002082ae0eee6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 5 Oct 2026 16:48:58 +0000 Subject: [PATCH] Raise MAX_TOKENS_CAP to 64000 for the 3d studio's scenes Oct 5: a scene request failed with "the answer ran out of room". On Claude Opus 5.5 thinking cannot be turned off and counts against max_tokens, and a scene with windows on every house is long JSON; the gateway clamped every request to 16000, so the reply stopped before its JSON closed. Only tokens generated are billed, so the higher cap costs nothing on short answers; the daily limit still counts requests. A test reads wrangler.toml so the cap is not silently lowered again. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015yy9hSCgHQ5WYRZu4JMuW9 --- README.md | 4 ++-- test/worker.test.mjs | 11 +++++++++++ wrangler.toml | 12 ++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 834be8b..bd91321 100644 --- a/README.md +++ b/README.md @@ -147,9 +147,9 @@ With that set, dev sign-in without the right `token` is refused. It still proves ## Sharing one gateway across apps -Two apps use this Worker, and their costs are not comparable: a chess coach comment is a few hundred tokens, while one AI drawing is up to 16000 output tokens plus an uploaded image — two or three orders of magnitude more. The daily limit counts **requests**, not cost, so fifty of each is not fifty of the same thing. Price `DEFAULT_DAILY_LIMIT` against the expensive one. +Two apps use this Worker, and their costs are not comparable: a chess coach comment is a few hundred tokens, while one AI drawing is up to 16000 output tokens plus an uploaded image, and one 3d scene up to 64000 — two or three orders of magnitude more. The daily limit counts **requests**, not cost, so fifty of each is not fifty of the same thing. Price `DEFAULT_DAILY_LIMIT` against the expensive one. -Two settings exist because of the drawing app, and both bite quietly if wrong. `MAX_TOKENS_CAP` is `16000`; requests above it are *clamped, not rejected*, so a cap set too low silently truncates an SVG mid-document instead of erroring. `MAX_BODY_BYTES` is 4 MB because a 768px canvas render arrives as base64 and blows past 256 KB immediately. +Two settings exist because of the drawing app, and both bite quietly if wrong. `MAX_TOKENS_CAP` is `64000` (the 3d studio's scenes need it: Claude's thinking counts against the same limit as the reply); requests above it are *clamped, not rejected*, so a cap set too low silently truncates an SVG or a scene mid-document instead of erroring. `MAX_BODY_BYTES` is 4 MB because a 768px canvas render arrives as base64 and blows past 256 KB immediately. If the two workloads diverge further, give the expensive one its own Worker with its own limit and its own D1 — it is all config, and a second deployment is a `name` change away. diff --git a/test/worker.test.mjs b/test/worker.test.mjs index 0a1d08b..4246e60 100644 --- a/test/worker.test.mjs +++ b/test/worker.test.mjs @@ -651,3 +651,14 @@ test('wrangler.toml allows the GitHub Pages site and no other github.io', async // Public pages sign in here now, so the no-password dev stub must stay off. assert.match(toml, /^DEV_AUTH\s*=\s*"false"/m, 'DEV_AUTH must be "false" in the deployed config'); }); + +/* The cap is clamped silently, so lowering it shows up only as answers cut off + mid-reply: the 3d studio's scenes need 64000 (Claude's thinking counts against + the same limit), the SVG app 16000. */ +test('wrangler.toml leaves room for a whole 3d scene', async () => { + const { readFileSync } = await import('node:fs'); + const toml = readFileSync(new URL('../wrangler.toml', import.meta.url), 'utf8'); + const m = toml.match(/^MAX_TOKENS_CAP\s*=\s*"(\d+)"/m); + assert.ok(m, 'MAX_TOKENS_CAP not found in wrangler.toml'); + assert.ok(+m[1] >= 64000, 'MAX_TOKENS_CAP is ' + m[1] + '; the 3d studio asks for 64000'); +}); diff --git a/wrangler.toml b/wrangler.toml index e4b77a7..caab720 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -79,10 +79,14 @@ DEV_AUTH = "false" ALLOWED_MODELS = "" # empty = any model your key can reach # Ceiling on max_tokens; requests above it are CLAMPED, not rejected — so a cap -# set too low does not error, it silently truncates the answer. 16000 exists -# because the SVG app asks for that much to draw a whole picture; a chess -# comment uses a few hundred. Lower it and long generations get cut off mid-SVG. -MAX_TOKENS_CAP = "16000" +# set too low does not error, it silently truncates the answer. 64000 because +# the 3d studio asks for a whole scene in one reply, and on Claude Opus 5.5 the +# model's thinking (which cannot be turned off) counts against the same limit: +# at 16000 a village with windows on every house ran out before its JSON closed +# (Oct 5, "the answer ran out of room"). The SVG app needs 16000; a chess comment +# a few hundred. Only tokens actually generated are billed, so a high cap costs +# nothing on short answers. Lower it and long generations get cut off mid-reply. +MAX_TOKENS_CAP = "64000" # Largest accepted request body. 4 MB because apps that send an image (the SVG # canvas goes up as a ~768px base64 PNG) blow straight past a 256 KB limit.