APIMODELSAPIMODELS

OpenAI API error codes: what each one means and what to do

Updated 2026-11-26

TL;DR Short answer: 4xx errors are yours to fix and retrying the same request will not help, with one exception: a 429 for rate limiting or slow_down clears after a wait. 500 and 503 are on OpenAI's side and are worth retrying with a growing delay. 401 is always the key, the organization or the IP allowlist. 403 is the country you are calling from. 429 has six variants, and four of them are about billing or quota, not speed.

Model page: GPT-6 Sol API — pricing, specs and the playground

An OpenAI API error has three parts worth reading: the HTTP status, error.type and error.code. The status tells you whose problem it is. The code tells you which problem: two 429s can share a status and a type and still need opposite reactions, one wants a wait and the other wants a payment. The message is written for humans and changes over time, so match on the code in your program, not on the text.

The tables below follow OpenAI's error-codes guide as it reads on 26 November 2026. That version lists five status groups, fourteen named API errors and ten exception types in the Python library.

Every OpenAI API error, by status code

StatusErrorCauseFixRetry?
400Invalid service_tier argumentThe service tier you asked for, or the one auto resolved to, is not allowed for the projectSend an allowed tier, or change the project's allowed tiersNo
401Invalid AuthenticationRevoked key, a key from another organization or project, or a key without permission for this endpointCheck the key and organization ID in the request headers; if unsure, create a new keyNo
401Incorrect API key providedTypo or extra space, a deleted or deactivated key, or an old key still cachedCheck the Authorization header; create a new key and update your codeNo
401You must be a member of an organization to use the APIThe account left, was removed from, or lost its organizationGet invited to an organization, or ask an owner to add you to a projectNo
401IP not authorizedThe request came from an IP that is not on the project or organization allowlistCall from an allowed IP, or update the allowlistNo
403Country, region, or territory not supportedThe API is being called from an unsupported locationSee OpenAI's supported countries pageNo
429Rate limit reached for requestsToo many requests or tokens in a short periodWait Retry-After, then pace requestsYes, after a wait
429Slow down (code slow_down)Traffic rose too fast, even inside RPM and TPMReduce the rate, then raise it graduallyYes, once steady
429Credit balance exhausted (credit_balance_exhausted)No prepaid credits leftAdd credits in billing settingsNo
429Organization or project spend limit reachedA monthly spend limit you or an owner set has been hitRaise or remove the limit, or wait for the monthly resetNo
429Organization usage limit reachedThe monthly usage limit OpenAI assigned to the organization has been hitAsk OpenAI for a higher approved limitNo
500The server had an error while processing your requestA fault on OpenAI's serversRetry after a short wait; check the status page; contact support if it continuesYes
503Model temporarily overloaded (server_is_overloaded)The model has no capacity for the request right nowHonor Retry-After, or lengthen the delay between retriesYes, with longer waits

What the OpenAI Python library raises

The library turns HTTP errors into exception classes. Two mappings surprise people: every 429 becomes RateLimitError, including the billing ones, and a 503 becomes InternalServerError. In both cases read error.code to know what actually happened.

ExceptionWhen it is raisedWhat to do
APIConnectionErrorThe request could not reach OpenAI or set up a secure connectionCheck network, proxy, SSL certificates and firewall
APITimeoutErrorThe request took too long and the connection was closedWait briefly and retry
AuthenticationErrorThe key or token is invalid, expired or revokedCheck the key, or create a new one
BadRequestErrorThe request is malformed or missing required parametersRead the message; check parameters, encoding, format and size
ConflictErrorThe resource was changed by another requestRetry the update
InternalServerErrorA problem on OpenAI's side (500, and 503 overload)Retry after a short wait
NotFoundErrorThe resource does not existCheck the resource identifier
PermissionDeniedErrorAccess to the resource is deniedCheck the key, organization ID and resource ID
RateLimitErrorAny 429: rate limit, slow_down, credits, spend or usage limitRead error.code, then wait or go to billing
UnprocessableEntityErrorThe format is valid but the request cannot be processedRetry the request

How to handle errors in code

1. Retry only three things: 429 with a rate-limit or slow_down code, 500 and 503. Everything else needs a change to the request, the key or the account.

2. Wait properly. Use Retry-After as the minimum when it is present; otherwise back off exponentially with a random jitter. Cap the number of attempts and the total time.

3. One retry layer. The SDKs retry on their own. If you wrap them in your own loop, set max_retries to 0 or count the SDK's attempts, because failed requests count towards your rate limit.

4. Log the request ID. Every response carries an x-request-id header; support needs it to look at a specific failure.

5. Treat 401 and 403 as configuration. They do not come and go. A 401 that appears on one machine only is usually an old key in an environment variable or a missing IP allowlist entry.

Errors when you call GPT models through APIMODELS

APIMODELS answers on the same OpenAI-style endpoint, but you are authenticated by an APIMODELS key and billed from an APIMODELS balance, so the errors about OpenAI organizations, IP allowlists, usage tiers and spend limits do not occur. These are the ones you can get instead:

When an upstream route answers with a 429, a 5xx or does not connect before the response starts, the request is sent to the next route for models that have one (GPT-6, GPT-6.1 and GPT-5.6 each have at least two; GPT-6.2 Sol and Astra do not both have a second route yet). You see the upstream error, with its status code, only after every route has failed. Failed requests are not charged.

StatusCode or typeMeaningFix
401invalid_api_keyThe key is missing or not an APIMODELS key (an OpenAI key will not work here)Create a key in the console and send it as Authorization: Bearer
400model_not_foundThe model name is not one we serveUse a model ID from /v1/models or the model's page
400invalid_requestThe body is not valid JSON, or a required field such as model is missingFix the request body
402type insufficient_creditsThe balance cannot cover the request; the message states the amount needed and the balanceLower max_tokens or top up; retrying does not help
404unknown_endpointThe path is not an endpoint we have, often a base_url without /v1Set base_url to https://api.apimodels.app/v1
429none (plain 429, no JSON body)More than 20 POST requests per second on one API key, beyond a burst of 400; answered by the gateway in front of the APISpread requests out

Quick start

cURL

# -i prints the status line and headers, so a 429 shows its Retry-After
curl -i https://api.apimodels.app/v1/chat/completions \
  -H "Authorization: Bearer $APIMODELS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-6-sol",
    "max_tokens": 256,
    "messages": [{"role": "user", "content": "Reply with the word ok."}]
  }'

Python

import openai

# Same OpenAI SDK, pointed at APIMODELS.
client = openai.OpenAI(
    base_url="https://api.apimodels.app/v1",
    api_key="sk_...your_apimodels_key...",
)

try:
    r = client.chat.completions.create(
        model="gpt-6-sol",
        max_tokens=256,
        messages=[{"role": "user", "content": "Reply with the word ok."}],
    )
    print(r.choices[0].message.content)
except openai.AuthenticationError as e:      # 401: fix the key, do not retry
    print("key problem:", e.code, e.message)
except openai.RateLimitError as e:           # 429: read the code before waiting
    print("429:", e.code, "retry-after:", e.response.headers.get("retry-after"))
except openai.BadRequestError as e:          # 400: fix the request
    print("bad request:", e.code, e.message)
except openai.APIStatusError as e:           # 402, 404, 5xx and anything else with a status
    print(e.status_code, e.code, e.message)
except openai.APIConnectionError as e:       # never reached the server
    print("connection problem:", e)

FAQ

What are the OpenAI API error codes?

OpenAI's guide groups them by HTTP status: 400 for an invalid service_tier, 401 for four authentication problems (invalid authentication, incorrect key, no organization, IP not authorized), 403 for an unsupported country, 429 for six rate, credit and limit errors, 500 for a server error and 503 for an overloaded model. Each response also carries error.type and error.code, and the code is what to match on in a program.

What is the difference between a 400 and a 500 error?

A 4xx error means the request, the key or the account needs to change, so sending the same request again returns the same error. A 5xx error means the server failed on a request that may be perfectly valid, so retrying after a wait is the right reaction. On the OpenAI API, 500 is a server fault and 503 is a model without capacity; both are worth retrying, and 503 deserves longer waits.

Which OpenAI API errors should I retry?

Retry 500, 503 and the two temporary 429s ("Rate limit reached for requests" and slow_down). Do not retry 400, 401, 403 or the four 429s about credits, spend limits and usage limits: they return the same answer until you change something. Use Retry-After as the minimum wait, back off exponentially otherwise, and keep a cap on attempts.

What does "Incorrect API key provided" mean?

It is a 401: the key in the Authorization header is not one OpenAI accepts. The usual causes are a typo or a stray space, a key that was deleted or deactivated, a key from a different organization or project, or an old key still held in an environment variable or cache. Check the header your program actually sends, then create a new key if needed. Sending an OpenAI key to another provider's endpoint, or the reverse, produces the same kind of error.

Are the error codes the same when I call GPT models through APIMODELS?

The shape is the same (an error object with a message and a type, and a code on most errors), so OpenAI SDKs raise the same exception classes. The set differs: you get 401 invalid_api_key for a missing or wrong APIMODELS key, 400 model_not_found, 402 insufficient_credits when the balance is short, 404 unknown_endpoint for a wrong path, and a 429 from our gateway above 20 POST requests per second per key. Errors tied to an OpenAI organization, such as spend limits and IP allowlists, do not occur.

Related

Featured on
APIMODELS on Product HuntAPIMODELS featured on ToolifyAPIMODELS featured on There's An AI For That