Pi
Add a custom provider to the Pi models.json.
Pi is a lightweight command-line coding agent. Connect it by adding a custom provider in models.json.
- Protocol: OpenAI-compatible (Chat Completions)
- Base URL:
https://tokenfunc.com/v1 - Models: any, for example
claude-sonnet-4-5
Install Pi
macOS / Linux
curl -fsSL https://pi.dev/install.sh | shWindows
powershell -c "irm https://pi.dev/install.ps1 | iex"npm
# Requires Node.js 22.19 or later npm install -g --ignore-scripts @earendil-works/pi-coding-agentRun
pi --versionto confirm. On Windows, install Git for Windows first.Add a custom provider
Put the following into Pi's model config file, creating it if needed:
~/.pi/agent/models.json{ "$schema": "https://pi.dev/schemas/models.schema.json", "providers": { "tokenfunc": { "baseUrl": "https://tokenfunc.com/v1", "api": "openai-completions", "apiKey": "sk-xxxxxxxxxxxxxxxx", "models": [ { "id": "claude-sonnet-4-5", "contextWindow": 200000, "maxTokens": 32000 } ] } } }- Set
contextWindowandmaxTokensto the model's real limits. - Add more entries to
modelsto use several models. apiKeycan also be"$TOKENFUNC_API_KEY"to read it from an environment variable and keep it out of the file.
- Set
Choose a model and verify
# List the models under this site's provider pi --list-models tokenfunc # Send a test message pi --model tokenfunc/claude-sonnet-4-5 -p "reply ok"A reply means you are connected. Day to day, type
/modelin Pi to pick a model and pressCtrl+Sto make it the default.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
This site's models are missing from /model | The outer providers key is missing, or apiKey names an environment variable that is not set |
| 404 | baseUrl is missing /v1 |
| 401 | Wrong key or no quota left. Check it on API Keys |
| An older guide's config does nothing | Older guides put the provider at the root and used context; both are obsolete. Rewrite it in the format above |