2xx status code and a JSON body
with a consistent envelope.
Error envelope
A stable, machine-readable code. Branch on this rather than on
message.A human-readable description of the failure. May change; not for branching.
Optional. Field-level validation details, each with a
field and message,
present on some VALIDATION_ERROR responses.Optional. An identifier for the failed request, included on server-side
errors (
5xx). Quote it when reporting an issue.Status codes
| Status | Code | Meaning |
|---|---|---|
400 | VALIDATION_ERROR | The request body is invalid (for example, an empty prompt). |
401 | UNAUTHORIZED | The bearer token is missing, malformed, or expired. |
502 | UPSTREAM_ERROR | A dependency the request relies on was unavailable. Retry. |
503 | DATABASE_ERROR | The request could not be completed. Retry after a short delay. |
Handling errors
- Always check the status code before reading a success body.
- Branch on
error.code, not on the human-readableerror.message. - Retry
502and503with backoff; do not retry400or401without fixing the request first.