Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 11 additions & 0 deletions test/worker.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
12 changes: 8 additions & 4 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading