Skip to main content
Version: Next

OpenAIError Class

The OpenAIError class is designed to handle errors returned by the OpenAI API. It extracts relevant information from the error response and provides methods to access this information.

Properties

Error properties

PropertyTypeDescription
errCodeIntegerThe error code returned by the API or the HTTP status.
messageTextThe error message returned by the API or the HTTP status text.

HTTP reponse properties

PropertyTypeDescription
responseObjectThe full response object.
statusIntegerThe HTTP status code of the response.
statusTextTextThe status text of the HTTP response.
bodyObjectThe body of the error response.
headersObjectThe headers of the error response.
requestIDTextThe request ID from the error response headers.

OpenAI specific

PropertyTypeDescription
codeVariantThe code of error returned by the API.
typeTextThe type of error returned by the API.
paramTextThe parameter that caused the error, if applicable.

HTTP status code info

PropertyTypeDescription
isBadRequestErrorBooleanIndicates if the error is a 400 Bad Request error.
isAuthenticationErrorBooleanIndicates if the error is a 401 Authentication error.
isPermissionDeniedErrorBooleanIndicates ∏if the error is a 403 Permission Denied error.
isNotFoundErrorBooleanIndicates if the error is a 404 Not Found error.
isUnprocessableEntityErrorBooleanIndicates if the error is a 422 Unprocessable Entity error.
isRateLimitErrorBooleanIndicates if the error is a 429 Rate Limit error.
isInternalServerErrorBooleanIndicates if the error is a 500 or higher Internal Server error.