@realvendex/pi-token-router
v0.2.0
Published
TokenRouter.com unified API gateway as a native Pi provider for accessing 300+ LLM models via a single API key
Downloads
3,420
Maintainers
Readme
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-routerOr 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 debugArchitecture
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
