Pi
Run Pi against AnyRouter as a custom OpenAI-compatible provider — one key, unified billing, and any AnyRouter model from a single config file.
Pi can use custom OpenAI-compatible providers declared in ~/.pi/agent/models.json. Register AnyRouter once and you can run Pi against any AnyRouter model id — with one sk-ar- key, unified billing, and full audit logs.
Why route through AnyRouter
- One key for every model Pi can call.
- Audit logs with cost, latency, and tokens per request.
- Swap models freely — add ids to
models.json, no key rotation.
Fastest path
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr pi
anyr pi --install --ok
The launcher writes a Pi agent dir (PI_CODING_AGENT_DIR) with AnyRouter already in models.json, sets ANYROUTER_API_KEY, and starts pi --provider anyrouter. Manual models.json below is only if you run pi yourself.
Set it up
Step 1 — Create an AnyRouter API key
Create an API key in your dashboard. AnyRouter keys start with sk-ar-. Add it to your shell:
export ANYROUTER_API_KEY="sk-ar-your-anyrouter-key"
Put the same line in ~/.zshrc or ~/.bashrc if you want it to persist.
Step 2 — Add AnyRouter to Pi
Create or edit ~/.pi/agent/models.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" }
]
}
}
}
apiKey is the environment variable name, not the secret value. Do not paste your sk-ar- key into this file.
Step 3 — Run Pi
Use the custom provider and pick one of the model ids from models.json:
pi --provider anyrouter --model "openai/gpt-5.4-mini"
Add more models from the model catalog by appending entries to the models array. Keep the id exactly as shown in AnyRouter, such as google/gemini-3.1-flash-lite or z-ai/glm-4.7-flash.
Verify
Run a prompt through the custom provider, then open your request logs. The call should appear within a second or two with the model name, token counts, and cost — confirmation you're routing through AnyRouter.
Troubleshooting
401 or 403 — confirm echo $ANYROUTER_API_KEY prints your key and that the key is active in the dashboard.
Model not found — make sure the model id in Pi exactly matches an AnyRouter model id.
429 — Pi can send repeated agent calls quickly. Wait for the rate-limit window to reset or use a key with a higher limit.