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.
Before you start, you need:
- An authenticated gateway and its gateway token. The gateway token must have
Runpermissions. - Your Cloudflare account ID. To find it, refer to Find your account and zone IDs.
- Pi installed and updated to the latest version.
-
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,
~/.zshrcor~/.bashrc).Replace
<CLOUDFLARE_API_KEY>and<CLOUDFLARE_ACCOUNT_ID>with your values. You can leaveCLOUDFLARE_GATEWAY_IDasdefaultto 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"PowerShell # Run `wrangler auth token` to get an auth token.$env:CLOUDFLARE_API_KEY = "<CLOUDFLARE_API_KEY>"# Run `wrangler whoami` to get your account ID.$env:CLOUDFLARE_ACCOUNT_ID = "<CLOUDFLARE_ACCOUNT_ID>"# Use `default` to route through your account's default gateway.$env:CLOUDFLARE_GATEWAY_ID = "default"Alternatively, leave out
CLOUDFLARE_API_KEYand run/logininside Pi to store the token instead. -
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.