Errors & retries
The unified error format and how to back off.
Status codes
| HTTP | Meaning | What to do |
|---|---|---|
| 401 | Key invalid or missing | Check the Authorization header |
| 402 | Balance exhausted | Top up, or claim the starter credit |
| 403 | Key not entitled to this model | Check the key's model scope in the console |
| 429 | Rate limited (RPM/TPM) | Retry with exponential backoff |
| 5xx | Upstream model failure | The gateway cools down the bad channel and retries; you can also back off and retry |
Retry example
import time
for attempt in range(4):
try:
resp = client.chat.completions.create(model="auto", messages=msgs)
break
except Exception as e:
if attempt == 3: raise
time.sleep(2 ** attempt) # 1s 2s 4s