# Enable Zyte API to avoid bans

Now that you have [run your project in Scrapy Cloud](cloud.md#tutorial-cloud), it
is time to improve the project itself, starting with handling website bans.

Your target domain in this tutorial, [toscrape.com](http://toscrape.com/), does not ban traffic.
However, when targeting other websites, sooner or later you will [get bans](../../get-started.md#ban-challenge).

You will now configure your web scraping code to use [Zyte API](../../../zyte-api/get-started.md#zyte-api)
to avoid bans on any website:

1. [Sign up for Zyte API](https://app.zyte.com/account/signup/zyteapi).

   You get [$5 free for a month](../../../zyte-api/pricing.md#zapi-trial), and you should only need a
   fraction of that to complete this tutorial.
2. Set up your project to use Zyte API with your key:

   ### Claude Code

   > [!NOTE]
   > Uses [Agentic Web Data](../../../zyte-web-data/index.md#agentic-web-data).

   Add `ZYTE_API_KEY = "YOUR_API_KEY"` to
   `web-scraping-tutorial/settings.py`, and replace
   `YOUR_API_KEY` with [your Zyte API key](https://app.zyte.com/o/zyte-api/api-access).

   ### Copilot

   > [!NOTE]
   > Uses [Web Scraping Copilot](../../../copilot/index.md#copilot).

   Remove `#` from the `#ZYTE_API_KEY = "YOUR_API_KEY"` line in
   `web-scraping-tutorial/settings.py`, and replace
   `YOUR_API_KEY` with [your Zyte API key](https://app.zyte.com/o/zyte-api/api-access).

   ### CLI

   1. Install the latest version of [scrapy-zyte-api](https://scrapy-zyte-api.readthedocs.io/en/latest/index.html):
      ```bash
      pip install --upgrade scrapy-zyte-api
      ```
   2. Configure scrapy-zyte-api in [transparent mode](https://scrapy-zyte-api.readthedocs.io/en/latest/usage/transparent.html#transparent) by adding the following code at the end of
      `web-scraping-tutorial/settings.py`, replacing
      `YOUR_ZYTE_API_KEY` with [your Zyte API key](https://app.zyte.com/o/zyte-api/api-access):
      ```python
      ZYTE_API_KEY = "YOUR_ZYTE_API_KEY"
      ```

      Then, edit the Addons section at the start of the
      `web-scraping-tutorial/settings.py` file:
      ```python
      ADDONS = {
          "scrapy_zyte_api.Addon": 500,
      }
      ```
3. Get `scrapy-zyte-api` installed when running in Scrapy Cloud:

   ### Claude Code

   > [!NOTE]
   > Uses [Agentic Web Data](../../../zyte-web-data/index.md#agentic-web-data).

   Skip this step.

   **Agentic Web Data for Claude Code** handled this automatically when
   you deployed your project to Scrapy Cloud.

   ### Copilot

   > [!NOTE]
   > Uses [Web Scraping Copilot](../../../copilot/index.md#copilot).

   1. Create `web-scraping-tutorial/requirements.txt` with the
      following content:
      ```none
      scrapy-zyte-api
      ```
   2. Add the following to
      `web-scraping-tutorial/scrapinghub.yml`:
      ```yaml
      requirements:
          file: requirements.txt
      ```

   ### CLI

   1. Create `web-scraping-tutorial/requirements.txt` with the
      following content:
      ```none
      scrapy-zyte-api
      ```
   2. Add the following to
      `web-scraping-tutorial/scrapinghub.yml`:
      ```yaml
      requirements:
          file: requirements.txt
      ```

If you run [your code](setup.md#tutorial-run-spider) again, your code will work
the same, only that requests will be sent through Zyte API, to avoid bans
[cost-efficiently](../../../zyte-api/pricing.md#zapi-pricing).

Continue to the [next chapter](js.md#tutorial-js) to learn about browser
automation.

> [!TIP]
> - We closely monitor the success rate for the most popular websites, but
>   less popular websites may slip under our radar. If you ever find a
>   website for which Zyte API does not work as expected (e.g. gives you a
>   ban response or too many [errors](../../../zyte-api/usage/errors.md#zapi-errors)), you can [reach
>   out to our expert anti-ban team](https://support.zyte.com/support/tickets/new).
> - If you get an SSL error, [install the Zyte CA certificate](../../../misc/ca.md#ca) on
>   your system and try again.
