Skip to content
All guides

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 StatusCategoryCommon CausesRecommended Action
400 Bad RequestInvalid requestMalformed JSON, empty messages, out-of-range parameters, or context overflowFix request payload per error message; do not retry unchanged
401 UnauthorizedAuthentication failureMissing Bearer prefix, empty environment variable, or revoked API keyVerify server API_KEY configuration
402 / 403Quota or permission deniedProject budget cap reached, model not enabled for key, or IP allowlist blockCheck project quota settings and key model permissions
404 Not FoundWrong URL or Model IDMissing or duplicated /v1 in base_url, or display name passed instead of exact Model IDVerify URL path and copy the canonical Model ID from Models
429 Too Many RequestsRate or concurrency limitRPM, TPM, or concurrent in-flight request limit exceededRetry with exponential backoff + jitter and bound worker concurrency
500 / 502 / 503Transient server errorUpstream compute contention or transient network blipLog the request trace ID and retry 1–3 times with backoff
504 Gateway TimeoutUpstream timeoutNon-streaming call to a deep reasoning or long-output model exceeded proxy idle timeoutEnable 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 openai Python and Node.js SDKs append /chat/completions to base_url, so base_url must include /v1 (e.g., https://gateway.example.com/v1).
  • Some GUI apps append /v1/chat/completions automatically—check the tool's URL preview if a valid Model ID returns 404.

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.