x402

It is possible to use Zyte API without a Zyte API account by using the x402 protocol to handle payments:

  1. Read the Zyte Terms of Service. By using Zyte API, you are accepting them.

  2. During installation, make sure to install the x402 extra.

  3. Configure the private key of your Ethereum account to authorize payments.

Configuring your Ethereum private key

It is recommended to configure your Ethereum private key through an environment variable, so that it can be picked by both the command-line client and the Python client library:

  • On Windows’ CMD:

    > set ZYTE_API_ETH_KEY=YOUR_ETH_PRIVATE_KEY
    
  • On macOS and Linux:

    $ export ZYTE_API_ETH_KEY=YOUR_ETH_PRIVATE_KEY
    

Alternatively, you may pass your Ethereum private key to the clients directly:

  • To pass your Ethereum private key directly to the command-line client, use the --eth-key switch:

    zyte-api --eth-key YOUR_ETH_PRIVATE_KEY 
  • To pass your Ethereum private key directly to the Python client classes, use the eth_key parameter when creating a client object:

    from zyte_api import ZyteAPI
    
    client = ZyteAPI(eth_key="YOUR_ETH_PRIVATE_KEY")
    
    from zyte_api import AsyncZyteAPI
    
    client = AsyncZyteAPI(eth_key="YOUR_ETH_PRIVATE_KEY")
    

You may also store your Ethereum private key in a .env file:

.env
ZYTE_API_ETH_KEY=YOUR_ETH_PRIVATE_KEY

Unlike the Zyte API key, the Ethereum private key is read only from a .env file in the current directory; parent directories are not searched, to limit the risk of loading it from an unrelated .env file. To read it from a different location, use the --dotenv-path switch or the dotenv_path parameter, which apply to both credentials. The environment variable takes precedence over the file, which is never modified.

Warning

Your Ethereum private key controls your funds. Storing it in a .env file is convenient but risky: keep the file out of version control (e.g. add it to .gitignore) and prefer a dedicated secrets manager for anything beyond local development. A leaked private key cannot be revoked or rotated like a Zyte API key.