# Pi

> Run Pi against AnyRouter as a custom OpenAI-compatible provider with one key.


# Pi

[Pi](https://pi.dev) reads custom OpenAI-compatible providers from `~/.pi/agent/models.json`. Register AnyRouter once to run Pi on any AnyRouter model with one `sk-ar-` key.

## Fastest path

```bash
curl -fsSL https://anyrouter.dev/cli.sh | bash
anyr pi
```

The launcher writes a Pi agent dir (`PI_CODING_AGENT_DIR`) with AnyRouter in `models.json`, sets `ANYROUTER_API_KEY`, and starts `pi --provider anyrouter`. Use `anyr pi --install --ok` to install Pi too. Pi has no MCP support, so Auto-connect does not apply.

## Manual setup

1. Create a key in the [dashboard](https://anyrouter.dev/dashboard/keys) and export it (add to `~/.zshrc` or `~/.bashrc` to persist):

   ```bash
   export ANYROUTER_API_KEY="sk-ar-your-anyrouter-key"
   ```

2. Add AnyRouter to `~/.pi/agent/models.json`:

   ```json
   {
     "providers": {
       "anyrouter": {
         "baseUrl": "https://anyrouter.dev/api/v1",
         "api": "openai-completions",
         "apiKey": "ANYROUTER_API_KEY",
         "models": [
           { "id": "openai/gpt-5.4-mini" },
           { "id": "anthropic/claude-sonnet-4-6" }
         ]
       }
     }
   }
   ```

   :::warning
   `apiKey` is the environment variable name, not the secret. Do not paste your `sk-ar-` key here.
   :::

3. Run Pi:

   ```bash
   pi --provider anyrouter --model "openai/gpt-5.4-mini"
   ```

Add more models from the [catalog](https://anyrouter.dev/models) as entries in `models`, with the `id` exactly as listed (for example `google/gemini-3.1-flash-lite`). The call appears in your [request logs](https://anyrouter.dev/dashboard/logs).

## Troubleshooting

| Symptom | Fix |
|---|---|
| 401 or 403 | `echo $ANYROUTER_API_KEY` must print your key, and the key must be active. |
| Model not found | The id in Pi must match an AnyRouter model id exactly. |
| 429 | Pi can send agent calls quickly. Wait for the window to reset or use a key with a higher limit. |


## Related

- [Chat Completions API](/docs/api-reference/chat-completions.md)
- [Models API](/docs/api-reference/models.md)
- [Rate Limits](/docs/features/rate-limits.md)
