---
title: Pi with AI Gateway
description: Connect Pi to AI Gateway with one CLI command, or configure it manually.
url: "https://vercel.com/docs/ai-gateway/coding-agents/pi"
last_updated: 2026-09-13
related:
  - /docs/cli/ai-gateway
  - /docs/agent-harnesses/pi
  - /docs/ai-gateway/observability-and-spend/budgets
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# Pi with AI Gateway

[Pi](https://github.com/earendil-works/pi) is an open-source terminal coding agent. It ships a first-class `vercel-ai-gateway` provider, so it already knows the gateway's base URL and model catalog and only needs your API key.

## Set up with the Vercel CLI

Run the [Vercel CLI setup command](/docs/cli/ai-gateway#setup) for Pi:

```bash filename="terminal"
npx vercel@latest ai-gateway setup --agent pi
```

This command:

- Provisions an AI Gateway API key, or reuses one you pass with `--key`.
- Writes the key to Pi's auth file (`~/.pi/agent/auth.json`, or `$PI_CODING_AGENT_DIR/auth.json` when that variable is set) under the `vercel-ai-gateway` provider key, with owner-only (`0600`) permissions.
- Backs up any file it changes alongside the original as `.bak`. Add `--dry-run` to preview changes without writing them.

The Vercel CLI configures Pi but doesn't install it. Install Pi before starting it:

```bash filename="terminal"
npm install -g @earendil-works/pi-coding-agent
```

> **💡 Note:** Pi always keeps the key in `auth.json`, so the command writes it there even in
> macOS Keychain mode. Pi reads its agent directory from `$PI_CODING_AGENT_DIR`
> when that variable is set, and falls back to `~/.pi/agent` otherwise.

Run the command without `--agent` to detect and configure every installed supported agent at once:

```bash filename="terminal"
npx vercel@latest ai-gateway setup
```

For the full command reference, see [`vercel ai-gateway`](/docs/cli/ai-gateway#setup).

To verify the setup, start Pi and choose a gateway model with `/model` (or `--model`), then confirm your requests appear in the [**AI Gateway**](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway\&title=Go+to+AI+Gateway) Overview in the Vercel dashboard.

## Manual setup

Only needed on machines where you can't use the Vercel CLI.

- ### Install Pi
  Install the Pi coding agent from npm:
  ```bash filename="Terminal"
  npm install -g @earendil-works/pi-coding-agent
  ```

- ### Create an API key
  Go to the [**AI Gateway**](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai-gateway\&title=Go+to+AI+Gateway) section in the Vercel dashboard sidebar and click **API keys** to create a new API key.

- ### Add the key to Pi
  Pi keeps credentials in `~/.pi/agent/auth.json`. Add an entry for the gateway provider:
  ```json filename="~/.pi/agent/auth.json"
  {
    "vercel-ai-gateway": {
      "type": "api_key",
      "key": "your-ai-gateway-api-key"
    }
  }
  ```
  The file holds a secret, so create it with owner-only permissions:
  ```bash filename="Terminal"
  chmod 600 ~/.pi/agent/auth.json
  ```
  > **💡 Note:** Pi reads its agent directory from `$PI_CODING_AGENT_DIR` when that variable
  > is set, and falls back to `~/.pi/agent` otherwise.

- ### Pick a model
  Start Pi and choose a gateway model with `/model`, or name one when you launch:
  ```bash filename="Terminal"
  pi --model anthropic/claude-opus-5
  ```
  Model IDs use the gateway's `creator/model-name` format. Browse the [models catalog](/ai-gateway/models) for what's available.

## Run Pi durably

To deploy Pi as a service that resumes after crashes, function timeouts, and deployments, use Pi's durable runtime with `durable-harness/pi-durable` or the `durable-harness/pi` adapter. Both use AI Gateway for model calls. Follow the [durable Pi guide](/docs/agent-harnesses/pi) to choose a variant and configure the agent, chat route, and queue.

## Next steps

- Browse the [models catalog](/ai-gateway/models) for available models
- Read Pi's own [provider documentation](https://github.com/earendil-works/pi/blob/main/packages/coding-agent/docs/providers.md)
- Configure [spend limits](/docs/ai-gateway/observability-and-spend/budgets) on your API key
- Connect your other agents with the [Vercel CLI](/docs/cli/ai-gateway#setup)

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
