@realvendex/pi-token-router

TokenRouter.com unified API gateway as a native Pi provider for accessing 300+ LLM models via a single API key

Packages

Package details

extension

Install @realvendex/pi-token-router from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@realvendex/pi-token-router
Package
@realvendex/pi-token-router
Version
0.2.0
Published
Jun 17, 2026
Downloads
not available
Author
realvendex
License
MIT
Types
extension
Size
62.5 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./extensions"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

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_KEY env var or ~/.pi/agent/auth.json

Features

  • Custom streamSimple — full SSE streaming with reasoning_split support
  • Dynamic model list — fetched from GET /v1/models at startup
  • Curated fallback — fallback model map when live fetch is unavailable
  • Reasoning support — MiniMax thinking object and DeepSeek reasoning_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-pro
  • openai/gpt-5.4-mini
  • anthropic/claude-opus-4.8
  • google/gemini-3.5-flash
  • deepseek/deepseek-v4-pro
  • qwen/qwen3.7-plus
  • x-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 Errorspi.on("message_end", ...) normalizes TokenRouter overflow errors to context_length_exceeded for 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