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
Provider setup
- 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.
Create a TokenRex API key, then copy an enabled chat model's exact ID from Models & Pricing. The examples use openai/gpt-6-astra; replace it with your selected ID.
- 3.
Set TOKENREX_API_KEY privately in the environment that launches Pi. Pi supports $NAME and ${NAME} references in its API-key field.
- 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.
Keep api set to openai-completions, baseUrl set to https://tokenrex.ai/api/public/v1, and the model id unchanged, including its openai/ prefix.
- 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.
{
"providers": {
"tokenrex": {
"baseUrl": "https://tokenrex.ai/api/public/v1",
"apiKey": "$TOKENREX_API_KEY",
"api": "openai-completions",
"authHeader": true,
"models": [
{
"id": "openai/gpt-6-astra",
"name": "GPT-6 Astra (TokenRex)"
}
]
}
}
}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.