Openclaw Smart Router
by @atlaspa
Automatically routes AI requests to cost-optimal models based on task complexity and budget, saving 30-50% on model expenses with adaptive learning.
clawhub install openclaw-smart-routerπ About This Skill
name: smart-router user-invocable: true metadata: {"openclaw":{"emoji":"π―","requires":{"bins":["node"]},"os":["darwin","linux","win32"]}}
OpenClaw Smart Router
Save 30-50% on model costs through intelligent, automatic model selection.
What is it?
The first OpenClaw skill that automatically routes requests to optimal models based on complexity analysis and budget constraints. Stops you from wasting money on expensive models for simple tasks. Learns from your usage patterns and gets smarter over time.
Key Features
Free vs Pro Tier
Free Tier:
Pro Tier (0.5 USDT/month):
Installation
claw skill install openclaw-smart-router
Commands
# View routing stats
claw router statsAnalyze complexity
claw router analyze "Your task description..."View routing history
claw router history --limit=10Show cost savings
claw router savingsOpen dashboard
claw router dashboardSubscribe to Pro
claw router subscribe
How It Works
1. Intercepts requests - Hooks before each API call 2. Analyzes complexity - Scores task from 0.0 (simple) to 1.0 (expert) 3. Checks budget - Considers spending limits 4. Selects model - Chooses optimal model: - Simple (0.0-0.3) β Haiku/GPT-3.5 - Medium (0.3-0.6) β Sonnet/GPT-4-Turbo - Complex (0.6-0.8) β Opus/GPT-4 - Expert (0.8-1.0) β Opus/GPT-4 5. Routes request - Sends to selected model 6. Learns from result - Tracks success and adapts
Complexity Scoring
What makes a task complex?
Examples:
Simple (0.0-0.3) β Haiku:
Medium (0.3-0.6) β Sonnet:
Complex (0.6-0.8) β Opus:
Expert (0.8-1.0) β Opus:
Use Cases
Cost Savings Examples
Example 1: Development Work
Without Smart Router:
100 requests/day to Opus
$0.015 per request
Monthly: $45 With Smart Router:
30 requests to Haiku ($0.90)
50 requests to Sonnet ($7.50)
20 requests to Opus ($9.00)
Monthly: $17.40 Savings: $27.60/month (61%)
Example 2: Customer Support
Without Smart Router:
500 requests/day to GPT-4
Monthly: $300 With Smart Router:
400 to GPT-3.5 ($24)
80 to GPT-4-Turbo ($24)
20 to GPT-4 ($12)
Monthly: $60 Savings: $240/month (80%)
Agent Economy
Agents can autonomously evaluate if Pro tier is worth it:
Example ROI:
Agent making 100 requests/day:
Without router: $45/month
With router: $17.40/month
Savings: $27.60/month
Pro cost: $0.50/month
Net profit: $27.10/month
ROI: 5,420%
Economic rationale: If routing decisions save more than 0.5 USDT/month in model costs, Pro tier pays for itself. Agent can autonomously pay via x402 without human approval.
See AGENT-PAYMENTS.md for x402 integration details.
Pattern Learning
Smart Router learns from your usage:
Example Learning:
Pattern detected: "Debug Python errors"
History: Haiku failed 3 times, Sonnet succeeded 5 times
Learning: Always use Sonnet+ for Python debuggingNext time: "Debug this Python error..."
β Automatically routes to Sonnet instead of Haiku
What it learns:
Integration with Other Tools
Memory System
Context Optimizer
Cost Governor
# Install full efficiency suite
claw skill install openclaw-memory
claw skill install openclaw-context-optimizer
claw skill install openclaw-smart-router
Privacy
~/.openclaw/openclaw-smart-router/Dashboard
Access web UI at http://localhost:9093:
ROI Tracking
Smart Router automatically calculates return on investment:
$ claw router savingsCost Analysis (Last 30 Days)
ββββββββββββββββββββββββββββββββ
Routing decisions: 2,847
Average complexity: 0.45
Model distribution:
Haiku: 42% ($3.60)
Sonnet: 49% ($21.00)
Opus: 9% ($11.12) Total actual cost: $35.72
Without Smart Router: $128.12
Savings: $92.40 (72%)
Pro cost: $0.50/month
Net profit: $91.90/month
ROI: 18,380% π
Requirements
API Reference
# Analyze complexity
POST /api/analyze
{
"agent_wallet": "0x...",
"query": "Task description...",
"context_length": 1500
}Response:
{
"complexity": 0.65,
"recommended_model": "claude-sonnet-4-5",
"recommended_provider": "anthropic",
"estimated_cost": 0.008,
"reasoning": "Medium complexity code task"
}Get routing stats
GET /api/stats?agent_wallet=0x...Get savings analysis
GET /api/savings?agent_wallet=0x...Get learned patterns
GET /api/patterns?agent_wallet=0x...x402 payment endpoints
POST /api/x402/subscribe
POST /api/x402/verify
GET /api/x402/license/:wallet
Budget Awareness
Smart Router respects your spending limits:
Budget levels:
Budget strategies:
Budget constraint handling:
IF daily_limit_reached:
β Downgrade to cheapest viable model
β Warn user about constraint
β Log budget event
Supported Models
Anthropic:
OpenAI:
Google:
Custom providers:
Statistics Example
Smart Router Stats (30 Days)
ββββββββββββββββββββββββββββββββ
Total decisions: 2,847
Avg complexity: 0.45Complexity breakdown:
Simple (0.0-0.3): 42%
Medium (0.3-0.6): 37%
Complex (0.6-0.8): 15%
Expert (0.8-1.0): 6% Model distribution:
Haiku: 1,200 (42%)
Sonnet: 1,400 (49%)
Opus: 247 (9%) Cost: $35.72 (vs $128.12 without)
Savings: 72% ($92.40/month)
Pattern learning:
23 patterns identified
94% success rate
342 pattern applications
Economic Rationale
Should you upgrade to Pro?
Calculate your potential savings:
Current requests/day Γ Avg cost per request = Monthly cost
Apply 30-50% savings = Amount saved
If saved amount > 0.5 USDT/month β Pro pays for itself
Typical savings:
ROI gets better with scale.
Links
Built by the OpenClaw community | First smart model router with x402 payments