Skip to content

Error Codes

When an API request fails, the response includes an HTTP status code and an error message. Here are the common errors and how to resolve them.

CodeNameDescriptionResolution
400Bad RequestInvalid request format or parametersCheck your request body and parameters
401UnauthorizedMissing or invalid API keyVerify your Authorization: Bearer header
403ForbiddenAPI key lacks permission for this resourceCheck your plan tier or contact support
404Not FoundInvalid endpoint or model not foundVerify the URL and model name
429Too Many RequestsRate limit exceededWait and retry with exponential backoff
500Internal Server ErrorServer-side errorRetry after a brief delay
503Service UnavailableModel is temporarily unavailableCheck Model Status and retry
{
"detail": "Incorrect API key provided"
}

When you hit a rate limit, implement exponential backoff:

import time
from openai import OpenAI, RateLimitError
client = OpenAI()
def call_with_retry(messages, max_retries=3):
for attempt in range(max_retries):
try:
return client.chat.completions.create(
model="Llama-3.3-70B-Instruct",
messages=messages,
)
except RateLimitError:
wait = 2 ** attempt
print(f"Rate limited. Retrying in {wait}s...")
time.sleep(wait)
raise Exception("Max retries exceeded")
  • Verify the model name matches exactly (case-sensitive)
  • Use the List Models API to check available models
  • Some models may only be available on certain plan tiers
  • Ensure the key is correctly set in your environment
  • Check that the key hasn’t expired
  • Visit the API Key Portal to manage keys
  • Reduce the input length or set a lower max_tokens
  • Check the model’s max_sequence_length in the model metadata