Skip to content

Error Codes

On error, the endpoint returns the standard OpenAI error structure:

json
{
  "error": {
    "message": "a specific error description",
    "type": "invalid_request_error",
    "code": "model_not_found"
  }
}

HTTP status codes

HTTP statusMeaningCommon causes & handling
400Bad requestMissing parameters, malformed JSON, or values out of a model's limits. Fix the body per the message field
401UnauthorizedMissing, wrong, or disabled token. Check the Authorization header
403Forbidden / out of quotaToken quota exhausted, model not in the allowed group, or IP not allowed. Check the token settings and balance in the console
404Not foundMisspelled model name or non-existent path. Verify the model ID with /v1/models
422Validation failedBody is well-formed but a value is invalid. Adjust per message
429Too many requestsRate limit hit. Retry with exponential backoff
500Server errorInternal platform error. Retry later; contact support if it persists
503Upstream unavailableUpstream channel is fluctuating. Retry later or switch models if it persists

Error types (type)

typeDescription
invalid_request_errorInvalid request parameters
authentication_errorAuthentication failed
permission_errorNo permission to access the resource
not_found_errorResource does not exist
rate_limit_errorRate limited
api_errorInternal API error
overloaded_errorService overloaded

Common error codes (code)

codeDescription
invalid_api_keyInvalid API key
model_not_foundModel does not exist or is not accessible
context_length_exceededInput exceeds the model's maximum context length
max_tokens_exceededmax_tokens exceeds the model's limit
insufficient_quotaInsufficient account balance
rate_limit_exceededRequest frequency too high
content_filterContent blocked by the safety filter

Retry advice

For 429 and 5xx errors, use exponential backoff:

python
import time

def chat_with_retry(client, max_retries=3, **kwargs):
    for attempt in range(max_retries):
        try:
            return client.chat.completions.create(**kwargs)
        except Exception as e:
            if attempt == max_retries - 1:
                raise
            wait = 2 ** attempt  # 1s, 2s, 4s
            print(f"request failed, retrying in {wait}s... ({e})")
            time.sleep(wait)

WARNING

For client errors like 400, 401, 403, and 404, retrying is pointless — check the request parameters or token configuration instead.

OpenAI-compatible · Multimodal AI gateway