Pi
Add RouterPlex to the Pi coding agent through models.json.
On this page
Set it up with your coding agent #
Paste your key into the prompt's key field, then copy the prompt into Claude Code, Codex, Cursor, or any coding agent. It configures the tool and keeps testing until a real request goes through RouterPlex, fixing environment problems along the way. Prefer to do it by hand? Follow the manual setup below; your key fills those commands too.
Optional. It stays in this browser tab and is never saved or sent. No key yet? Create one in guided setup.
Set up Pi on this machine to use RouterPlex, an OpenAI- and Anthropic-compatible AI gateway. Keep working until a real request from Pi succeeds through RouterPlex.My RouterPlex API key: YOUR_ROUTERPLEX_API_KEYKey handling:- If the key line above is a placeholder rather than a real key (real keys start with sk-), use my ROUTERPLEX_API_KEY environment variable. If that is empty too, ask me for the key once, then continue.- Store the key only in user-level config or my user environment. Never put it in a project file, never commit it, and do not repeat the full key in your replies (show at most its first 8 characters).Config handling:- Before changing an existing config file or shell startup file, copy it to a .bak file next to it and show me the diff. Merge into what is there; never replace my other settings, providers, or MCP servers.- If a step needs something only I can do, such as a click in a settings window, print the exact steps instead of guessing.Full guide: https://docs.routerplex.com/piStep 1. Prove the key and the RouterPlex gateway work before changing anything else. Run:curl -sS https://api.routerplex.com/v1/chat/completions -H "Authorization: Bearer YOUR_ROUTERPLEX_API_KEY" -H "Content-Type: application/json" -d '{"model":"claude-sonnet-4-6","max_tokens":32,"messages":[{"role":"user","content":"Reply with exactly: RouterPlex connected."}]}'On Windows PowerShell, use curl.exe with the body in a file, or Invoke-RestMethod.- A reply containing "RouterPlex connected.": go on.- 401: the key is wrong or revoked. Stop and ask me for a correct key.- 402: my balance or trial credit is used up. 403: this key reached its own spending limit. Stop and tell me; retrying cannot fix these.- Network, DNS, TLS, or proxy errors: find and fix the cause (proxy variables, VPN, firewall, system clock, outdated CA certificates), then run it again.Step 2. Configure Pi:- Run pi --version. If Pi is missing, install it with curl -fsSL https://pi.dev/install.sh | sh, or npm install -g --ignore-scripts @earendil-works/pi-coding-agent (Node.js 22.19+).- Merge this provider into ~/.pi/agent/models.json (or models.json in $PI_CODING_AGENT_DIR if set); create the file as {"providers": {}} if missing:{"providers": {"routerplex": {"baseUrl": "https://api.routerplex.com/v1", "api": "openai-completions", "apiKey": "$ROUTERPLEX_API_KEY","models": [{"id": "claude-sonnet-4-6", "name": "Claude Sonnet 4.6 (RouterPlex)", "reasoning": true, "input": ["text", "image"], "contextWindow": 1000000, "maxTokens": 64000,"cost": {"input": 3, "output": 15, "cacheRead": 0.25, "cacheWrite": 3}}]}}}- Keep apiKey as the literal text $ROUTERPLEX_API_KEY; Pi fills it in from my environment, so the raw key never goes in the file. For other models, take contextWindow, maxTokens, cost (USD per million tokens), reasoning, and image input from that model's entry in https://routerplex.com/api/models.- Make ROUTERPLEX_API_KEY permanent for my user so new terminals get it:- macOS/Linux: add export ROUTERPLEX_API_KEY='<key>' (keep the word export: a plain ROUTERPLEX_API_KEY=... line is invisible to programs started from the shell) to the startup file of the shell I use (check $SHELL: zsh uses ~/.zshrc; bash uses ~/.bashrc, plus ~/.bash_profile or ~/.profile if they do not source ~/.bashrc). Update an existing line instead of adding a second one.- Windows: run [Environment]::SetEnvironmentVariable('ROUTERPLEX_API_KEY', '<key>', 'User'). Only terminals and apps started after this see it.- WSL, SSH, or a dev container: set it inside that environment, where the tool actually runs.Step 3. Test Pi itself from a new terminal or a restarted app, so you test the saved setup rather than the shell you changed:From an empty temporary folder: pi -p --provider routerplex --model claude-sonnet-4-6 "Reply with exactly: RouterPlex connected. Do not read files or run tools."Expected reply: "RouterPlex connected."Step 4. If step 1 works but step 3 fails, the problem is Pi's configuration or environment, not RouterPlex. Check these, fix what is wrong, and repeat step 3:- The key or base URL is set in one place but not where Pi starts: zsh vs bash startup files, login vs non-login shells, a desktop launcher, a background service, Windows vs WSL, or a remote SSH or container environment.- Another setting wins: OPENAI_API_KEY, OPENAI_BASE_URL, OPENAI_API_BASE, ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, or a project-level config that overrides the user-level one.- Pi is outdated, or still needs a full restart to read the new settings.- If an environment variable cannot be made to reach Pi reliably and Pi accepts a key in its user-level config, put the key there instead.Keep repeating steps 3 and 4 until the test reply comes back.Step 5. The test above sends no tools, but real sessions send every tool, MCP server, and plugin schema with each request, and that is where models differ. From a folder with a README.md (create a temporary one containing "# RouterPlex tool check" if needed), run:pi -p --provider routerplex --model claude-sonnet-4-6 "List your available tools, then read ./README.md and reply with its first heading."It passes when the reply lists the tools and quotes the heading. If it fails while step 3 passes, the tool schemas are the problem, not the connection. Tell me the exact error; the chosen model may not handle Pi's tools, so suggest another tool-capable model from https://routerplex.com/models.Stop early only for a 401, 402, or 403, or for a step only I can do, such as a click in a settings window or a login. Then tell me exactly what to do, wait for me, and continue testing afterwards.When it works, tell me exactly which files you changed and which values you set (key shown by its first 8 characters only) so I can undo it, where the key is stored, and the final test output. Remind me that every request shows up in https://routerplex.com/dashboard/usage.
Manual setup #
Add RouterPlex to Pi, the terminal coding agent, as a custom provider in models.json. Pi speaks Chat Completions to RouterPlex and reads the key from your environment at request time, so the key never sits in the file.
1. Install #
macOS, Linux, and WSL:
curl -fsSL https://pi.dev/install.sh | sh
Or with npm (Node.js 22.19+, any OS): npm install -g --ignore-scripts @earendil-works/pi-coding-agent. Reopen your terminal and run pi --version.
2. Add the provider #
Merge this into ~/.pi/agent/models.json (create it as {"providers": {}} if missing). If you set PI_CODING_AGENT_DIR, edit models.json in that folder instead.
{"providers": {"routerplex": {"baseUrl": "https://api.routerplex.com/v1","api": "openai-completions","apiKey": "$ROUTERPLEX_API_KEY","models": [{"id": "claude-sonnet-4-6","name": "Claude Sonnet 4.6 (RouterPlex)","reasoning": true,"input": ["text", "image"],"contextWindow": 1000000,"maxTokens": 64000,"cost": { "input": 3, "output": 15, "cacheRead": 0.25, "cacheWrite": 3 }}]}}}
Keep apiKey as the literal text $ROUTERPLEX_API_KEY; Pi fills it from your environment. Add one models item per model, and copy its values from the public catalog: contextWindow from context_tokens, maxTokens from max_output_tokens, and cost in USD per million tokens. For this Sonnet example, cache writes bill at the input rate. Set reasoning and "image" input only for models whose catalog entry has reasoning and vision. Pi reloads the file whenever /model opens, so no restart is needed.
3. Set your key and test #
export ROUTERPLEX_API_KEY='YOUR_ROUTERPLEX_API_KEY'pi -p --provider routerplex --model claude-sonnet-4-6 "Reply with exactly: RouterPlex connected. Do not read files or run tools."
Then check tools from a folder that has a README.md:
pi -p --provider routerplex --model claude-sonnet-4-6 "List your available tools, then read ./README.md and reply with its first heading."
Confirm both requests in Usage. Start an interactive session with pi --provider routerplex --model claude-sonnet-4-6, or pick the model with /model and press Ctrl+S to make it the default. To keep the key across terminals, add the export line to your shell startup file (see environment setup).
Troubleshooting #
- The model is missing from /model: the key variable is not set in the shell that started Pi, so Pi hides the provider. Check with
echo ${ROUTERPLEX_API_KEY:+set}. - 401: wrong or revoked key, or a stored
/logincredential forrouterplexin~/.pi/agent/auth.jsontakes priority overmodels.json. Remove it with/logout. - Model not found: the
idmust match the catalog exactly.
Official references: models and custom endpoints, CLI.