Intelligent, explainable, cost- and latency-aware LLM request routing platform, AI Traffic Control Room, and drop-in SDKs.
Companies building AI applications face ballooning API costs, rate limits, and latency spikes. They want to use large models (like GPT-4o, Claude 3.5 Sonnet, or JEV reasoning models) for complex reasoning, but cheaper/faster models (like Llama 3 or Haiku) for simple tasks. Manually writing logic to route these requests is brittle and hard to maintain.
- The "Traffic Control Room": A stunning frontend UI that makes routing decisions transparent and explainable. You don't just route; you see why a request went to a specific model.
- 100% Local & Self-Hosted: No data leaves the user's infrastructure.
- A/B Policy Experimentation: Built-in tools to test different routing policies (e.g., "lowest cost" vs "balanced") and see projected savings.
- Triple-Mode Analyzer: Fast deterministic heuristics (<3ms), semantic ONNX embedding classification, and LLM-based continuous complexity scoring.
- Thompson Sampling RL Auto-Tuning: Contextual multi-armed bandit automatically adjusts model quality scores online based on real-time latency, throughput, and error rates.
- Production-Ready Scalability: Database-agnostic (SQLite for local dev, PostgreSQL for production) with Redis Pub/Sub powering real-time SSE traffic telemetry across distributed worker nodes.
- Resilient Execution: Built-in sliding-window circuit breaker dynamically bypasses failing upstream providers to prevent cascading latency spikes.
- Enterprise Observability: Standardized OpenTelemetry distributed tracing and native Prometheus
/metricsexposition.
- Triple-Mode Request Analyzer: Deterministic heuristics (<3ms latency overhead), ONNX dense semantic embedding similarity, and continuous complexity scoring (0.05 to 0.99).
- Explainable Multi-Criteria Routing Engine: Normalized 0-100 scoring across Quality, Cost Efficiency, Speed, Capabilities, and Reliability with transparent decision factor reports and candidate rejection logs.
- Thompson Sampling RL Auto-Tuner: Online Beta-distribution bandit exploration and exploitation that dynamically refines candidate priors based on real-world feedback.
- Multi-Tenant Workspaces & Rate Limiting: Workspace tenant isolation, cryptographically hashed API keys (
mr_live_...), and sliding-window token-bucket rate limiters. - Provider Abstraction: Decoupled adapters for Mock (simulation), Ollama (local), OpenAI, Anthropic, Together AI, DeepSeek, Groq, and Google Gemini.
- Resilience and Tiered Fallback: Automated retry classification for transient errors (timeouts, HTTP 429, 503) and tiered fallback to local/mock alternatives with circuit breaker protection.
- Automated Benchmarking & Pareto Evaluator: Run GSM8K, HumanEval, and MMLU benchmarks via CLI and compute 3D Cost-Accuracy Pareto frontiers with ASCII curve visualizers.
- OpenTelemetry & Prometheus Observability: Distributed trace span propagation across routing stages, plus Prometheus metrics scraping at
/metrics. - Traffic Control Room UI: Real-time operational interface with dark/light mode, live topology graphs, playground inspector, SSE live request stream, telemetry export as CSV/JSON, visual rules builder, and cost savings simulator.
- Drop-In Client SDKs: Native Python (
modelrouter-sdk) and TypeScript/JavaScript (@picadolabs/modelrouter-sdk) libraries for 1-line OpenAI client replacement.
flowchart TD
classDef client fill:#1e293b,stroke:#38bdf8,stroke-width:2px,color:#f8fafc;
classDef gateway fill:#0f172a,stroke:#818cf8,stroke-width:2px,color:#f8fafc;
classDef intel fill:#1e1b4b,stroke:#a855f7,stroke-width:2px,color:#f8fafc;
classDef exec fill:#064e3b,stroke:#34d399,stroke-width:2px,color:#f8fafc;
classDef obs fill:#431407,stroke:#fb923c,stroke-width:2px,color:#f8fafc;
subgraph CLIENTS["1. INGESTION & CLIENTS"]
SDK["Python & TypeScript SDKs<br/><code>modelrouter-sdk</code>"]:::client
CLI["Typer CLI<br/><code>modelrouter</code>"]:::client
UI["Traffic Control Room<br/><code>React / Vite UI</code>"]:::client
REST["OpenAI Drop-In API<br/><code>POST /api/generate</code>"]:::client
end
subgraph GATEWAY["2. GATEWAY & ACCESS CONTROL"]
AUTH["Tenant Auth & Workspace Isolation<br/><code>Bearer mr_live_...</code>"]:::gateway
RL["Sliding-Window Rate Limiter<br/><code>Token Bucket Algorithm</code>"]:::gateway
OTEL_CTX["OpenTelemetry Baggage Context<br/><code>Span Propagation</code>"]:::gateway
end
subgraph INTELLIGENCE["3. INTELLIGENT ROUTING PIPELINE"]
ANALYZER["Triple-Mode Analyzer<br/>β’ Fast Heuristics (<3ms)<br/>β’ ONNX Semantic Embeddings<br/>β’ Continuous Complexity (0.05 - 0.99)"]:::intel
PRUNE["Rules & Candidate Pruner<br/>β’ Context Window & Capability Match<br/>β’ Explicit Rule Overrides"]:::intel
SCORER["Multi-Criteria Scoring Engine<br/>β’ Weighted Quality, Speed, Cost, Reliability<br/>β’ Contextual Thompson Sampling Bandit RL"]:::intel
EXPLAIN["Explainability Engine<br/>β’ Transparent Decision Factors & Rejections"]:::intel
end
subgraph RESILIENCE["4. EXECUTION & RESILIENCE LAYER"]
CB["Sliding-Window Circuit Breaker<br/><code>Auto-bypass failing endpoints</code>"]:::exec
FALLBACK["Tiered Fallback Supervisor<br/><code>Automatic retry & failover</code>"]:::exec
subgraph PROVIDERS["Provider Adapters"]
CLOUD["Frontier Models<br/><code>OpenAI, Anthropic, Gemini, DeepSeek, Groq, Together</code>"]:::exec
LOCAL["Local Inference<br/><code>Ollama / Qwen, Llama 3, DeepSeek-R1</code>"]:::exec
MOCK["Zero-Cost Simulation<br/><code>In-Memory Mock Engine</code>"]:::exec
end
end
subgraph STORAGE["5. OBSERVABILITY & STORAGE ENGINE"]
PROM["Prometheus Metrics<br/><code>/metrics Scraping Endpoint</code>"]:::obs
DB[(Database WAL<br/><code>SQLite / PostgreSQL</code>)]:::obs
REDIS["Redis Pub/Sub Event Bus<br/><code>Live SSE Traffic Stream</code>"]:::obs
end
CLIENTS --> GATEWAY
GATEWAY --> INTELLIGENCE
INTELLIGENCE --> RESILIENCE
RESILIENCE --> STORAGE
REDIS -.->|Real-Time SSE Feed| UI
- Linux (Ubuntu 20.04+, Debian 11+, Fedora)
- macOS (macOS 12+ / Apple Silicon & Intel)
- Windows (Windows 10, Windows 11 / PowerShell & WSL2)
- Python 3.10, 3.11, or 3.12
- Node.js 18+ and npm
- (Optional) Ollama for local model inference
Install Model Router and its embedded AI Traffic Control Room dashboard directly from PyPI:
pip install model-router-cli# Run system diagnostics & environment checks
modelrouter doctor
# Launch the Traffic Control Room Dashboard & API Gateway in your browser
modelrouter ui --open-browser
# Route a prompt and inspect the explainability decision (Dry Run)
modelrouter route "Write an optimized async task worker in Python"
# Run automated GSM8K benchmark and evaluate Cost-Accuracy Pareto Frontier
modelrouter benchmark --dataset gsm8k --limit 10git clone https://github.com/PicadoLabs/ai-model-router.git
cd ai-model-router# Create and activate virtual environment
python -m venv venv
# On Linux/macOS:
source venv/bin/activate
# On Windows PowerShell:
.\venv\Scripts\Activate.ps1
# Install Python dependencies
pip install -r requirements.txt
# Create environment file from template
cp .env.example .envcd frontend
npm install
cd ..Model Router provides official lightweight, zero-dependency client libraries for drop-in routing in Python and Node.js/Browser applications.
pip install modelrouter-sdkfrom modelrouter import ModelRouter
# Initialize drop-in client
client = ModelRouter(base_url="http://localhost:8000", policy="balanced")
# 1. Standard OpenAI drop-in completion
response = client.chat.completions.create(
messages=[{"role": "user", "content": "Explain Dijkstra's algorithm"}]
)
print("Routed Model:", response.model)
print("Content:", response.choices[0].message.content)
# 2. Real-time streaming
for chunk in client.chat.completions.create(prompt="Write a Python script", stream=True):
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
# 3. Dry-run explainability inspector
decision = client.route("Design a distributed caching architecture")
print(f"Selected: {decision.selected_model_name} (Confidence: {decision.confidence*100:.0f}%)")npm install @picadolabs/modelrouter-sdkimport { ModelRouter } from '@picadolabs/modelrouter-sdk';
const router = new ModelRouter({
baseUrl: 'http://localhost:8000',
policy: 'balanced', // 'balanced' | 'cost_optimized' | 'speed_optimized' | 'quality_first'
});
// 1. Chat Completion
const response = await router.chat.completions.create({
messages: [{ role: 'user', content: 'What is the speed of light in vacuum?' }]
});
console.log('Response:', response.choices[0].message.content);
console.log('Routed Model:', response.model);
// 2. Real-Time Streaming
const stream = await router.chat.completions.create({
prompt: 'Write a quicksort in TypeScript',
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}The built-in Typer CLI provides terminal commands for inspection, diagnostics, benchmarking, and testing:
# Launch the AI Traffic Control Room Web UI and API Gateway
modelrouter ui --open-browser
# Run system diagnostics & provider health checks
modelrouter doctor
# Inspect routing decision for a prompt without executing (Dry Run)
modelrouter route "Write a Python function to parse JSON"
# Route and execute a query through the selected model
modelrouter run "Debug this distributed async deadlock in worker pool"
# Run automated Pareto benchmark suite (GSM8K, HumanEval, MMLU)
modelrouter benchmark --dataset gsm8k --limit 10 --format table
# List all registered models in the catalog
modelrouter models
# View recent routed traffic logs
modelrouter traffic
# View system-wide routing performance and cost savings analytics
modelrouter analyticscurl -X POST http://127.0.0.1:8000/api/route \
-H "Content-Type: application/json" \
-d '{"prompt": "Write a quicksort algorithm in Python", "policy": "balanced"}'curl -X POST http://127.0.0.1:8000/api/generate \
-H "Content-Type: application/json" \
-d '{"prompt": "Explain the difference between TCP and UDP", "policy": "cost_optimized"}'curl http://127.0.0.1:8000/metricscurl -X POST http://127.0.0.1:8000/api/benchmarks/run \
-H "Content-Type: application/json" \
-d '{"dataset": "gsm8k", "limit": 10, "baseline_model": "gpt-4o"}'# Export as JSON
curl -OJ "http://127.0.0.1:8000/api/traffic/export?format=json"
# Export as CSV
curl -OJ "http://127.0.0.1:8000/api/traffic/export?format=csv"The test suite includes 96 automated unit, integration, and end-to-end tests covering semantic embedding classification, Thompson sampling RL auto-tuning, OpenTelemetry & Prometheus metrics, benchmarking Pareto evaluator, SDK clients, and circuit breakers:
# Run the complete test suite from repository root
pytest
# Run tests with detailed coverage
pytest --cov=appai-model-router/
βββ .github/
β βββ workflows/ci.yml # Continuous integration & test workflow
βββ backend/
β βββ app/
β β βββ analytics/ # Cost savings and aggregate analytics service
β β βββ analyzer/ # Triple-mode request analyzer (heuristics, semantic ONNX, LLM)
β β βββ api/ # FastAPI REST endpoints and request handlers
β β βββ auth/ # Multi-tenant API keys & token bucket rate limiter
β β βββ budgets/ # Spend tracking and automated threshold manager
β β βββ cli/ # Typer CLI application (doctor, route, benchmark, ui)
β β βββ config/ # Pydantic Settings environment configuration
β β βββ experiments/ # Benchmarking suite & Cost-Accuracy Pareto evaluator
β β βββ fallback/ # Error classifier, circuit breaker & tiered fallback supervisor
β β βββ models/ # Pydantic schemas (RequestAnalysis, RoutingDecision)
β β βββ observability/ # Prometheus metrics exporter & OpenTelemetry tracer
β β βββ providers/ # Adapters (Mock, Ollama, OpenAI, Anthropic, Gemini, DeepSeek, Groq)
β β βββ router/ # Scoring matrix, pruner, rules engine & Thompson Sampling RL
β β βββ storage/ # SQLAlchemy models and SQLite async database
β βββ tests/ # Pytest suite (96 passing tests)
β βββ main.py # FastAPI application entrypoint
βββ frontend/
β βββ src/
β β βββ components/ # UI components (Navbar, RoutingMap topology graph)
β β βββ pages/ # Control Room pages (Dashboard, Playground, Rules, etc.)
β β βββ types/ # TypeScript data interfaces
β βββ package.json # Node.js dependencies
βββ sdk/
β βββ python/ # Official Python SDK (modelrouter-sdk)
β βββ typescript/ # Official TypeScript SDK (@picadolabs/modelrouter-sdk)
βββ examples/ # Standalone SDK quickstart scripts
βββ pyproject.toml # Project build metadata
βββ requirements.txt # Root Python dependencies
βββ README.md # Project documentation
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Maintained and architected by PicadoLabs.
- Maintainer: @Kaap10
- Organization: PicadoLabs
- Website: https://picadolabs.me
- Contact: picadolabs@gmail.com