{"text": "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.\n\n\n\n\n| | |\n| --- | --- |\n| [APIError](https://help.openai.com/en/articles/6897179-apierror) | **Cause** Issue on our side.\n**Solution** Retry your request after a brief wait and contact us if the issue persists. |\n| [Timeout](https://help.openai.com/en/articles/6897186-timeout) | **Cause** Request timed out.\n**Solution** Retry your request after a brief wait and contact us if the issue persists. |\n| [APIConnectionError](https://help.openai.com/en/articles/6897191-apiconnectionerror) | **Cause** Issue connecting to our services.\n**Solution** Check your network settings, proxy configuration, SSL certificates, or firewall rules. |\n| [InvalidRequestError](https://help.openai.com/en/articles/6897194-invalidrequesterror) | **Cause:** Your request was malformed or missing some required parameters, such as a token or an input.\n**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. |\n| [AuthenticationError](https://help.openai.com/en/articles/6897198-authenticationerror) | **Cause** Your API key or token was invalid, expired, or revoked.\n**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. |\n| [PermissionError](https://help.openai.com/en/articles/6897199-permissionerror)\n | **Cause** Your API key or token does not have the required scope or role to perform the requested action.\n**Solution** Make sure your API key has the appropriate permissions for the action or model accessed. |\n| [RateLimitError](https://help.openai.com/en/articles/6897202-ratelimiterror)\n | **Cause** You have hit your assigned rate limit. \n**Solution** Pace your requests. Read more [here](https://help.openai.com/en/articles/6891753-rate-limit-advice). |\n| [ServiceUnavailableError](https://help.openai.com/en/articles/6897204-serviceunavailableerror) | **Cause** Issue on our servers.\n**Solution** Retry your request after a brief wait and contact us if the issue persists. |\n\nWe advise you to programmatically handle errors returned by the API. To do so, you may wish to use a code snippet like below:\n\n\n\n\n```\ntry: \n #Make your OpenAI API request here \n response = openai.Completion.create(model=\"text-davinci-003\", \n prompt=\"Hello world\") \nexcept openai.error.Timeout as e: \n #Handle timeout error, e.g. retry or log \n print(f\"OpenAI API request timed out: {e}\") \n pass \nexcept openai.error.APIError as e: \n #Handle API error, e.g. retry or log \n print(f\"OpenAI API returned an API Error: {e}\") \n pass \nexcept openai.error.APIConnectionError as e: \n #Handle connection error, e.g. check network or log \n print(f\"OpenAI API request failed to connect: {e}\") \n pass \nexcept openai.error.InvalidRequestError as e: \n #Handle invalid request error, e.g. validate parameters or log \n print(f\"OpenAI API request was invalid: {e}\") \n pass \nexcept openai.error.AuthenticationError as e: \n #Handle authentication error, e.g. check credentials or log \n print(f\"OpenAI API request was not authorized: {e}\") \n pass \nexcept openai.error.PermissionError as e: \n #Handle permission error, e.g. check scope or log \n print(f\"OpenAI API request was not permitted: {e}\") \n pass \nexcept openai.error.RateLimitError as e: \n #Handle rate limit error, e.g. wait or log \n print(f\"OpenAI API request exceeded rate limit: {e}\") \n pass\n```\n\n", "title": "OpenAI Library Error Types Guidance", "article_id": "6897213", "url": "https://help.openai.com/en/articles/6897213-openai-library-error-types-guidance"}