Troubleshooting & FAQ
Error Codes, Rate Limits & Troubleshooting
Look up HTTP status codes, configure timeouts and exponential backoff, and isolate request failures.
Updated 2026-11-26 · 3 min read
HTTP Status Code Reference
When an API request fails, the gateway returns an HTTP status code paired with a structured JSON error body. Always distinguish non-retryable client errors (400–404) from transient capacity or rate-limit responses (429, 5xx):
| HTTP Status | Category | Common Causes | Recommended Action |
|---|---|---|---|
400 Bad Request | Invalid request | Malformed JSON, empty messages, out-of-range parameters, or context overflow | Fix request payload per error message; do not retry unchanged |
401 Unauthorized | Authentication failure | Missing Bearer prefix, empty environment variable, or revoked API key | Verify server API_KEY configuration |
402 / 403 | Quota or permission denied | Project budget cap reached, model not enabled for key, or IP allowlist block | Check project quota settings and key model permissions |
404 Not Found | Wrong URL or Model ID | Missing or duplicated /v1 in base_url, or display name passed instead of exact Model ID | Verify URL path and copy the canonical Model ID from Models |
429 Too Many Requests | Rate or concurrency limit | RPM, TPM, or concurrent in-flight request limit exceeded | Retry with exponential backoff + jitter and bound worker concurrency |
500 / 502 / 503 | Transient server error | Upstream compute contention or transient network blip | Log the request trace ID and retry 1–3 times with backoff |
504 Gateway Timeout | Upstream timeout | Non-streaming call to a deep reasoning or long-output model exceeded proxy idle timeout | Enable stream: true (SSE) and raise client read timeout |
Bounded Exponential Backoff with Jitter
Never retry 400, 401, 403, or 404 responses in a loop. Restrict automatic retries to 429 and transient 5xx errors with randomized jitter to prevent thundering-herd spikes:
import random
import time
from openai import APIStatusError, APITimeoutError
RETRYABLE_STATUS = {429, 500, 502, 503, 504}
def call_with_backoff(fn, max_attempts=4):
for attempt in range(max_attempts):
try:
return fn()
except APITimeoutError:
if attempt == max_attempts - 1:
raise
except APIStatusError as err:
if err.status_code not in RETRYABLE_STATUS or attempt == max_attempts - 1:
raise
sleep_seconds = min(16.0, (2 ** attempt) + random.uniform(0.1, 0.8))
time.sleep(sleep_seconds)Resolving /v1 Path Mismatches (404)
Most 404 integration issues in third-party tools stem from /v1 path handling:
- Official
openaiPython and Node.js SDKs append/chat/completionstobase_url, sobase_urlmust include/v1(e.g.,https://gateway.example.com/v1). - Some GUI apps append
/v1/chat/completionsautomatically—check the tool's URL preview if a valid Model ID returns404.
Minimal cURL Isolation Check
When debugging errors hidden beneath framework abstractions, run a minimal curl -i probe from the same host to inspect raw status codes and headers:
curl -i --request POST "${API_BASE_URL}/chat/completions" --header "Authorization: Bearer ${API_KEY}" --header "Content-Type: application/json" --data '{"model":"deepseek-v3.2","messages":[{"role":"user","content":"ping"}],"max_tokens":16}'When escalating an issue, record the timestamp, Model ID, HTTP status code, and response request ID—and always scrub your API_KEY first. See Frequently Asked Questions for additional guidance.