Analyze OpenClaw usage and generate optimized configs to reduce AI costs by 48%+
AI cost optimization for OpenClaw — Analyze usage patterns, generate optimized configs, and cut costs by 48%+ without sacrificing quality.
SmartMeter helps you save money on AI API costs by:
openclaw.json configurationsTested on live OpenClaw data:
The key insight: 69% of tasks worked perfectly with cheaper models, while premium models were only needed for 15% of complex work.
npx clawhub@latest install smartmeter
npm install -g openclaw-smartmeter
git clone https://github.com/vajih/openclaw-smartmeter.git
cd openclaw-smartmeter
npm install
npm link
smartmeter analyze
This will:
The dashboard opens at http://localhost:8080 with:
# 1. Analyze usage (opens dashboard)
smartmeter analyze [session-file.jsonl]
# 2. Preview optimizations (without applying)
smartmeter preview
# 3. Apply optimizations to openclaw.json
smartmeter apply
# 4. Rollback if needed
smartmeter rollback
# Quick cost evaluation
smartmeter evaluate examples/sample-session.jsonl
# Open dashboard (if already analyzed)
smartmeter dashboard
# Export analysis as JSON
smartmeter export --format json --output analysis.json
# Show current version
smartmeter --version
# Get help
smartmeter --help
~/.openclaw/agents/*/sessions/openclaw.json generationsmartmeter rollbackFor live usage monitoring and alerts:
# Via environment variable
export OPENROUTER_API_KEY="or-v1-xxxxxxxxxxxx"
# Or store in OpenClaw config
smartmeter config --key or-v1-xxxxxxxxxxxx
The dashboard server runs on:
To change ports, edit ~/.openclaw/smartmeter/config.json
SmartMeter reads your OpenClaw session logs:
~/.openclaw/agents/*/sessions/*.jsonl
Each log entry contains:
For each task category:
Example:
Category: code
Current: Claude Opus 4.5 ($0.80/task)
Success rate: 94%
Optimal: Claude Sonnet 4.5 ($0.38/task)
Success rate: 94% (same quality)
Savings: $0.42/task × 200 tasks = $84/month (52.5%)
Creates optimized openclaw.json:
{
"agents": {
"defaults": {
"model": {
"primary": "openrouter/auto",
"fallback": ["claude-sonnet-4-5", "claude-opus-4-5"]
},
"budget": {
"daily": 5.0,
"weekly": 30.0,
"alert": {
"telegram": true,
"threshold": 0.75
}
}
},
"code-reviewer": {
"model": "claude-sonnet-4-5",
"description": "Handles code review, debugging, and programming tasks",
"budget": { "daily": 2.0 }
},
"quick-tasks": {
"model": "deepseek/chat",
"description": "Simple queries, quick answers, config changes",
"budget": { "daily": 0.5 }
}
}
}
Run analysis:
# Check if servers are running
ps aux | grep node
# Restart servers
killall node
smartmeter analyze
# Check if session logs exist
ls -la ~/.openclaw/agents/*/sessions/
# Use sample data for testing
smartmeter analyze examples/sample-session.jsonl
# Verify API key
echo $OPENROUTER_API_KEY
# Test connection
curl -H "Authorization: Bearer $OPENROUTER_API_KEY" \
https://openrouter.ai/api/v1/auth/key
# Check config backup
ls -la ~/.openclaw/openclaw.json.backup-*
# Rollback to previous
smartmeter rollback
# Validate config manually
cat ~/.openclaw/openclaw.json | jq '.'
smartmeter analyze [file]Analyze OpenClaw usage and launch dashboard.
Options:
[file] - Optional path to specific session file~/.openclaw/agents/Output:
~/.openclaw/smartmeter/analysis.jsonsmartmeter previewPreview optimizations without applying.
Shows:
smartmeter applyApply optimizations to openclaw.json.
Safety:
openclaw.json.backup-{timestamp}smartmeter rollbackRestore previous configuration.
Process:
smartmeter dashboardOpen dashboard without re-analyzing.
Requirements:
smartmeter evaluate <file>Quick cost evaluation of session file.
Use Case:
smartmeter exportExport analysis data.
Options:
--format json|csv - Output format--output <file> - Destination filesmartmeter configManage SmartMeter configuration.
Subcommands:
--key <api-key> - Store OpenRouter API key--show - Display current config--reset - Reset to defaults# Install
npm install -g openclaw-smartmeter
# Analyze and view dashboard
smartmeter analyze
# Apply optimizations
smartmeter apply
# Analyze specific session
smartmeter analyze ~/.openclaw/agents/my-agent/sessions/session-123.jsonl
# Preview changes
smartmeter preview
# Export analysis
smartmeter export --format json --output report.json
# Apply optimizations
smartmeter apply
# Monitor for issues, rollback if needed
smartmeter rollback
# Weekly analysis (add to cron)
0 0 * * 0 smartmeter analyze && smartmeter export --format csv --output weekly-report.csv
# Budget alerts via Telegram
export TELEGRAM_BOT_TOKEN="your-token"
export TELEGRAM_CHAT_ID="your-chat-id"
smartmeter monitor --alert-threshold 0.75
No. SmartMeter only recommends changes when cheaper models achieve the same success rate. You can always preview before applying.
Minimum 2 days, but 14+ days recommended for accurate patterns. The tool will warn if data is insufficient.
Yes. All analysis happens locally on your machine. No data is sent to external servers except OpenRouter API (if you configure it).
Yes. Every change creates an automatic backup. Use smartmeter rollback to restore.
Currently optimized for OpenRouter, but works with any provider supported by OpenClaw.
SmartMeter merges with your existing config and preserves custom settings. It only modifies cost-related fields.
Found a bug? Have a feature request?
Made with 💰 by the OpenClaw community