Pi Setup with AnonRouter
Configure the Pi coding agent with private, uncensored AI models through AnonRouter. Covers models.json, API keys, model selection, and tool calling.
Connect Pi, the terminal coding agent, to AnonRouter through a custom
OpenAI-compatible provider. Add the models you want to models.json, keep your
key in an environment variable, and select a model with /model.
The short version
Add the provider below to ~/.pi/agent/models.json, set
ANONROUTER_API_KEY, then start Pi with --provider anonrouter and your
chosen --model. Use openai-completions for Chat Completions.
1. Install Pi and create your key
Follow Pi's installation guide for your platform. The current npm installation is:
npm install -g --ignore-scripts @earendil-works/pi-coding-agentCreate an AnonRouter inference key with OpenAI-compatible access enabled (on by default). Your account needs available credits or a subscription allowance. Use a dedicated key and set a total credit limit for coding sessions that may make repeated requests.
Create an API keySet the key in the environment that will launch Pi:
export ANONROUTER_API_KEY=ar_REPLACE_WITH_YOUR_API_KEYUse your usual secret manager or private shell environment for the real value. Keep it out of project files and shared shell history.
2. Configure the AnonRouter provider
Create ~/.pi/agent/models.json, or merge the provider into the existing file:
{
"$schema": "https://pi.dev/schemas/models.schema.json",
"providers": {
"anonrouter": {
"name": "AnonRouter",
"baseUrl": "https://api.anonrouter.ai/v1",
"api": "openai-completions",
"apiKey": "$ANONROUTER_API_KEY",
"authHeader": true,
"models": [
{
"id": "deepseek/deepseek-v4.1-flash-uncensored",
"name": "DeepSeek V4.1 Flash Uncensored",
"input": [
"text",
"image"
],
"reasoning": true,
"contextWindow": 1000000,
"maxTokens": 32000
}
]
}
}
}The $ in "$ANONROUTER_API_KEY" tells current Pi releases to resolve the
value from your environment. authHeader sends the resolved key as a bearer
credential. The base URL ends at /v1; Pi appends /chat/completions.
Despite its name, openai-completions selects Chat Completions, not the
legacy /completions endpoint. Keep this API type even for Claude-family
models reached through AnonRouter.
The configuration uses the selected model's full advertised context window. The starting output budget is 32,000 tokens, or the model's output limit if lower, following OpenCode's fallback budget. This is a configured budget, not the model's maximum. Reasoning and image input follow the selected model's catalog capabilities. Check the live catalog when using a different model.
Pi uses its default agent directory unless you override it with --agent-dir
or PI_CODING_AGENT_DIR. Put models.json in that directory when using an
override; .pi/settings.json in a project is a different configuration file.
3. Start and select a model
From your project directory, run:
pi --provider anonrouter --model "deepseek/deepseek-v4.1-flash-uncensored"Inside Pi, use /model to change models. Opening that picker also reloads
models.json, so you can add another entry to models without restarting.
Select a model with usable credentials; a missing environment variable can
keep the custom provider from appearing.
Start with a harmless text request, then ask Pi to inspect a small test file. Check the resulting tool call before using the setup for edits or shell tasks.
For a one-shot text check without tools or a saved session:
pi --provider anonrouter --model "deepseek/deepseek-v4.1-flash-uncensored" --no-tools --no-session --print "Reply with one short greeting."This sends a real generation request and can incur a charge. It checks the connection; it does not verify tool execution.
Choose models and capabilities
Use exact API IDs from the AnonRouter catalog. Each entry in Pi's models
array represents a model you want in its picker; this configuration does not
import AnonRouter's whole catalog automatically.
Check tool support, privacy labels, context size, and output limits when adding
an entry. Pi's optional cost metadata describes USD per million tokens for
its local estimates; it does not set AnonRouter's prices or enforce a spending
limit. This example omits pricing metadata, so use AnonRouter usage and billing
for actual charges rather than treating an absent or zero Pi estimate as free
usage.
For vision-capable models, the configuration includes "image" alongside
"text". Text-only models keep input: ["text"]. AnonRouter accepts supported
image parts in user messages; image-producing tools need separate compatibility
checks. Review compatibility mode for image formats and limits.
Tools and local sessions
Pi executes tools on your computer; AnonRouter transports the model request and returns tool calls. The default Pi tool set includes file reading, shell commands, edits, and writes. Pi runs with the permissions of its process and does not ask for approval before every tool call. Use a restricted account or isolated environment when the task needs a stronger boundary.
Pi can save local sessions containing prompts, file content, and tool output.
Use --no-session for an in-memory session when you do not want that session
persisted. Review session contents before exporting or sharing them.
Privacy boundary
Files, repository instructions, terminal output, tool results, and conversation context included in a request reach AnonRouter and the selected model provider. Only expose the files and credentials needed for the task.
This setup uses AnonRouter compatibility mode. The broker temporarily receives static-key identity and plaintext content together in memory. AnonRouter does not intentionally retain prompts or responses, but this connection does not provide the unlinkability of the optional private ticket flow. Pi's local session storage is separate from AnonRouter's retention policy.
Troubleshooting
AnonRouter is missing from /model
Check the JSON syntax, the agent-directory location, and the models array.
Confirm ANONROUTER_API_KEY is set in the process launching Pi, then reopen
/model. Current Pi uses $NAME environment interpolation; do not replace
"$ANONROUTER_API_KEY" with a literal variable name without the $.
Authentication returns 401 or 403
Verify the full inference key and its OpenAI-compatible access setting.
Use an ar_... inference key rather than a management key. Check for an old
saved credential: Pi's stored auth.json credential takes precedence over
models.json, and a --api-key override takes precedence over both.
Requests return 404 or model not found
Keep baseUrl at https://api.anonrouter.ai/v1 and api at
openai-completions. Copy the model ID exactly from the live catalog, including
its creator prefix.
Context errors or failed tool calls
Check the model's current limits and tool capability. Reduce the included files and history, or select another route. A text response alone does not prove tool calling works.
Sources and further reading
- Pi: installation and overview
- Pi: choosing models and compatible endpoints
- Pi: models.json reference
- Pi: configuration locations
- Pi: command-line options
- Pi: running safely
- AnonRouter compatibility mode
- AnonRouter model catalog
AnonRouter is an independent service and is not affiliated with Pi.
Kilo Code
Configure Kilo Code with private, uncensored AI models through AnonRouter. Covers VS Code and CLI setup, API keys, model selection, and tool calling.
Strix
Configure Strix with private, uncensored AI models through AnonRouter. Covers the custom API endpoint, model selection, tools, and spending controls.