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
  1. Install Pi

    macOS / Linux

    curl -fsSL https://pi.dev/install.sh | sh

    Windows

    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-agent

    Run pi --version to confirm. On Windows, install Git for Windows first.

  2. 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 contextWindow and maxTokens to the model's real limits.
    • Add more entries to models to use several models.
    • apiKey can also be "$TOKENFUNC_API_KEY" to read it from an environment variable and keep it out of the file.
  3. 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 /model in Pi to pick a model and press Ctrl+S to make it the default.

Troubleshooting

SymptomCause and fix
This site's models are missing from /modelThe outer providers key is missing, or apiKey names an environment variable that is not set
404baseUrl is missing /v1
401Wrong key or no quota left. Check it on API Keys
An older guide's config does nothingOlder guides put the provider at the root and used context; both are obsolete. Rewrite it in the format above