Intelligent cost-optimizing model router for OpenClaw
Save 60-90% on your OpenClaw LLM costs by automatically routing requests to cheaper models when appropriate.
v1.1 β Intelligent, local, and private.
Works with any OpenAI-compatible client β OpenClaw, Cursor, custom apps, or direct API calls. No special detection needed.
ClawRoute is a local HTTP proxy that sits between OpenClaw and your LLM providers. It:
- Intercepts every LLM request from OpenClaw
- Classifies the task complexity using local heuristics (no API calls)
- Routes to the cheapest model that can handle it
- Escalates automatically if the cheap model fails (before streaming)
OpenClaw β ClawRoute (127.0.0.1:18790) β OpenAI/Anthropic/Google/DeepSeek
β
[Classify β Route β Execute]
β
SQLite logs (savings tracked)
# Clone and install
git clone https://github.com/user/clawroute && cd clawroute
npm install && npm run build
# Configure API keys
echo 'OPENAI_API_KEY=sk-xxx' >> .env
echo 'DEEPSEEK_API_KEY=sk-xxx' >> .env
# Start the proxy
npm start
# Configure OpenClaw to use ClawRoute
# Edit ~/.openclaw/openclaw.json:
# providers.openai.baseUrl β "http://127.0.0.1:18790/v1"| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY |
- | OpenAI API key |
ANTHROPIC_API_KEY |
- | Anthropic API key |
GOOGLE_API_KEY |
- | Google AI API key |
DEEPSEEK_API_KEY |
- | DeepSeek API key |
CLAWROUTE_PORT |
18790 |
Proxy port |
CLAWROUTE_HOST |
127.0.0.1 |
Bind address |
CLAWROUTE_TOKEN |
- | Auth token (optional) |
CLAWROUTE_DRY_RUN |
false |
Classify but don't reroute |
CLAWROUTE_DEBUG |
false |
Verbose logging |
Default tier β model mappings:
| Tier | Primary Model | Use Case |
|---|---|---|
| Heartbeat | gemini-2.5-flash-lite |
Ping/status checks |
| Simple | deepseek-chat |
Acknowledgments, short replies |
| Moderate | gemini-2.5-flash |
General conversation |
| Complex | claude-sonnet-4.5 |
Tool use, analysis |
| Frontier | claude-sonnet-4.5 |
Code, reasoning |
Customize in config/clawroute.json.
Test ClawRoute risk-free:
# Enable dry-run
CLAWROUTE_DRY_RUN=true npm start
# Or toggle at runtime
curl -X POST http://127.0.0.1:18790/api/dry-run/enableIn dry-run mode, ClawRoute:
- Classifies every request
- Logs what it would have done
- Forwards to original model unchanged
Access the real-time dashboard at: http://127.0.0.1:18790/dashboard
Features:
- Today's savings
- Tier breakdown chart
- Recent routing decisions
- Enable/disable controls
clawroute start # Start the proxy server
clawroute stats # Show today's stats
clawroute stats --week # This week's stats
clawroute stats --month # This month's stats
clawroute enable # Enable routing
clawroute disable # Disable (passthrough)
clawroute dry-run # Enable dry-run mode
clawroute live # Disable dry-run (go live)
clawroute log # Show recent routing decisions
clawroute config # Show current configClawRoute uses heuristic rules evaluated in priority order:
- Matches: "ping", "hi", "status", "test"
- Short messages (< 30 chars) with no tools
- Routes to:
gemini-2.5-flash-lite($0.075/M tokens)
- Acknowledgments: "thanks", "ok", "π"
- Short questions (< 80 chars)
- Routes to:
deepseek-chat($0.14/M tokens)
- General conversation
- Routes to:
gemini-2.5-flash($0.15/M tokens)
- Tool/function calls present
- Analytical keywords + length
- Deep conversations (> 8 messages)
- Routes to:
claude-sonnet-4.5($3/M tokens)
- Code blocks detected
- Tool calls with
tool_choiceset - Very long context (> 8K tokens)
- Routes to: original model (no downgrade)
- Streaming safety: Once streaming starts, we're committed. No interruptions, no doubled output.
- Tool call protection: Responses with tool calls are NEVER retried (prevents duplicate side effects).
- Passthrough on error: Any ClawRoute error β transparent passthrough to original model.
- Kill switch:
POST /api/disableorCLAWROUTE_ENABLED=falseimmediately stops all routing.
- Classification runs 100% locally (no API calls)
- No content logged by default (
CLAWROUTE_LOG_CONTENT=false) - No telemetry, no analytics, no phoning home
- Binds to
127.0.0.1by default (never exposed to network)
| Provider | Status | Notes |
|---|---|---|
| OpenAI | β Full | GPT-4, GPT-4o, o1 |
| DeepSeek | β Full | DeepSeek Chat |
| β Full | Gemini models (OpenAI-compatible) | |
| Anthropic | Use OpenRouter for Claude models | |
| OpenRouter | β Full | Any model via OpenRouter |
- OpenAI-compatible format only (v1.0): Native Anthropic format coming in v1.1
- Heuristic classification: Rules-based, not ML. May occasionally misclassify.
- Token estimates for streaming: Estimated from chunk count, not exact.
- Cost data: Based on published prices, may lag behind provider changes.
POST /v1/chat/completions # Main proxy (OpenAI-compatible)
GET /health # Health check
GET /stats # Full stats JSON
GET /dashboard # Web dashboard
GET /api/config # Current config (redacted)
POST /api/enable # Enable routing
POST /api/disable # Disable routing
POST /api/dry-run/enable # Enable dry-run
POST /api/dry-run/disable # Disable dry-run
POST /api/override/global # Set global model override
POST /api/override/session # Set session override
Yes! Use OpenRouter as your provider, which gives you an OpenAI-compatible interface to Claude models. Set OPENROUTER_API_KEY in your .env.
No. ClawRoute is designed to fail safe:
- Any internal error β passthrough to original model
- Streaming responses are never interrupted
- Tool calls block retry (no duplicate actions)
Multiple options:
curl -X POST http://127.0.0.1:18790/api/disable- Set
CLAWROUTE_ENABLED=falseand restart - Remove the
baseUrloverride from OpenClaw config
Yes. ClawRoute is 100% local:
- Classification is heuristic-based (no API calls)
- No content logging by default
- No telemetry or external connections
- All data stays on your machine
Contributions welcome! Please read our contributing guidelines first.
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
npm test - Submit a pull request
ClawRoute is 100% free and open-source. There is no billing for LLM usage within ClawRoute itselfβyou pay your providers (OpenAI, Anthropic, etc.) directly.
If you find this tool useful, you can optionally support development. The wallet address in the config (CLAWROUTE_DONATION_USDC_ADDR) is strictly for voluntary donations and is never used for mandatory billing or routing.
MIT License - see LICENSE for details.
Built with β€οΈ by atharv404