model-router
Model Router — Kostenbewusstes Multi-LLM-Routing mit Free-First-Fallback-Kette
Leite jede Aufgabe automatisch an das beste Modell weiter – zuerst kostenlose Anbieter, kostenpflichtige als Fallback.
🎯 Warum Model Router?
Die meisten LLM-Integrationscodes verwenden ein fest codiertes Modell oder einen einzigen API-Anbieter. Das bedeutet:
❌ Teuer: Jede Anfrage (auch triviale) geht an ein kostenpflichtiges Spitzenmodell
❌ Anfällig: Ein Ausfall eines Anbieters = Totalausfall
❌ Unflexibel: Keine Möglichkeit, Modellfähigkeiten an die Aufgabenschwierigkeit anzupassen
Model Router löst alle drei Probleme mit einem einfachen, abhängigkeitsarmen Design:
✅ Aufgabenschwierigkeitsklassifizierung: 5 Stufen (
vision/long/complex/medium/simple) mittels Schlüsselwort- und Inhaltslängen-Heuristiken (kostenlos, kein LLM beteiligt)✅ Free-First-Fallback-Kette: Jede Routing-Stufe definiert eine geordnete Kandidatenkette – zuerst werden kostenlose Anbieter (Zhipu, SiliconFlow, OpenRouter kostenlose Modelle) versucht; bei einem Fehlschlag wird automatisch der nächste Kandidat (ggf. kostenpflichtige DeepSeek/Qwen/GLM/Kimi) versucht
✅ Keine Drittanbieter-Abhängigkeiten: Die Kernbibliothek benötigt nur
requests; der MCP-Server ist reine Stdlib (JSON-RPC 2.0 über stdio)✅ Mehrere Schnittstellen: Python-API · CLI · MCP-Server (jeder MCP-Client: Claude, Qoder, Cursor…) · File-Watch-Daemon
🏗 Architektur
┌─────────────────────────────────────────────┐
│ router_core.py │
│ │
task_desc ──▶│ classify_task() → 5 difficulty levels │
content ──▶│ _get_candidates() → ordered provider chain│
image ──────▶│ route_and_call() → free-first, fallback │
│ │
└──────────────┬──────────────────────────────┘
│
┌────────────────┼───────────────────┐
▼ ▼ ▼
auto_router.py mcp_server.py Python API
(CLI + daemon) (MCP tools) (import router_core)Routing-Stufen
Stufe | Auslöser | Typische Modelle |
| Bild/Screenshot/OCR | Qwen-VL, GLM-4V |
| Inhalt > 2000 Zeichen, vollständige Dokumente | 128K-Kontext-Modelle |
| Analyse/Code/Daten/Statistiken/Argumentation | DeepSeek, Qwen3-32B |
| Schreiben/Übersetzen/Verfeinern | GLM, Qwen |
| Täglicher Chat / schnelle Anfragen | kleine kostenlose Modelle |
Fallback-Semantik: Kandidaten werden der Reihe nach versucht; die Antwort meldet tier (free/paid), attempts, fallback_used und anbieterbezogene errors für vollständige Beobachtbarkeit.
🚀 Schnellstart
# 1. Install (only requests is required)
pip install requests
# 2. Configure
cp config.example.json config.json
# → fill in your API keys
# 3. CLI — analyze only (zero cost, no model call)
python router_core.py analyze "分析这份气象数据"
# 4. CLI — route and call
python router_core.py call "翻译以下段落" --content "Hello world" --system "你是专业翻译"
# 5. Python API
from router_core import route_and_call, analyze_task
result = analyze_task("写一份论文摘要", content_len=300)
print(result["primary"]) # first candidate
print(result["candidates"]) # full fallback chain
text = route_and_call("总结要点", "long text...")["content"]🖥 MCP-Server (für jeden MCP-Client)
python mcp_server.pyTool | Beschreibung |
| Automatisches Routing + Aufruf (zuerst kostenlos, Fallback bei Fehler) |
| Schwierigkeit analysieren + Kandidatenkette zurückgeben (kostenlos) |
| Alle konfigurierten Anbieter, Modelle und Ketten auflisten |
Registrieren Sie in Ihrem MCP-Client (z.B. Claude Desktop claude_desktop_config.json):
{
"mcpServers": {
"model-router": {
"command": "python",
"args": ["/path/to/model-router/mcp_server.py"],
"env": {"PYTHONIOENCODING": "utf-8"}
}
}
}⏱ Aufgabengetriggerter Daemon (File-Watch-Modus)
# One-shot
python auto_router.py "任务描述" -c "内容" --image photo.png
# Daemon: drop task files into inbox/, results appear in outbox/
python auto_router.py --watch --dir ./tasks🔧 Konfiguration
config.json-Struktur (siehe config.example.json):
providers: OpenAI-kompatible Endpunkte mit
tier(free/paid) und optionalemenabled: falserouting: Pro Stufe geordnete
candidates-Ketten – zuerst kostenlos, kostenpflichtig als Sicherheitsnetzlevels: Menschenlesbare Beschreibungen pro Stufe
Fügen Sie Anbieter frei hinzu oder entfernen Sie sie – der Router ist vollständig datengesteuert.
📄 Lizenz
MIT – kostenlos für private und kommerzielle Nutzung. Siehe LICENSE.
Inspiriert von realer Kostenoptimierung: ~90% der alltäglichen Aufgaben können von kostenlosen Modellen bedient werden, während schwierige Aufgaben durch automatischen Fallback weiterhin Spitzenmodellqualität erhalten.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
Agent Cost Allocator MCP — multi-tenant LLM cost attribution for chargeback billing. Companion to
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/yaowanxiang/model-router'
If you have feedback or need assistance with the MCP directory API, please join our Discord server