Responses
A declaration says what a successful call resolves to. Usually that is one JSON schema, but it can also depend on the status, or not be JSON at all. This page covers each form, plus how to read the status and headers of a reply.
Failures are a separate topic: see Errors.
One JSON schema
responseSchema validates the body of a 2xx reply and gives the call its type. The call resolves to the schema's output, so transforms and defaults apply.
A body that does not match fails the call with kind response-validation. Your code never receives data that contradicts its type.
A schema in a contract with a Navios server has to accept its own output: see Responses in a shared contract.
A different body per status
When the success body depends on the status, declare responses in place of responseSchema. Each entry is a schema, or null for a status with no body.
The call resolves to the union of every entry, with null contributing undefined. To find out which status came back, use .safe() and read response.status:
A 2xx status that is not listed fails the call with kind response-validation, the same as a body that does not match its entry.
If your API returns different shapes under the same status, describe that in the schema itself with a union, for example z.discriminatedUnion('type', [...]). responses is only for bodies that differ by status.
Non-JSON responses
The response option changes what the call resolves to. For anything but 'json' nothing is validated, so declaring a responseSchema or responses beside it is an error.
Builder asks the HTTP client for the matching body type by setting responseType on the request. Downloads and streams shows blob, text and stream in use.
Status and headers
.safe() exposes the metadata of the reply as response, on success and on failure. It holds status, statusText and a Headers instance. On a failure where nothing came back, it is null.
Three helpers read common headers and accept null, so you can call them without checking first:
Browsers do not let scripts read Set-Cookie, so getCookie is for servers and other runtimes without that rule.
The throwing form resolves to the data alone. Call .safe() when you need the metadata.
Skipping validation
For high-volume reads from a server you trust, validateResponse: false skips the runtime check of the response.
The result is then typed as the schema's input, because transforms and defaults no longer run. Input validation and error handling are unaffected.