# ApifyApiError<!-- -->

Error raised when the Apify API returns an error response.

Instantiating `ApifyApiError` dispatches to the subclass matching the HTTP status code (e.g. 404 → `NotFoundError`, any 5xx → `ServerError`). Unmapped statuses stay on `ApifyApiError`. Existing `except ApifyApiError` handlers keep working because every subclass inherits from this class.

The `type`, `message` and `data` fields from the response body are exposed for inspection but are treated as non-authoritative metadata — dispatch is driven by the status code only.

### Hierarchy

* [ApifyClientError](https://docs.apify.com/api/client/python/reference/class/ApifyClientError)

  * *ApifyApiError*

    * [InvalidRequestError](https://docs.apify.com/api/client/python/reference/class/InvalidRequestError)
    * [UnauthorizedError](https://docs.apify.com/api/client/python/reference/class/UnauthorizedError)
    * [ForbiddenError](https://docs.apify.com/api/client/python/reference/class/ForbiddenError)
    * [NotFoundError](https://docs.apify.com/api/client/python/reference/class/NotFoundError)
    * [ConflictError](https://docs.apify.com/api/client/python/reference/class/ConflictError)
    * [RateLimitError](https://docs.apify.com/api/client/python/reference/class/RateLimitError)
    * [ServerError](https://docs.apify.com/api/client/python/reference/class/ServerError)

## Index[**](#Index)

### Methods

* [**\_\_init\_\_](https://docs.apify.com/sdk/python/sdk/python/reference/class/ApifyApiError.md#__init__)
* [**\_\_new\_\_](https://docs.apify.com/sdk/python/sdk/python/reference/class/ApifyApiError.md#__new__)

## Methods<!-- -->[**](#Methods)

### [**](#__init__)[**](https://github.com/apify/apify-sdk-python/blob/b216cff988b3dc02e3b17a3d553d3e35801c6799//src/apify_client/errors.py#L54)\_\_init\_\_

* ****\_\_init\_\_**(response, attempt, \*, method): None

- Initialize the API error from a failed response.

  ***

  #### Parameters

  * ##### response: [HttpResponse](https://docs.apify.com/api/client/python/reference/class/HttpResponse)

    The failed HTTP response from the Apify API.

  * ##### attempt: int

    The attempt number when the request failed (1-indexed).

  * ##### optionalkeyword-onlymethod: str = <!-- -->'GET'

    The HTTP method of the failed request.

  #### Returns None

### [**](#__new__)[**](https://github.com/apify/apify-sdk-python/blob/b216cff988b3dc02e3b17a3d553d3e35801c6799//src/apify_client/errors.py#L42)\_\_new\_\_

* ****\_\_new\_\_**(response, attempt, \*, method): Self

- Dispatch to the subclass matching the response's HTTP status code, if any.

  ***

  #### Parameters

  * ##### response: [HttpResponse](https://docs.apify.com/api/client/python/reference/class/HttpResponse)
  * ##### attempt: int
  * ##### optionalkeyword-onlymethod: str = <!-- -->'GET'

  #### Returns Self
