Error Codes - OpenAI API
Error Codes - OpenAI API
Error codes
This guide includes an overview on error codes you might see from both the API and our
official Python library. Each error code mentioned in the overview has a dedicated section with
further guidance.
API errors
CODE OV E RV I E W
401 - Incorrect API key provided Cause: The requesting API key is not correct.
Solution: Ensure the API key used is correct, clear your
browser cache, or generate a new one.
401 - You must be a member of an Cause: Your account is not part of an organization.
organization to use the API Solution: Contact us to get added to a new organization
or ask your organization manager to invite you to an
organization.
403 - Country, region, or territory not Cause: You are accessing the API from an unsupported
supported country, region, or territory.
Solution: Please see this page for more information.
429 - Rate limit reached for requests Cause: You are sending requests too quickly.
Solution: Pace your requests. Read the Rate limit guide.
429 - You exceeded your current Cause: You have run out of credits or hit your maximum
quota, please check your plan and monthly spend.
billing details Solution: Buy more credits or learn how to increase
your limits.
500 - The server had an error while Cause: Issue on our servers.
processing your request Solution: Retry your request after a brief wait and
p gy q yy q
CODE OV E RV I E W
contact us if the issue persists. Check the status page.
503 - The engine is currently Cause: Our servers are experiencing high traffic.
overloaded, please try again later Solution: Please retry your requests after a brief wait.
429 - You exceeded your current quota, please check your plan and
billing details
AuthenticationError Cause: Your API key or token was invalid, expired, or revoked.
Solution: Check your API key or token and make sure it is correct
and active. You may need to generate a new one from your
t d hb d
TYPE account dashboard.
OV E RV I E W
UnprocessableEntityError Cause: Unable to process the request despite the format being
correct.
Solution: Please try the request again.
APIConnectionError
APITimeoutError
AuthenticationError
B dR E
BadRequestError
InternalServerError
RateLimitError
Persistent errors
If the issue persists, contact our support team via chat and provide them with the following
information:
Our support team will investigate the issue and get back to you as soon as possible. Note that
our support queue times may be long due to high demand. You can also post in our
Community Forum but be sure to omit any sensitive information.
Handling errors
We advise you to programmatically handle errors returned by the API. To do so, you may want
to use a code snippet like below:
1 import openai
2 from openai import OpenAI
3 client = OpenAI()
4
5 try:
6 #Make your OpenAI API request here
7 response = client.completions.create(
8 prompt="Hello world",
9 model="gpt-3.5-turbo-instruct"
10 )
11 except openai.APIError as e:
12 #Handle API error here, e.g. retry or log
13 print(f"OpenAI API returned an API Error: {e}")
14 pass
15 except openai.APIConnectionError as e: