Repository navigation
Description
Summary
On the Provider API (POST /provider/v1/chat/completions), a long, tool-heavy session gets a deterministic 400 with an opaque message and no param:
{"error":{"message":"{\"error\":{\"message\":\"Request validation failed.\",\"type\":\"invalid_request_error\",\"code\":\"400\"}}","type":"invalid_request_error"}}Note the message is a JSON string nested inside the message field — so the client sees an error whose text is another JSON document, with "code":"400" (not the usual param-bearing body). There is nothing for the caller to act on: no field path, no trace id, no documented limit to compare against.
Impact
A single session becomes permanently unusable: the client rebuilds the same history on every retry, so every subsequent turn fails the same way. Users have to abandon the conversation and start a new one.
Evidence
Captured the exact request body that fails (tcpdump on the loopback hop of our gateway, body reassembled and replayed):
- model:
deepseek/deepseek-v4.1-flash - body: 3.7–3.9 MB
- messages: ~220 (
1 system / 52–59 user / 124–196 assistant / 119–191 tool) - tools: 39 function tools, no duplicate names
max_tokens: 128000,stream: true,stream_options.include_usage: true- 8–9
image_urlparts (real PNG/JPEG data URLs, in user messages) - every assistant message carries
reasoning_content
The same body is accepted by the DeepSeek official API (200), and by another account in the same pool, so the payload itself is well-formed. Only the Command Code lane rejects it — and only for sessions of this size; smaller requests with the same tools/model return 200.
What we already ruled out (all return 200 on CC)
- duplicate
function.nameintools(CC rejects this, but with a different error) tool_choicepointing at an unknown tool (also a different error)max_tokens8k → 128k- single message bodies up to 5 MB, and up to ~400k tokens of real text
- images up to 7.6 MB as data URLs, including inside
toolmessages reasoning_contenton user / assistant / tool / system messages, and as array (array is rejected with aparam, string is fine)- null-valued fields:
parallel_tool_calls,tool_choice,max_tokens,temperature,top_p— these all produce a usefulparamerror, which is what we'd expect here too
Ask
- Is there a documented limit on request body size / token count / message count for
/chat/completions? If yes, which one, and can the error become explicit (paramorcode) instead ofRequest validation failed.? - If the nested
"code":"400"string is coming from an upstream lane rather than your validator, can that be surfaced distinctly? - Any chance of a trace/request id in the 400 body? We can supply full request bodies (privacy-scrubbed) plus timestamps if it helps.
Related issues
- HTTP 400 missing messages[N].reasoning_content after context compaction (long sessions) #1121 — long sessions +
reasoning_contenthandling around compaction - Provider API: tool JSON-Schema pattern with \0 escape kills the whole request — DeepSeek lane 502/overloaded_error (Claude Code Artifact tool affected) #1156 — a single tool JSON-Schema
patternkilling the whole request on the DeepSeek lane
Both point at the same shape: one field in a large request kills the entire call, and the failure is hard to attribute.
Activity