xuanwo on X (tweet 2114748847167815951): Codex on DeepSeek kept ending
"stream disconnected before completion: Incomplete response returned,
reason: max_output_tokens". Codex names no max_output_tokens, magpie
relayed its turn to DeepSeek's /v1/responses as it came, and DeepSeek
reads no limit as 8K without thinking and 64K with it (its
create-chat-completion docs: "When not set, the default is 8K in
non-thinking mode, 64K in thinking mode"), where deepseek-flash and
deepseek-v4-pro give 384K (393216, its /v1/models and pricing page).
Reproduced on api.deepseek.com with the owner's key: deepseek-flash,
effort none, no limit: status incomplete, reason max_output_tokens, at
8192 output tokens; with max_output_tokens 393216: completed at 17602.
- Relayed or translated, a request naming no reply limit, to DeepSeek's
own API (api.deepseek.com, shortByDefault), is sent the model's own
limit (askedOutput: the user's Max output, else the vendor's list or
models.dev, within the window), in the client's words: Responses
max_output_tokens, Chat max_tokens, Gemini generationConfig.
maxOutputTokens. A relay serving DeepSeek's models elsewhere goes as
it came: its default isn't DeepSeek's.
- Translated onto a vendor's Chat or Responses (fillsOutput), a request
naming none is sent the model's own, as on Anthropic's since #1792:
the client's API reads none as the model's whole, a vendor's needn't.
Not for an account's own backend (the ChatGPT one turns
max_output_tokens away) or another magpie (it fills its own). A
vendor that turns the filled figure away ("max_tokens" in a 400/422
that isn't the window) is asked again naming none, and from then on
(outputFillRefused).
- The window: DeepSeek counts the reply asked for in its 1M window. The
existing room retry (replyLeft) asks again for what the window left;
withReplyCap now also adds the field to a Gemini body, which it
couldn't before, so a Gemini client's long conversation isn't
refused where DeepSeek's default fitted.
- A limit the client named goes as it is, everywhere. A reply DeepSeek
cuts on length still reaches Codex as incomplete / max_output_tokens
(relayed as DeepSeek says it; translated by responses.go's length
stop), unchanged.
Tests: TestShortDefaultAsksTheModelsOutput (DeepSeek relayed on
Responses and Chat, the client's own limit kept, a Gemini client
translated, and a relay's Responses and Chat with the same model sent
no limit), TestTranslatedAsksTheModelsOutput (Codex onto a Chat-only
vendor: the catalog's 65536; the client's 700 kept; a vendor refusing
past 32768 is asked again naming none, and not filled again).
Broken by hand: withOwnOutput returning the body as it came turns the
two DeepSeek relayed cases red; fillsOutput false for Chat/Responses
turns the translated case red; the refusal retry off turns the refusal
case red (400 to the client).
Real run (sandbox HOME, only the owner's DeepSeek provider copied, this
build serving on 127.0.0.1:3481): a streamed Codex-shaped Responses turn
to deepseek/deepseek-flash naming no limit, asking for ~17K tokens:
response.completed, 17602 output tokens (8192 and incomplete before, as
above). A 699015-token Codex turn: DeepSeek refused 393216 against its
1M window, magpie asked again with max_output_tokens 349561 (the window
left), response.completed.
Run: gofmt -l clean; go vet ./internal/gateway on darwin, linux and
windows; go test ./internal/gateway (whole package) -count=1
-timeout 45m: ok (465s) at base 479de8900.
Not tried: deepseek-v4-pro with thinking on (64K default) in a real
run, only flash with effort none; a plugin provider for real (its path
is forwardTranslated's, covered by the translated test with an API-key
vendor); other vendors whose Chat default is small (Kimi, GLM, MiniMax)
on their relayed path, which this leaves as it was: only DeepSeek's
default was checked against its docs and its API. The full ./... suite
(only internal/gateway changed).