Pi coding agent logo
Coding agents

Use TokenRex with Pi coding agent

Add TokenRex as a custom OpenAI-compatible provider in Pi's terminal coding agent.

Use a model that supports tool calling for agent tasks. Review file, terminal and connected-account permissions before allowing actions. Provider setup is documented; a live connection from this app has not been tested. Pi supplies defaults when model limits are omitted. Set contextWindow and maxTokens from your model's verified TokenRex details if you customize them; do not assume those defaults are the model's actual limits. Provider setup checked against the official reference. Live execution inside this third-party tool has not been tested; model limits, streaming and tool behavior must be verified separately.

Before you start

  • Pi installed from pi.dev
  • A TokenRex API key
  • An enabled tool-capable chat model

Setup methods

01

Provider setup

  1. 1

    Install Pi using the official quick start at https://pi.dev/docs/latest/quickstart. On supported macOS/Linux systems the documented installer is curl -fsSL https://pi.dev/install.sh | sh; review it first.

  2. 2

    Create a TokenRex API key, then copy an enabled chat model's exact ID from Models & Pricing. The examples use gpt-6-astra; replace it with your selected ID.

  3. 3

    Set TOKENREX_API_KEY privately in the environment that launches Pi. Pi supports $NAME and ${NAME} references in its API-key field.

  4. 4

    Create ~/.pi/agent/models.json if needed and merge the providers entry below. If PI_CODING_AGENT_DIR is set, use that agent directory instead.

  5. 5

    Keep api set to openai-completions, baseUrl set to https://tokenrex.ai/api/public/v1, and the model id exactly as TokenRex lists it.

  6. 6

    Run pi in your project folder, use /model and select the TokenRex provider's model. Send a short question before enabling file or terminal actions.

Configuration
{
  "providers": {
    "tokenrex": {
      "baseUrl": "https://tokenrex.ai/api/public/v1",
      "apiKey": "$TOKENREX_API_KEY",
      "api": "openai-completions",
      "authHeader": true,
      "models": [
        {
          "id": "gpt-6-astra",
          "name": "GPT-6 Astra (TokenRex)"
        }
      ]
    }
  }
}

Setup reference

Troubleshooting

Authentication fails
Check that the saved TokenRex key is active and belongs in the tool's API-key field, not its subscription sign-in. Remove accidental spaces, check your wallet balance, and never share the key in screenshots or exported settings.
The model is missing or the request URL returns 404
Copy an exact enabled model ID from Models & Pricing. Follow this method's URL field: some tools expect the versioned base, others the root or full completion address. Check the documented API protocol before changing the path.
Chat works but streaming or tools fail
Test a short plain-text conversation first. Confirm the selected model and installed tool version support the required protocol and capabilities. Enable agent actions only after separately checking streaming and tool calls.

Verify the connection

Send a short message with the selected model, read its response, then confirm the exact model appears in your TokenRex usage. Test streaming and tool use separately before larger agent tasks.