Skip to content

Pi

Pi is a coding agent you run in your terminal. It has built-in support for AI Gateway, so instead of setting a base URL you select the cloudflare-ai-gateway provider and point Pi at your gateway. Pi builds the gateway endpoint from your account ID and gateway slug and routes requests through it.

Prerequisites

Before you start, you need:

  1. Set your gateway token, account ID, and gateway slug as environment variables. The following commands set them for the current session. To persist them, add them to your shell profile (for example, ~/.zshrc or ~/.bashrc).

    Replace <CLOUDFLARE_API_KEY> and <CLOUDFLARE_ACCOUNT_ID> with your values. You can leave CLOUDFLARE_GATEWAY_ID as default to route through your account's default gateway, or change it to another gateway slug.

    Terminal window
    # Run `wrangler auth token` to get an auth token.
    export CLOUDFLARE_API_KEY="<CLOUDFLARE_API_KEY>"
    # Run `wrangler whoami` to get your account ID.
    export CLOUDFLARE_ACCOUNT_ID="<CLOUDFLARE_ACCOUNT_ID>"
    # Use `default` to route through your account's default gateway.
    export CLOUDFLARE_GATEWAY_ID="default"

    Alternatively, leave out CLOUDFLARE_API_KEY and run /login inside Pi to store the token instead.

  2. Start a session against a model. Requests now route through AI Gateway.

    Terminal window
    pi --provider cloudflare-ai-gateway --model "claude-sonnet-4-6"

To confirm traffic reaches AI Gateway, refer to Verify it works.