# 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/api/client/python/reference/class/ApifyClientError.md)

  * *ApifyApiError*

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

## Index[**](#Index)

### Methods

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

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

### [**](#__init__)\_\_init\_\_

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

- Initialize the API error from a failed response.

  ***

  #### Parameters

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

    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__)\_\_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/api/client/python/reference/class/HttpResponse.md)
  * ##### attempt: int
  * ##### optionalkeyword-onlymethod: str = <!-- -->'GET'

  #### Returns Self
