Claude Code asks claude-opus-5-5 for max_tokens 128000. A relay that
holds back max_tokens x price from a key's quota answered 403 "token
quota is not enough ... need $2.59" for every turn (128000 x $20/M plus
~8K input x $4/M). Setting the provider's Max output didn't help: the
gateway lowered max_tokens with withMaxOutput only inside a group
(outputLimit), so a request routed straight to a provider went out as
the agent asked.
userOutput finds the Max output the user set for the provider's model
(provider > model or the provider's "*", Entry.OutputSet) and lowers a
larger request to it on any route. Only the user's own value does this
outside a group: a vendor's catalog figure may be stale. Group routing
is unchanged.
Run:
- TestUserMaxOutputLowersAPlainProvidersRequest (new): 128000 -> 32000
with Max output 32k on the model, 8000 kept, a sibling model with no
Max output kept at 128000. Red without the gateway.go change ("went
as 128000").
- go test ./internal/gateway -count=1 (whole package, -timeout 45m):
ok, 1200s, before rebasing onto 4e9335c96; after the rebase the
Output/MaxTokens tests again: ok.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
- A real Claude Code 2.1.29x against a fake server with the reporter's
env: it sends max_tokens 128000 for claude-opus-5-5 with or without
magpie. Not tried against the reporter's relay.