Checked 2026-10-28

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, or npm install -g --ignore-scripts @earendil-works/pi-coding-agent on 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:

json
1{
2 "$schema": "https://pi.dev/schemas/models.schema.json",
3 "providers": {
4 "relayswitch": {
5 "name": "RelaySwitch",
6 "baseUrl": "https://api.relayswitch.io/v1",
7 "api": "openai-completions",
8 "apiKey": "$RELAYSWITCH_API_KEY",
9 "models": [
10 {
11 "id": "claude-sonnet-5-5",
12 "name": "Claude Sonnet 5.5",
13 "input": [
14 "text",
15 "image"
16 ],
17 "cost": {
18 "input": 1.2,
19 "output": 3,
20 "cacheRead": 0.075,
21 "cacheWrite": 1.2
22 },
23 "contextWindow": 1000000,
24 "maxTokens": 128000
25 },
26 {
27 "id": "claude-opus-5-5",
28 "name": "Claude Opus 5.5",
29 "input": [
30 "text",
31 "image"
32 ],
33 "cost": {
34 "input": 2.716,
35 "output": 9.7,
36 "cacheRead": 0.1455,
37 "cacheWrite": 2.716
38 },
39 "contextWindow": 1000000,
40 "maxTokens": 128000
41 },
42 {
43 "id": "gpt-5.5",
44 "name": "GPT-5.5",
45 "input": [
46 "text",
47 "image"
48 ],
49 "cost": {
50 "input": 1.8,
51 "output": 9,
52 "cacheRead": 0.16,
53 "cacheWrite": 1.8
54 },
55 "contextWindow": 1050000,
56 "maxTokens": 128000
57 },
58 {
59 "id": "gemini-3.1-pro-preview",
60 "name": "Gemini 3.1 Pro Preview",
61 "input": [
62 "text",
63 "image"
64 ],
65 "cost": {
66 "input": 1.2,
67 "output": 7.2,
68 "cacheRead": 0.12,
69 "cacheWrite": 1.2
70 },
71 "contextWindow": 1048576,
72 "maxTokens": 65536
73 },
74 {
75 "id": "deepseek-v4-pro-0813",
76 "name": "DeepSeek V4 Pro 0813",
77 "cost": {
78 "input": 0.792,
79 "output": 1.188,
80 "cacheRead": 0.0625,
81 "cacheWrite": 0.792
82 },
83 "contextWindow": 1048576,
84 "maxTokens": 393216
85 },
86 {
87 "id": "glm-5.3",
88 "name": "GLM 5.3",
89 "cost": {
90 "input": 0.317772,
91 "output": 0.998712,
92 "cacheRead": 0.06596,
93 "cacheWrite": 0.317772
94 },
95 "contextWindow": 1000000,
96 "maxTokens": 131072
97 }
98 ]
99 }
100 }
101}
  • Any key under providers that is not a built-in id adds a provider. It needs baseUrl and an api; openai-completions calls /chat/completions under https://api.relayswitch.io/v1, which every model on this page answers.
  • apiKey as "$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 models entry needs only id. cost is 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. cacheRead is the catalog's cached-input rate; cacheWrite is set to the input rate, since the catalog bills no separate write price. name is what /model shows.
  • contextWindow and maxTokens default to 128,000 and 16,384 when omitted; the block fills them from each model's catalog specs. input adds image where 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

  1. Save the block above as ~/.pi/agent/models.json.
  2. Export the key in the shell that runs Pi, then start it:
bash
1export RELAYSWITCH_API_KEY="sk-relay-..."
2pi --model relayswitch/claude-sonnet-5-5
  1. 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:

json
1{
2 "defaultProvider": "relayswitch",
3 "defaultModel": "claude-sonnet-5-5"
4}

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.

ModelInputCachedOutputDeveloper list in / outContext
Claude Sonnet 5.5$1.20 (40% under)$0.075$3.00 (70% under)$2.00 / $10.001M tokens
Claude Opus 5.5$2.716 (32% under)$0.1455$9.70 (51% under)$4.00 / $20.001M tokens
GPT-5.5$1.80 (64% under)$0.16$9.00 (70% under)$5.00 / $30.001.1M tokens
Gemini 3.1 Pro Preview$1.20 (40% under)$0.12$7.20 (40% under)$2.00 / $12.001M tokens
DeepSeek V4 Pro 0813$0.792 (40% under)$0.0625$1.188 (70% under)$1.32 / $3.961M tokens
GLM 5.3$0.3178 (70% under)$0.066$0.9987 (70% under)$1.092 / $3.4321M 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.

ModelWith cache hitsNo 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:

bash
1curl https://api.relayswitch.io/v1/models -H "Authorization: Bearer $RELAYSWITCH_API_KEY"
  • 401: the key is wrong or revoked, or RELAYSWITCH_API_KEY was 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: the id in 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 /model again; 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.

Run Pi on a prepaid balance

One key, from $10 by card or crypto. No KYC, no subscription.

Join on Telegram