Pi coding agent on one key
Add RelaySwitch to Pi as a provider in models.json: the base URL, one prepaid key from an environment variable, and the model ids you want in /model. Pay as you go, by card or crypto.
Pi reads compatible endpoints from ~/.pi/agent/models.json. One entry under providers with https://api.relayswitch.io/v1 as its base URL puts Claude, GPT, Gemini, DeepSeek and GLM in the same /model picker, every request billed per token to the balance behind one key. No subscription and no weekly cap: the balance is the only limit.
The block below is generated from the live catalog, so its cost fields are today's prices and Pi's own session figure matches what the console charges.
01What you need
- Pi installed:
curl -fsSL https://pi.dev/install.sh | sh, ornpm install -g --ignore-scripts @earendil-works/pi-coding-agenton Node.js 22.19 or newer. - A RelaySwitch key from the console (email-code sign-in). Keys start with
sk-relay-. - A prepaid balance, from $10 by card or crypto, no subscription and no KYC. The console chat runs 12 free turns a day before the first top-up; Pi requests bill the balance.
02Pi models.json provider block
Pi keeps its user configuration in ~/.pi/agent (PI_CODING_AGENT_DIR moves it). Custom providers go in models.json there:
{ "$schema": "https://pi.dev/schemas/models.schema.json", "providers": { "relayswitch": { "name": "RelaySwitch", "baseUrl": "https://api.relayswitch.io/v1", "api": "openai-completions", "apiKey": "$RELAYSWITCH_API_KEY", "models": [ { "id": "claude-sonnet-5-5", "name": "Claude Sonnet 5.5", "input": [ "text", "image" ], "cost": { "input": 1.2, "output": 3, "cacheRead": 0.075, "cacheWrite": 1.2 }, "contextWindow": 1000000, "maxTokens": 128000 }, { "id": "claude-opus-5-5", "name": "Claude Opus 5.5", "input": [ "text", "image" ], "cost": { "input": 2.716, "output": 9.7, "cacheRead": 0.1455, "cacheWrite": 2.716 }, "contextWindow": 1000000, "maxTokens": 128000 }, { "id": "gpt-5.5", "name": "GPT-5.5", "input": [ "text", "image" ], "cost": { "input": 1.8, "output": 9, "cacheRead": 0.16, "cacheWrite": 1.8 }, "contextWindow": 1050000, "maxTokens": 128000 }, { "id": "gemini-3.1-pro-preview", "name": "Gemini 3.1 Pro Preview", "input": [ "text", "image" ], "cost": { "input": 1.2, "output": 7.2, "cacheRead": 0.12, "cacheWrite": 1.2 }, "contextWindow": 1048576, "maxTokens": 65536 }, { "id": "deepseek-v4-pro-0813", "name": "DeepSeek V4 Pro 0813", "cost": { "input": 0.792, "output": 1.188, "cacheRead": 0.0625, "cacheWrite": 0.792 }, "contextWindow": 1048576, "maxTokens": 393216 }, { "id": "glm-5.3", "name": "GLM 5.3", "cost": { "input": 0.317772, "output": 0.998712, "cacheRead": 0.06596, "cacheWrite": 0.317772 }, "contextWindow": 1000000, "maxTokens": 131072 } ] } }}- Any key under
providersthat is not a built-in id adds a provider. It needsbaseUrland anapi;openai-completionscalls/chat/completionsunderhttps://api.relayswitch.io/v1, which every model on this page answers. apiKeyas"$NAME"reads an environment variable. A literal key works, and a value that begins with an exclamation point runs a command and uses its output, for a secret manager.- A
modelsentry needs onlyid.costis optional, but once set it needs all four fields in USD per million tokens; this block sets them so Pi's session cost uses the catalog prices.cacheReadis the catalog's cached-input rate;cacheWriteis set to the input rate, since the catalog bills no separate write price.nameis what/modelshows. contextWindowandmaxTokensdefault to 128,000 and 16,384 when omitted; the block fills them from each model's catalog specs.inputaddsimagewhere the model takes one, so Pi can attach screenshots.
Field reference: Pi's models-configuration.md; the compatible-endpoint walkthrough is models.md (both read 2026-10-28). Add any other id from the Models page the same way; an entry whose id matches an existing model on that provider replaces it, and modelOverrides changes a built-in's metadata without a new list.
03Steps
- Save the block above as ~/.pi/agent/models.json.
- Export the key in the shell that runs Pi, then start it:
export RELAYSWITCH_API_KEY="sk-relay-..."pi --model relayswitch/claude-sonnet-5-5- Send a prompt. The request shows on the console's Usage page within seconds, with its tokens and its charge.
Add the export to your shell profile so new terminals have it. --model takes provider/id, an exact id or a fuzzy match on id or name; --provider relayswitch narrows the lookup to this block.
04Pick the model
Inside Pi, /model lists every model whose provider has usable credentials. Ctrl+S on a model saves it as the default for new sessions and Ctrl+P cycles through the available ones. The same default as a file:
{ "defaultProvider": "relayswitch", "defaultModel": "claude-sonnet-5-5"}That file is ~/.pi/agent/settings.json. enabledModels in it, or --models on the command line, limits startup selection and cycling to a list of exact ids, fuzzy matches or globs (an array in the file, comma-separated on the command line): pi --models claude-sonnet-5-5,claude-opus-5-5 keeps the cycle to those two.
05Which model id to list
Any chat id on the Models page. The ids in the block are the usual coding set: a Claude flagship for planning and hard edits, GPT-5.5 and Gemini 3.1 Pro as second opinions, DeepSeek V4 Pro and GLM 5.3 where the input price decides. The table is what they cost today.
| Model | Input | Cached | Output | Developer list in / out | Context |
|---|---|---|---|---|---|
| Claude Sonnet 5.5 | $1.20 (40% under) | $0.075 | $3.00 (70% under) | $2.00 / $10.00 | 1M tokens |
| Claude Opus 5.5 | $2.716 (32% under) | $0.1455 | $9.70 (51% under) | $4.00 / $20.00 | 1M tokens |
| GPT-5.5 | $1.80 (64% under) | $0.16 | $9.00 (70% under) | $5.00 / $30.00 | 1.1M tokens |
| Gemini 3.1 Pro Preview | $1.20 (40% under) | $0.12 | $7.20 (40% under) | $2.00 / $12.00 | 1M tokens |
| DeepSeek V4 Pro 0813 | $0.792 (40% under) | $0.0625 | $1.188 (70% under) | $1.32 / $3.96 | 1M tokens |
| GLM 5.3 | $0.3178 (70% under) | $0.066 | $0.9987 (70% under) | $1.092 / $3.432 | 1M tokens |
USD per million tokens, read from the RelaySwitch catalog when this page was built. Developer list: the catalog's record of the developer's own price.
Input decides the cost of an agent session: the conversation and every tool result travel up again on each step. Cached input bills at the cached rate by itself; there is no switch to set.
06What 40 agent turns cost
A turn here is 80,000 tokens of earlier context, 2,000 fresh input tokens and 1,500 output tokens. The first column bills the earlier context at the cached rate, the second as if none of it were cached.
| Model | With cache hits | No cache hits |
|---|---|---|
| GLM 5.3 | $0.2964 | $1.10 |
| DeepSeek V4 Pro 0813 | $0.3346 | $2.67 |
| Claude Sonnet 5.5 | $0.516 | $4.12 |
| Gemini 3.1 Pro Preview | $0.912 | $4.37 |
| GPT-5.5 | $1.20 | $6.44 |
| Claude Opus 5.5 | $1.26 | $9.49 |
40 turns at the live per-token prices. A model with no cached rate bills cached tokens at its input rate.
With cache hits the task runs $0.2964 on GLM 5.3 and $1.26 on Claude Opus 5.5. Run routine edits on the low end and keep the flagship for reviews, and the balance lasts longer.
07Errors and fixes
Confirm the key from a shell before you open Pi:
curl https://api.relayswitch.io/v1/models -H "Authorization: Bearer $RELAYSWITCH_API_KEY"401: the key is wrong or revoked, orRELAYSWITCH_API_KEYwas not set in the shell that started pi. Export it and start Pi again, or confirm the value with the curl above.402: the balance is too low. Top up in the console; the key works again at once.404: theidin the models array is not in the catalog. Copy it from the Models page rather than typing it: a dot, a dash or a date suffix out of place is enough.429: the key hit its rate limit. Wait and resend, or create a key with a higher Requests / min in the console.- The model is missing from
/model: Pi hides a custom model until it can resolve the provider's credentials. Check the variable, then open/modelagain; opening it reloads models.json, so a new id needs no restart either.
The full error table is in the docs.
Questions
- Can Pi use a custom OpenAI-compatible endpoint?
- Yes. Pi's models.json takes any endpoint that speaks an API it already supports, and openai-completions is one of them. A provider entry needs baseUrl, api, apiKey and a models list; the block on this page is that entry for https://api.relayswitch.io/v1.
- How do I add a model to Pi?
- Add an object with the model id (plus its four cost fields, so Pi can price the session) to the models array of your provider in ~/.pi/agent/models.json. Opening /model reloads the file, so the new id appears without a restart. Any id on the RelaySwitch Models page works.
- Does Claude work in Pi through this block?
- Yes. claude-sonnet-5-5 and claude-opus-5-5 answer the OpenAI chat completions format at https://api.relayswitch.io/v1, so they sit in the same openai-completions provider as gpt-5.5 or deepseek-v4-pro-0813. No Anthropic provider entry is needed.
- How do I set a default model in Pi?
- Press Ctrl+S on a model in /model, or set defaultProvider and defaultModel in ~/.pi/agent/settings.json. For one run, pi --model relayswitch/claude-sonnet-5-5 picks it on the command line.
- What does Pi cost to run?
- Pi is free and open source; the model is the only bill, per token at the live rates in the table above, drawn from a prepaid balance you top up from $10 by card or crypto. No subscription.
- Why is my custom model not in /model?
- Pi lists a custom model only once it can resolve the provider's credentials. Export RELAYSWITCH_API_KEY in the shell that starts Pi, or put the key in apiKey as a literal, then open /model again.