Envelope
string
Stable, machine-readable error code. This is the contract — branch on
it in your code.
string
Human-readable explanation. Display it to operators, log it, but never
parse it.
string | null
Field that caused the error, when applicable (e.g.
"model", "input.prompt").Codes
Headers worth handling
Recommended retry strategy
1
Honor `Retry-After` first
For
429, 502, 504, sleep for the value of Retry-After (with a
small jitter) before the next attempt.2
Cap retries on terminal codes
400, 401, 403, 404, 422 are user errors — retrying won’t help.
Surface them to the caller.3
Bound everything
Apply an outer deadline on every request and limit retries to e.g. 3
attempts so a degraded backend can’t spiral your client.