Model Router
A comprehensive AI model routing system that automatically selects the optimal model for any task. Set up multiple AI providers (Anthropic, OpenAI, Gemini, Moonshot, Z.ai, GLM) witโฆ
digitaladaption
@digitaladaption
Install
$ openclaw skills install @digitaladaption/model-routerModel Router
Intelligent AI model routing across multiple providers for optimal cost-performance balance.
Automatically select the best model for any task based on complexity, type, and your preferences. Support for 6 major AI providers with secure API key management and interactive configuration.
๐ฏ What It Does
- Analyzes tasks and classifies them by type (coding, research, creative, simple, etc.)
- Routes to optimal models from your configured providers
- Optimizes costs by using cheaper models for simple tasks
- Secures API keys with file permissions (600) and isolated storage
- Provides recommendations with confidence scoring and reasoning
๐ Quick Start
Step 1: Run the Setup Wizard
cd skills/model-router
python3 scripts/setup-wizard.py
The wizard will guide you through:
- Provider setup - Add your API keys (Anthropic, OpenAI, Gemini, etc.)
- Task mappings - Choose which model for each task type
- Preferences - Set cost optimization level
Step 2: Use the Classifier
# Get model recommendation for a task
python3 scripts/classify_task.py "Build a React authentication system"
# Output:
# Recommended Model: claude-sonnet
# Confidence: 85%
# Cost Level: medium
# Reasoning: Matched 2 keywords: build, system
Step 3: Route Tasks with Sessions
# Spawn with recommended model
sessions_spawn --task "Debug this memory leak" --model claude-sonnet
# Use aliases for quick access
sessions_spawn --task "What's the weather?" --model haiku
๐ Supported Providers
| Provider | Models | Best For | Key Format |
|---|---|---|---|
| Anthropic | claude-opus-4-5, claude-sonnet-4-5, claude-haiku-4-5 | Coding, reasoning, creative | sk-ant-... |
| OpenAI | gpt-4o, gpt-4o-mini, o1-mini, o1-preview | Tools, deep reasoning | sk-proj-... |
| Gemini | gemini-2.0-flash, gemini-1.5-pro, gemini-1.5-flash | Multimodal, huge context (2M) | AIza... |
| Moonshot | moonshot-v1-8k/32k/128k | Chinese language | sk-... |
| Z.ai | glm-4.5-air, glm-4.7 | Cheapest, fast | Various |
| GLM | glm-4-flash, glm-4-plus, glm-4-0520 | Chinese, coding | ID.secret |
๐๏ธ Task Type Mappings
Default routing (customizable via wizard):
| Task Type | Default Model | Why |
|---|---|---|
simple | glm-4.5-air | Fastest, cheapest for quick queries |
coding | claude-sonnet-4-5 | Excellent code understanding |
research | claude-sonnet-4-5 | Balanced depth and speed |
creative | claude-opus-4-5 | Maximum creativity |
math | o1-mini | Specialized reasoning |
vision | gemini-1.5-flash | Fast multimodal |
chinese | glm-4.7 | Optimized for Chinese |
long_context | gemini-1.5-pro | Up to 2M tokens |
๐ฐ Cost Optimization
Aggressive Mode
Always uses the cheapest capable model:
- Simple โ glm-4.5-air (~10% cost)
- Coding โ claude-haiku-4-5 (~25% cost)
- Research โ claude-sonnet-4-5 (~50% cost)
Savings: 50-90% compared to always using premium models
Balanced Mode (Default)
Considers cost vs quality:
- Simple tasks โ Cheap models
- Critical tasks โ Premium models
- Automatic escalation if cheap model fails
Quality Mode
Always uses the best model regardless of cost
๐ Security
API Key Storage
~/.model-router/
โโโ config.json # Model mappings (chmod 600)
โโโ .api-keys # API keys (chmod 600)
Features:
- File permissions restricted to owner (600)
- Isolated from version control
- Encrypted at rest (via OS filesystem encryption)
- Never logged or printed
Best Practices
- Never commit
.api-keysto version control - Use environment variables for production deployments
- Rotate keys regularly via the wizard
- Audit access with
ls -la ~/.model-router/
๐ Usage Examples
Example 1: Cost-Optimized Workflow
# Classify task first
python3 scripts/classify_task.py "Extract prices from this CSV"
# Result: simple task โ use glm-4.5-air
sessions_spawn --task "Extract prices" --model glm-4.5-air
# Then analyze with better model if needed
sessions_spawn --task "Analyze price trends" --model claude-sonnet
Example 2: Progressive Escalation
# Try cheap model first (60s timeout)
sessions_spawn --task "Fix this bug" --model glm-4.5-air --runTimeoutSeconds 60
# If fails, escalate to premium
sessions_spawn --task "Fix complex architecture bug" --model claude-opus
Example 3: Parallel Processing
# Batch simple tasks in parallel with cheap model
sessions_spawn --task "Summarize doc A" --model glm-4.5-air &
sessions_spawn --task "Summarize doc B" --model glm-4.5-air &
sessions_spawn --task "Summarize doc C" --model glm-4.5-air &
wait
Example 4: Multimodal with Gemini
# Vision task with 2M token context
sessions_spawn --task "Analyze these 100 images" --model gemini-1.5-pro
๐ ๏ธ Configuration Files
~/.model-router/config.json
{
"version": "1.1.0",
"providers": {
"anthropic": {
"configured": true,
"models": ["claude-opus-4-5", "claude-sonnet-4-5", "claude-haiku-4-5"]
},
"openai": {
"configured": true,
"models": ["gpt-4o", "gpt-4o-mini", "o1-mini", "o1-preview"]
}
},
"task_mappings": {
"simple": "glm-4.5-air",
"coding": "claude-sonnet-4-5",
"research": "claude-sonnet-4-5",
"creative": "claude-opus-4-5"
},
"preferences": {
"cost_optimization": "balanced",
"default_provider": "anthropic"
}
}
~/.model-router/.api-keys
# Generated by setup wizard - DO NOT edit manually
ANTHROPIC_API_KEY=sk-ant-...
OPENAI_API_KEY=sk-proj-...
GEMINI_API_KEY=AIza...
๐ Version 1.1 Changes
New Features
- โ Interactive setup wizard for guided configuration
- โ Secure API key storage with file permissions
- โ Task-to-model mapping customization
- โ Multi-provider support (6 providers)
- โ Cost optimization levels (aggressive/balanced/quality)
Improvements
- โ Better task classification with confidence scores
- โ Provider-specific model recommendations
- โ Enhanced security with isolated storage
- โ Comprehensive documentation
Migration from 1.0
Run the setup wizard to reconfigure:
python3 scripts/setup-wizard.py
๐ Command Reference
Setup Wizard
python3 scripts/setup-wizard.py
Interactive configuration of providers, mappings, and preferences.
Task Classifier
python3 scripts/classify_task.py "your task description"
python3 scripts/classify_task.py "your task" --format json
Get model recommendation with reasoning.
List Models
python3 scripts/setup-wizard.py --list
Show all available models and their status.
๐ค Integration with Other Skills
| Skill | Integration |
|---|---|
| model-usage | Track cost per provider to optimize routing |
| sessions_spawn | Primary tool for model delegation |
| session_status | Check current model and usage |
โก Performance Tips
- Start simple - Try cheap models first
- Batch tasks - Combine multiple simple tasks
- Use cleanup - Delete sessions after one-off tasks
- Set timeouts - Prevent runaway sub-agents
- Monitor usage - Track costs per provider
๐ Troubleshooting
"No suitable model found"
- Run setup wizard to configure providers
- Check API keys are valid
- Verify permissions on
.api-keysfile
"Module not found"
pip3 install -r requirements.txt # if needed
Wrong model selected
- Customize task mappings via wizard
- Use explicit model in
sessions_spawn --model - Adjust cost optimization preference
๐ Additional Resources
Related skills
Save Money
@peterokase42Auto-detect task complexity for Claude models (Haiku + Sonnet). Route simple tasks to Haiku, escalate complex ones to Sonnet. Save 50%+ on API costs. | ้ฉ็จ Claude ๆจกๅ๏ผHaiku + Sonnet๏ผ๏ผ่ชๅๅตๆธฌไปปๅ้ฃๅบฆ๏ผ็ฐกๅฎ็จ Haiku๏ผ่ค้ๅ็ด Sonnet๏ผ่ผ้ฌ็ไธ 50% ไปฅไธ็่ฒป็จใโ RULES: Before responding, classify the task. If it matches an escalation trigger, call sessions_spawn with the full task and model anthropic/claude-sonnet-4-20250514 IMMEDIATELY. Do NOT answer complex tasks yourself. ESCALATE: analysis, comparisons, planning, strategy, code >10 lines, reports, proposals, multi-step reasoning, tables, outlines, charts, long writing >3 paragraphs, summarization, long translation. NEVER on Haiku: comparison tables, code >10 lines, multi-step analysis, reports, complex reasoning. STAY on Haiku: factual Q&A, definitions, greetings, reminders, short lookups, casual chat, 1-2 sentence tasks. When in doubt, escalate. Keep Haiku replies concise.
Model Usage
@steipeteUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
Openclaw Agent Optimize
@phenomenonerUse when: you want a structured audit -> options -> recommended plan to improve an OpenClaw workspace (cost, model routing, context discipline, delegation, r...
Git-Based Knowledge Graph Memory System for Claude Code
@mourad-ghafiriGit-Notes-Based knowledge graph memory system. Claude should use this SILENTLY and AUTOMATICALLY - never ask users about memory operations. Branch-aware persistent memory using git notes. Handles context, decisions, tasks, and learnings across sessions.
Humanizer
@biostartechnologyRemove signs of AI-generated writing from text. Use when editing or reviewing text to make it sound more natural and human-written. Based on Wikipedia's comprehensive "Signs of AI writing" guide. Detects and fixes patterns including: inflated symbolism, promotional language, superficial -ing analyses, vague attributions, em dash overuse, rule of three, AI vocabulary words, negative parallelisms, and excessive conjunctive phrases.
Smart Model Switching
@millibusAuto-route tasks to the cheapest Claude model that works correctly. Three-tier progression: Haiku โ Sonnet โ Opus. Classify before responding. HAIKU (default): factual Q&A, greetings, reminders, status checks, lookups, simple file ops, heartbeats, casual chat, 1-2 sentence tasks. ESCALATE TO SONNET: code >10 lines, analysis, comparisons, planning, reports, multi-step reasoning, tables, long writing >3 paragraphs, summarization, research synthesis, most user conversations. ESCALATE TO OPUS: architecture decisions, complex debugging, multi-file refactoring, strategic planning, nuanced judgment, deep research, critical production decisions. Rule: If a human needs >30 seconds of focused thinking, escalate. If Sonnet struggles with complexity, go to Opus. Save 50-90% on API costs by starting cheap and escalating only when needed.