OpenAI chat list of error codes and types

Hello guys, does anyone have the list of all possible error codes and types that can be returned from the api, since i’m building an integration i want to handle each error differently, for example if i get a rate limit error i can back-off and try the request again, if i get a tokens exceeded the allowed amount error i can cut down my messages. this is an example of the response, i’m wondering if any one have all the possible error responses :
‘type’ => ‘invalid_request_error’,
‘code’ => ‘***’

1 Like

Hi @omar.essaouaf
these are some of the errors u encountered while using the API:
1 invalid_request_error (Code: 400)
2 rate_limit_error (Code: 429)
3 tokens_exceeded_error (Code: 403)
4 authentication_error (Code: 401)
5 not_found_error (Code: 404)
6 server_error (Code: 500)
7 permission_error (Code: 403)

Thank you @Innovatix , how about the codes of the errors ?

Here’s a link for Python errors but it also has general API errors and their codes:

Thank you, tho i’m not talking about http status codes, i’m talking about a specific string that the api send back, something like this :
‘type’ => ‘invalid_request_error’,
‘code’ => ‘***’

APIError Cause Issue on OpenAI side.
Timeout Cause Request timed out.
APIConnectionError Cause Issue connecting to our services.
InvalidRequestError Cause: Your request was malformed or missing some required parameters.
AuthenticationError Cause Your API key or token was invalid, expired, or revoked.
PermissionError Cause Your API key or token does not have the required permissions
RateLimitError Cause You have hit your assigned rate limit.
ServiceUnavailableError Cause Issue on our servers.

1 Like

guys i’m hitting the api with PHP not the python library, so when i get an error it’s returned in the format posted in the topic

It looks like the only translation needed is to add underscores between words and make it all lowercase, so that list should still be valid.

Yes i think so, but the code property is missing from that list and from the documentation

Indeed, I don’t see the code property listed, unless it’s within the hyper link locations.

Sorry😞for the delay in my response Omar. While the OpenAI API may not provide error responses in the exact format you mentioned, error types

  • APIError 2: This error indicates an issue on the OpenAI side.
  • Timeout: It occurs when a request timed out.
  • APIConnectionError: This error is caused by issues connecting to our services.
  • InvalidRequestError: It occurs when your request was malformed or missing some required parameters.
  • AuthenticationError: This error is caused by an invalid, expired, or revoked API key or token.
  • PermissionError: It happens when your API key or token lacks the required permissions.
  • RateLimitError: This error is triggered when you’ve hit your assigned rate limit.
  • ServiceUnavailableError: This error is caused by issues on our servers.

error codes in your PHP integration, you can use the below mappings:

$errorMappings = [
    'invalid_request_error' => [
        'code' => '400',
        'description' => 'Your request was malformed or missing some required parameters.',
    'rate_limit_error' => [
        'code' => '429',
        'description' => 'You have hit your assigned rate limit.',
    'tokens_exceeded_error' => [
        'code' => '403',
        'description' => 'You have exceeded the allowed number of tokens in your request.',
    'authentication_error' => [
        'code' => '401',
        'description' => 'Your API key or token was invalid, expired, or revoked.',
    'not_found_error' => [
        'code' => '404',
        'description' => 'The requested resource was not found.',
    'server_error' => [
        'code' => '500',
        'description' => 'An issue occurred on the OpenAI server side.',
    'permission_error' => [
        'code' => '403',
        'description' => 'Your API key or token lacks the required permissions for the requested action.',

// You can access the error details hhere:
$errorType = 'rate_limit_error';
$errorCode = $errorMappings[$errorType]['code'];
$errorDescription = $errorMappings[$errorType]['description'];

Omar, I hope this helps!

Made up AI hallucinations and chatbot pastes like above don’t help.

The exact messages undergo alteration by OpenAI. One could not anticipate a 200 - “deprecated warning” would be text added to a response, for example.

We can use text added to a response as a temporary workaround until OpenAI updates their documentation and releases a robust error handling mechanism for PHP. this is not a good practise but we have use it for now😟! using a custom error handler is not considered a best practice in PHP, it is currently our only option. It is better than not handling errors at all.