omp packages

@realvendex/pi-token-router0.2.0

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

realvendex Published 4 months ago MIT ~7.8K downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

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 Errors — pi.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