Errors use the shape your SDK reads (OpenAI, Anthropic or Gemini), with a readable error.code and error.message.
Retry only 429 and 5xx errors, with backoff between attempts. Never resend after a stream has returned part of the answer.
Key points
- 400/422: invalid request or field.
- 401: API key invalid, revoked or expired.
- 402: wallet balance too low; top up to continue.
- 403: the API key may not use this model, or the IP is not allowed.
- 429: rate limit exceeded; wait a moment and retry.
- 502/503: the model is temporarily unavailable; retry shortly.
- A stream can send an error event or stop before [DONE]; keep what you received and show the error.