Errors & retries

The unified error format and how to back off.

Status codes

HTTPMeaningWhat to do
401Key invalid or missingCheck the Authorization header
402Balance exhaustedTop up, or claim the starter credit
403Key not entitled to this modelCheck the key's model scope in the console
429Rate limited (RPM/TPM)Retry with exponential backoff
5xxUpstream model failureThe 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