How to connect Pi to the Tokenator API
Pi has no provider wizard: custom providers are declared in a single JSON file. The file is re-read every time you open /model, so the agent needs no restart after an edit.
What you end up with
Once configured, Pi stops talking to its default provider and sends every request to Tokenator. Billing comes out of your key's token limit, and the list of available models is defined by the key rather than by the tool.
| Tool | Pi |
| Protocol | OpenAI-compatible |
| Base URL | https://api.tokenator.top/v1 |
| Key | sk-your-tokenator-key |
Requirements and supported operating systems
- Windows 10/11, macOS 12+, or a modern 64-bit Linux.
- Outbound HTTPS access to the Tokenator domain.
- A Tokenator API key that looks like
sk-your-tokenator-key.
You need Node.js with npm and a terminal. The file with custom providers is created by hand, in any editor.
Installing Pi
npm install -g --ignore-scripts @earendil-works/pi-coding-agent
--ignore-scripts disables the dependency lifecycle scripts — a normal Pi install does not need them. The agent is started with pi from the project directory.
Setting up Tokenator
- Register in your account and buy a token bundle.
- The key appears in the account right after the payment is confirmed — copy it whole, including the prefix.
- The examples below use the placeholder
sk-your-tokenator-key. Never publish a real key in repositories or screenshots.
Configuration
- Create
~/.pi/agent/models.json; on Windows that is%USERPROFILE%\.pi\agent\models.json. - Describe the provider in it: address, protocol, key and the model list.
- Put the key into the
TOKENATOR_API_KEYenvironment variable — the file keeps only a reference to it. - Run
piand open/model(or Ctrl+L): the file is re-read every time the picker opens.
{
"providers": {
"tokenator": {
"baseUrl": "https://api.tokenator.top/v1",
"api": "openai-completions",
"apiKey": "$TOKENATOR_API_KEY",
"models": [
{ "id": "gpt-5.5" }
]
}
}
}apiKey field understands three forms: $VARIABLE or ${VARIABLE} substitutes an environment value, a string starting with ! is executed as a command and its output is used, and anything else is taken literally. So TOKENATOR_API_KEY without the dollar sign would be sent as the key itself — the dollar is required. A missing variable leaves the value unresolved.The only required field on a model is id. The rest (name, contextWindow, maxTokens, input, cost) shape how the model is displayed and accounted for in the UI and are optional.
Your first request
Before starting the tool it helps to confirm that the key and the model both work. A single curl request answers both questions.
curl https://api.tokenator.top/v1/chat/completions \ -H "Authorization: Bearer sk-your-tokenator-key" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-5.5", "messages": [{"role": "user", "content": "ping"}] }'
cd /path/to/project
piOpen /model (or Ctrl+L) and pick a model of the tokenator provider. Ctrl+S in the picker saves the highlighted model as the startup default.
A successful response means the key is valid, the model is allowed for it and the upstream is reachable. Usage appears in your account right after the request.
Switching models
Every model is an entry of the models array in ~/.pi/agent/models.json. The file is re-read when /model opens, so a newly added model shows up in the picker without restarting the agent.
Examples of model IDs available right now:
claude-haiku-4-5claude-opus-4-6claude-opus-4-7claude-sonnet-4-6gpt-5.5deepseek-v4-pro
Current IDs and specs live in the AI model catalog, which also shows which models are available right now. The model comparison helps choose between close options.
Configuring reasoning
A reasoning model is marked in models.json with "reasoning": true. If the server does not accept the reasoning_effort field, set "supportsReasoningEffort": false in the provider's compat block; if it does not understand the developer role, set "supportsDeveloperRole": false and the system prompt is sent as a plain system message instead. compat can be set on the provider for all its models or on a single model.
The key's reasoning switch in your account works independently of the tool, and thinking is billed as output tokens.
Common errors and how to fix them
| Symptom | Cause | Fix |
|---|---|---|
The model loads but stays unavailable in /model | No auth is configured for the provider: without it models are visible but cannot be selected. | Set apiKey in the file, store a key with /login, or pass --api-key when selecting the model. |
The literal string TOKENATOR_API_KEY is sent to the server | A value without $ is treated as a literal rather than an environment variable name. | Write $TOKENATOR_API_KEY and make sure the variable is present in the environment. |
| The file was not picked up at all | A syntax error in the JSON. | Validate the file with a JSON linter and open /model again — it is re-read every time the picker opens. |
401 or an invalid-key message | The key was copied with stray spaces, was revoked, has expired, or landed in the wrong environment variable. | Check the key in your account and make sure the environment variable actually reached the process running the tool. |
403 | The model is not in the key's allowed-model list. | Check the key's model list in your account and pick an ID from the model catalog. |
429 | The per-minute or per-hour request limit, or the concurrent-stream limit for the key, was exceeded. | Lower the agent's concurrency and retry with exponential backoff. Key limits are visible in your account. |
| Model not found / not supported | The request used an ID that is not in the catalog, or an alias unavailable to this key. | Copy the exact API ID from the model page — case and dots matter. |
| The request hangs or breaks on a long answer | The client closed the connection on its own timeout before the model finished generating. | Turn on streaming (stream: true) and raise the client timeout: with long reasoning answers the first token can take a while. |
| A bare "Request error" with no details | The upstream provider returned an error. Its text is not passed through to the client. | Retry: Tokenator fails over to the next provider for the model on its own. If it persists, contact support. |
FAQ
Do I need a Pi subscription or a separate provider account?
No. The tool talks to Tokenator, and billing comes from your Tokenator key's tokens.
Where do I see usage after connecting?
In your account: it shows requests, spent tokens and the key's remaining limit.
Can one key be used in several tools?
Yes. The limits are the key's own: requests per minute and hour, plus the number of concurrent streams.
What happens if tokens run out mid-session?
Requests start returning an error. Topping up the same key restores the limit — no need to reinstall the tool.
How do I switch back to the previous provider?
Remove the settings you added — the environment variables or the provider block in the config. The tool reverts to its default behaviour.
Where can I read about the API format itself?
In the Tokenator API documentation and on the OpenAI-compatible API page.