Errors and retries

Errors use the OpenAI shape: a JSON body with an error object carrying a message and a type. The status code tells you whether to fix the request, wait, or give up.

What each code means

  • 400 - the body does not match the schema: a missing field, a wrong type, a role that does not exist
  • 401 - the key is missing, malformed or revoked
  • 403 - the key is valid but not allowed to use that model or endpoint
  • 404 - the model id is unknown, or the path is wrong
  • 429 - a token quota or a rate limit was hit; the message says which
  • 499 - the client closed the connection before the response finished
  • 502 - the upstream provider failed or timed out after the request was accepted

Which ones are safe to retry

Retry 429 and 502, with backoff and a cap. 429 is a wait; 502 is a provider problem that is usually transient. Retry 499 never - the client is gone, so a retry has nobody to answer.

Never retry 400, 401, 403 or 404 unchanged. They are deterministic: the same request produces the same error, and a retry loop only burns quota.

What is billed

A request rejected for a client error is not charged. Only a successful response, metered by its token usage, draws on the balance. A 502 that never produced an answer is not billed as a completion.

Timeouts deserve care: if the response was generated but the client gave up, the usage exists on the provider side. That is one more reason to stream long answers - a stream that is being read is not a timeout.

Reproducing a failure

Log the status, the error message, the model id and the time of the request. With those four, support can find the exact call; without the time, the search space is every request that day. If you report a problem from the contact page, include them.

Related pages