Install
Install with PiG
pig install npm:@realvendex/pi-token-routerInstall with Pi
pi install npm:@realvendex/pi-token-routerPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./extensions"
]
}README
Written by the package's publisher, shown as published in version 0.2.0 (README.md). PiG does not review it.
pi-token-router
Native Pi provider for TokenRouter.com — a unified API gateway exposing 300+ LLM models through a single OpenAI-compatible endpoint.
Just switch your base URL.
- Provider name:
tokenrouter - Base URL:
https://api.tokenrouter.com/v1 - API:
tokenrouter-api(custom streamSimple) - Auth: API key via
TOKENROUTER_API_KEYenv var or~/.pi/agent/auth.json
Features
- ✅ Custom streamSimple — full SSE streaming with reasoning_split support
- ✅ Dynamic model list — fetched from
GET /v1/modelsat startup - ✅ Curated fallback — fallback model map when live fetch is unavailable
- ✅ Reasoning support — MiniMax
thinkingobject and DeepSeekreasoning_content - ✅ Tool calling — full OpenAI-compatible tool call streaming
- ✅ Context overflow recovery — auto-compaction on context-length errors
- ✅ All 9 documented model fields — id, name, reasoning, input, cost, contextWindow, maxTokens
- ✅ Logging — Structured logger with configurable verbosity
Install
pi install npm:@realvendex/pi-token-router
Or register as a local path in ~/.pi/agent/settings.json:
"packages": [
"..\\..\\nexus\\pi-token-router"
]
Configure
Option 1: Environment variable (recommended)
# Linux/Mac
export TOKENROUTER_API_KEY="sk-..."
# Windows PowerShell
$env:TOKENROUTER_API_KEY="sk-..."
# Windows CMD
set TOKENROUTER_API_KEY=sk-...
Option 2: auth.json (or /login tokenrouter)
{
"tokenrouter": {
"type": "api_key",
"key": "sk-..."
}
}
Default model
Set your default provider and model in ~/.pi/agent/settings.json:
{
"defaultProvider": "tokenrouter",
"defaultModel": "openai/gpt-5.4-mini"
}
Popular model IDs:
MiniMax-M3(free, 1M context, reasoning)openai/gpt-5.5-proopenai/gpt-5.4-minianthropic/claude-opus-4.8google/gemini-3.5-flashdeepseek/deepseek-v4-proqwen/qwen3.7-plusx-ai/grok-4.3
Commands
set-log-level
Configure the logger verbosity. Supports: debug, info, warn, error.
> set-log-level debug
Architecture
The extension strictly follows the pi custom provider docs:
- Register New Provider pattern with an async factory for dynamic model discovery
api: "openai-completions"— uses pi's built-in OpenAI-compatible streaming (no custom streamSimple needed for an OpenAI-compatible provider)apiKey: "$TOKENROUTER_API_KEY"— env var interpolation as documented- Context Overflow Errors —
pi.on("message_end", ...)normalizes TokenRouter overflow errors tocontext_length_exceededfor auto-compaction
Stability & Verification
This package has undergone a comprehensive quality audit:
- Build Pipeline: TypeScript compilation with strict mode.
- Logger Utility: Structured logging with debug/info/warn/error levels.
- Error Handling: All catch blocks produce meaningful log output.
- Type Safety: Explicit type annotations on event handlers and callbacks.
License
MIT © ZachDreamZ