A request body is bounded before anything is parsed
The cheapest refusals come first. A body that is too large, too deeply nested, or not JSON at all is turned away before any workflow-level meaning is read out of it.
The rule
- A request body MUST be JSON whose top level is an object or an array.
- Every endpoint that takes a JSON body MUST support the media type
application/json. - A media type of
application/jsonwith parameters, such ascharset=utf-8, MUST be treated asapplication/json. - A request that carries content with no
Content-Type, or with a media type the endpoint does not support, MUST be refused with 415. - That refusal MUST be made whatever the body holds, so it is answered ahead of every other check of the body.
- A body that exceeds 8 MiB of octets MUST be refused with 413.
- It MAY be refused without being read whole.
- A body that is empty where the endpoint requires one, is not well-formed JSON, or nests 64 levels or deeper MUST be refused with 400.
- A body nested too deep is refused like a broken one because an implementation may stop reading at the depth limit, and so cannot always tell a body nested too deep from one that is broken further on.
- A body that is both over the size limit and unreadable MAY be refused with either 413 or 400.
- A body that was read but whose top level is a scalar (
nullincluded) MUST be refused with 422. - Nothing is stored when a body is refused.
- An implementation MUST accept a document nested 63 levels deep.
- Every refusal here MUST carry the
error_code(API-8) that goes with its status:UNSUPPORTED_MEDIA_TYPEwith 415,REQUEST_BODY_TOO_LARGEwith 413, andINVALID_REQUEST_BODYwith 400 and with the 422 for a scalar top level.
What it means
This is the storage endpoints' own copy of the gate API-1 describes: the same checks, with the numbers fixed. A body sent as something other than JSON, over 8 MiB, malformed, nested 64 levels or deeper, or not an object or array at its top level never reaches workflow-level meaning.
Each check has its own status, and the line between them is one question: could a
JSON value be read from the body within the limits? A body sent under the wrong
media type is 415, decided on the headers alone; application/json; charset=utf-8
is application/json. A body too large is 413, and
the endpoint may stop reading it once it knows. A body that could not be read (empty
where one is required, broken, or nested too deep) is 400. A body that was read but is a bare scalar is
422: it is well-formed, just not something an endpoint can take fields from.
Each refusal also carries a code, so a client never reads the message to tell
them apart: UNSUPPORTED_MEDIA_TYPE for 415, REQUEST_BODY_TOO_LARGE for
413, and INVALID_REQUEST_BODY for 400 and for the scalar's 422. The scalar
shares the unreadable bodies' code because, to a caller, both are a body the
endpoint could not take fields from; the status still says which it was.
Depth sits with the unreadable bodies, not with the scalar, for a practical reason.
Many JSON parsers enforce the depth limit themselves and stop there with an error,
so an implementation cannot always say whether the rest of the body would have
parsed. Putting depth on the 400 side means it gets the same answer however it is
caught.
The depth bound is easy to get off by one. The bound is a maximum depth, so a document nested 64 levels deep is already one level past what is accepted; every implementation accepts a document nested 63 levels deep, and no deeper is promised.
The other clause that bites is the one API-1 states in general and this rule makes concrete: an endpoint whose body is optional is not an endpoint the gate skips. An absent body is fine, but a body that is present and malformed is refused like any other — the gate does not degrade "nothing to check" into "nothing checked".
Example
An endpoint whose body is optional still runs whatever is actually sent through the same gate as any other endpoint.
POST /api/flowdrop/workflows/{workflow_id}/playground/sessions
5POST /api/flowdrop/workflows/{workflow_id}/playground/sessions
{"name": "unterminatedSending nothing at all to this same endpoint is still accepted — the gate's bounds apply to what is sent, not to whether something was sent.