# SwitchRouter — Complete Agent & Developer Integration Guide (llms-full.txt) SwitchRouter provides a unified multi-protocol inference endpoint (`https://api.switchrouter.dev/v1`) for coding agents and applications with smart phase routing (`switchrouter/auto`), automatic failover, and NGN wallet/subscription settlement. --- ## 0. SwitchRouter Connect & Official CLI (`npx switchrouter` / `sr`) - **Product & Pricing Page**: `/connect` — One monthly Naira coding subscription across Claude Code, Codex CLI, OpenCode, Cursor, Windsurf, Cline, Roo Code, and OpenClaw with smart phase routing (`switchrouter/auto`) and 3× unused credit rollover: - **Starter (`₦5,000/mo`)**: ₦5,000 monthly credits (rolls over up to ₦15,000), Auto/Fast/Code/Vision routing, 10% Frontier reasoning share, 2 parallel coding sessions. - **Builder (`₦15,000/mo` — Most popular)**: ₦15,000 monthly credits (rolls over up to ₦45,000), 3× capacity, 20% Frontier reasoning share, 4 parallel coding sessions. - **Pro (`₦35,000/mo`)**: ₦35,000 monthly credits (rolls over up to ₦105,000), 7× capacity, 35% Frontier reasoning share, 6 parallel coding sessions. - **Max (`₦75,000/mo`)**: ₦75,000 monthly credits (rolls over up to ₦225,000), 15× capacity, 50% Frontier reasoning share, 8 parallel coding sessions. - **Ultra (`₦165,000/mo`)**: ₦165,000 monthly credits (rolls over up to ₦495,000), 33× capacity, 70% Frontier reasoning share, 12 parallel coding sessions. If you are an autonomous agent with terminal access, you can configure the local machine or current repository in one non-interactive command: ```bash # Global setup (configures OpenCode, Claude Code, Codex CLI, and Shell with .bak backups) npx --yes switchrouter@latest connect --key "$SWITCHROUTER_API_KEY" --yes # Project-scoped setup (writes ./opencode.jsonc, ./.claude/settings.local.json, ./.env.local + .gitignore) npx --yes switchrouter@latest connect --key "$SWITCHROUTER_API_KEY" --project --yes # Initialize an application repository (Node.js/TypeScript/Vercel AI SDK/Python) npx --yes switchrouter@latest init --key "$SWITCHROUTER_API_KEY" --yes # Inspect Naira credit balance & 5h / 7d / monthly fair-use windows as JSON npx --yes switchrouter@latest status --json # Run health check & live switchrouter/fast TTFT latency ping npx --yes switchrouter@latest doctor ``` ### Virtual Model Aliases (`switchrouter/*`) - `switchrouter/auto` — Smart phase router (Default). Routes planning, multi-file coding, one-turn vision screenshots, and fast tool calls automatically while maintaining sticky prompt-cache affinity. - `switchrouter/code` — Core coding workhorse pool. - `switchrouter/fast` — Sub-second search & light edit pool. - `switchrouter/deep` — Frontier architecture & hard debugging pool. ### Multi-Protocol Wire Endpoints - **OpenAI Chat Completions** (OpenCode, Cursor, Cline, SDKs): `POST https://api.switchrouter.dev/v1/chat/completions` - **Anthropic Messages** (Claude Code): `POST https://api.switchrouter.dev/v1/messages` - **OpenAI Responses** (Codex CLI): `POST https://api.switchrouter.dev/v1/responses` - **Connect Status & Links**: `GET https://api.switchrouter.dev/v1/connect/me` (returns `workspace`, `subscription`, `limits`, `models`, `console_url`, and `links`) ### Claude Code Configuration ```bash export ANTHROPIC_BASE_URL="https://api.switchrouter.dev" export ANTHROPIC_AUTH_TOKEN="$SWITCHROUTER_API_KEY" export ANTHROPIC_MODEL="switchrouter/auto" export ANTHROPIC_SMALL_FAST_MODEL="switchrouter/fast" claude ``` ### Codex CLI Configuration (`~/.codex/config.toml`) ```toml model = "switchrouter/auto" model_provider = "switchrouter" [model_providers.switchrouter] name = "SwitchRouter Connect" base_url = "https://api.switchrouter.dev/v1" env_key = "SWITCHROUTER_API_KEY" wire_api = "responses" ``` --- ## 1. Self-Discovery for Autonomous Agents Before writing config files, any agent can query the public catalogue (no API key needed): ```bash curl -s https://api.switchrouter.dev/v1/models | jq '.data[] | {id, name, context_window, max_output_tokens, capabilities}' ``` Verify a Connect API key, Naira credit buckets, and fair-use limits: ```bash curl -s https://api.switchrouter.dev/v1/connect/me \ -H "Authorization: Bearer $SWITCHROUTER_API_KEY" ``` Verify a standard workspace API key and auth context: ```bash curl -s https://api.switchrouter.dev/v1/auth/context \ -H "Authorization: Bearer $SWITCHROUTER_API_KEY" ``` --- ## 2. Hermes Agent Configuration Hermes and similar autonomous agent runtimes support OpenAI-compatible model providers. Point Hermes at SwitchRouter using environment variables or your Hermes provider configuration: ```bash export OPENAI_API_BASE="https://api.switchrouter.dev/v1" export OPENAI_BASE_URL="https://api.switchrouter.dev/v1" export OPENAI_API_KEY="$SWITCHROUTER_API_KEY" export SWITCHROUTER_API_KEY="$SWITCHROUTER_API_KEY" ``` Example Hermes `config.yaml` / agent provider block: ```yaml provider: type: openai_compatible name: switchrouter base_url: "https://api.switchrouter.dev/v1" api_key_env: SWITCHROUTER_API_KEY model: switchrouter/auto headers: X-Title: "Hermes Agent" ``` --- ## 3. OpenCode Configuration (`~/.config/opencode/opencode.jsonc`) OpenCode uses the Vercel AI SDK under the hood. Add `switchrouter-connect` (or `switchrouter`) under `provider` in `~/.config/opencode/opencode.jsonc`: ```jsonc { "$schema": "https://opencode.ai/config.json", "model": "switchrouter-connect/switchrouter/auto", "small_model": "switchrouter-connect/switchrouter/fast", "provider": { "switchrouter-connect": { "npm": "@ai-sdk/openai-compatible", "name": "SwitchRouter Connect", "options": { "baseURL": "https://api.switchrouter.dev/v1", "apiKey": "{env:SWITCHROUTER_API_KEY}", "headers": { "X-Title": "OpenCode" } }, "models": { "switchrouter/auto": { "name": "SwitchRouter Auto (Smart Router)", "tool_call": true, "attachment": true, "limit": { "context": 200000, "output": 64000 } }, "switchrouter/code": { "name": "SwitchRouter Code (Workhorse Pool)", "tool_call": true, "limit": { "context": 200000, "output": 64000 } }, "switchrouter/fast": { "name": "SwitchRouter Fast (Search & Light Edits)", "tool_call": true, "limit": { "context": 200000, "output": 32000 } }, "switchrouter/deep": { "name": "SwitchRouter Deep (Frontier Architecture)", "tool_call": true, "attachment": true, "limit": { "context": 200000, "output": 64000 } }, "deepseek.v3.2": { "name": "DeepSeek V3.2", "tool_call": true, "limit": { "context": 163840, "output": 16384 } }, "qwen.qwen3-coder-480b-a35b": { "name": "Qwen3 Coder 480B", "tool_call": true, "limit": { "context": 262144, "output": 65536 } } } } } } ``` --- ## 4. Application SDKs (Node.js / TypeScript, Python, Vercel AI SDK) ### OpenAI Node / TypeScript SDK ```typescript import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.SWITCHROUTER_API_KEY, baseURL: "https://api.switchrouter.dev/v1", defaultHeaders: { "X-Title": "My App", }, }); const response = await client.chat.completions.create({ model: "switchrouter/auto", messages: [{ role: "user", content: "Build a fast parser in TypeScript." }], }); ``` ### Vercel AI SDK (`@ai-sdk/openai-compatible`) ```typescript import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { generateText } from "ai"; const switchrouter = createOpenAICompatible({ name: "switchrouter", baseURL: "https://api.switchrouter.dev/v1", apiKey: process.env.SWITCHROUTER_API_KEY, headers: { "X-Title": "My Next.js App" }, }); const { text } = await generateText({ model: switchrouter("switchrouter/auto"), prompt: "Hello from SwitchRouter!", }); ``` ### Python OpenAI SDK ```python import os from openai import OpenAI client = OpenAI( api_key=os.environ["SWITCHROUTER_API_KEY"], base_url="https://api.switchrouter.dev/v1", default_headers={"X-Title": "My Python Service"}, ) completion = client.chat.completions.create( model="switchrouter/auto", messages=[{"role": "user", "content": "Hello from SwitchRouter"}], ) print(completion.choices[0].message.content) ```