OpenAI API error codes: what each one means and what to do
Updated 2026-11-26
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
| Status | Error | Cause | Fix | Retry? |
|---|---|---|---|---|
| 400 | Invalid service_tier argument | The service tier you asked for, or the one auto resolved to, is not allowed for the project | Send an allowed tier, or change the project's allowed tiers | No |
| 401 | Invalid Authentication | Revoked key, a key from another organization or project, or a key without permission for this endpoint | Check the key and organization ID in the request headers; if unsure, create a new key | No |
| 401 | Incorrect API key provided | Typo or extra space, a deleted or deactivated key, or an old key still cached | Check the Authorization header; create a new key and update your code | No |
| 401 | You must be a member of an organization to use the API | The account left, was removed from, or lost its organization | Get invited to an organization, or ask an owner to add you to a project | No |
| 401 | IP not authorized | The request came from an IP that is not on the project or organization allowlist | Call from an allowed IP, or update the allowlist | No |
| 403 | Country, region, or territory not supported | The API is being called from an unsupported location | See OpenAI's supported countries page | No |
| 429 | Rate limit reached for requests | Too many requests or tokens in a short period | Wait Retry-After, then pace requests | Yes, after a wait |
| 429 | Slow down (code slow_down) | Traffic rose too fast, even inside RPM and TPM | Reduce the rate, then raise it gradually | Yes, once steady |
| 429 | Credit balance exhausted (credit_balance_exhausted) | No prepaid credits left | Add credits in billing settings | No |
| 429 | Organization or project spend limit reached | A monthly spend limit you or an owner set has been hit | Raise or remove the limit, or wait for the monthly reset | No |
| 429 | Organization usage limit reached | The monthly usage limit OpenAI assigned to the organization has been hit | Ask OpenAI for a higher approved limit | No |
| 500 | The server had an error while processing your request | A fault on OpenAI's servers | Retry after a short wait; check the status page; contact support if it continues | Yes |
| 503 | Model temporarily overloaded (server_is_overloaded) | The model has no capacity for the request right now | Honor Retry-After, or lengthen the delay between retries | Yes, 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.
| Exception | When it is raised | What to do |
|---|---|---|
| APIConnectionError | The request could not reach OpenAI or set up a secure connection | Check network, proxy, SSL certificates and firewall |
| APITimeoutError | The request took too long and the connection was closed | Wait briefly and retry |
| AuthenticationError | The key or token is invalid, expired or revoked | Check the key, or create a new one |
| BadRequestError | The request is malformed or missing required parameters | Read the message; check parameters, encoding, format and size |
| ConflictError | The resource was changed by another request | Retry the update |
| InternalServerError | A problem on OpenAI's side (500, and 503 overload) | Retry after a short wait |
| NotFoundError | The resource does not exist | Check the resource identifier |
| PermissionDeniedError | Access to the resource is denied | Check the key, organization ID and resource ID |
| RateLimitError | Any 429: rate limit, slow_down, credits, spend or usage limit | Read error.code, then wait or go to billing |
| UnprocessableEntityError | The format is valid but the request cannot be processed | Retry 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.
| Status | Code or type | Meaning | Fix |
|---|---|---|---|
| 401 | invalid_api_key | The 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 |
| 400 | model_not_found | The model name is not one we serve | Use a model ID from /v1/models or the model's page |
| 400 | invalid_request | The body is not valid JSON, or a required field such as model is missing | Fix the request body |
| 402 | type insufficient_credits | The balance cannot cover the request; the message states the amount needed and the balance | Lower max_tokens or top up; retrying does not help |
| 404 | unknown_endpoint | The path is not an endpoint we have, often a base_url without /v1 | Set base_url to https://api.apimodels.app/v1 |
| 429 | none (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 API | Spread 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.
