Skip to main content
OpenAI Library Error Types Guidance

A quick guide to errors returned in our Python library.

Updated over a year ago

This article outlines the error types returned when using the OpenAI Python Library. Read a summary of the cause and solution, or click the article for more.

Cause Issue on our side.

Solution Retry your request after a brief wait and contact us if the issue persists.

Cause Request timed out.

Solution Retry your request after a brief wait and contact us if the issue persists.

Cause Issue connecting to our services.

Solution Check your network settings, proxy configuration, SSL certificates, or firewall rules.

Cause: Your request was malformed or missing some required parameters, such as a token or an input.

Solution: The error message should advise you on the specific error made. Check the documentation for the specific API method you are calling and make sure you are sending valid and complete parameters. You may also need to check the encoding, format, or size of your request data.

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 account dashboard.

Cause Your API key or token does not have the required scope or role to perform the requested action.

Solution Make sure your API key has the appropriate permissions for the action or model accessed.

Cause You have hit your assigned rate limit.

Solution Pace your requests. Read more here.

Cause Issue on our servers.

Solution Retry your request after a brief wait and contact us if the issue persists.

We advise you to programmatically handle errors returned by the API. To do so, you may wish to use a code snippet like below:

try:
#Make your OpenAI API request here
response = openai.Completion.create(model="text-davinci-003",
prompt="Hello world")
except openai.error.Timeout as e:
#Handle timeout error, e.g. retry or log
print(f"OpenAI API request timed out: {e}")
pass
except openai.error.APIError as e:
#Handle API error, e.g. retry or log
print(f"OpenAI API returned an API Error: {e}")
pass
except openai.error.APIConnectionError as e:
#Handle connection error, e.g. check network or log
print(f"OpenAI API request failed to connect: {e}")
pass
except openai.error.InvalidRequestError as e:
#Handle invalid request error, e.g. validate parameters or log
print(f"OpenAI API request was invalid: {e}")
pass
except openai.error.AuthenticationError as e:
#Handle authentication error, e.g. check credentials or log
print(f"OpenAI API request was not authorized: {e}")
pass
except openai.error.PermissionError as e:
#Handle permission error, e.g. check scope or log
print(f"OpenAI API request was not permitted: {e}")
pass
except openai.error.RateLimitError as e:
#Handle rate limit error, e.g. wait or log
print(f"OpenAI API request exceeded rate limit: {e}")
pass

Did this answer your question?