What to retry
| Result | Retry? |
|---|---|
| Timeout or dropped connection | Yes |
| 429 | Yes, and honor Retry-After if it's sent |
| 500, 502, 503, 504, 522 | Yes |
| 401, 404, 405 | No, fix the request |
With the OpenAI SDKs
Both official SDKs already retry 408, 409, 429 and 5xx responses with backoff (checked in openai Python 3.22.1 and Node.js 7.25.0). Python defaults to 2 retries. Raise it if you'd rather wait than fail:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.luv13.ai/v1",
api_key=os.environ["LUV13_API_KEY"],
max_retries=5,
timeout=120,
)In Node.js, pass maxRetries: 5 to new OpenAI({...}).
With curl
curl --retry 5 --retry-delay 0 --retry-max-time 120 \
https://api.luv13.ai/v1/chat/completions \
-H "Authorization: Bearer $LUV13_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "luv13/glm-5.3-flash", "messages": [{"role": "user", "content": "ping"}]}'--retry-delay 0 keeps curl's own doubling backoff. curl retries timeouts, 408, 429, 500, 502, 503, 504 and a few other codes, but not 522. For 522, use a loop or the SDKs.
