π¦ ClawHub
Cost Guardian
by @mariusfit
Track, analyze, and optimize AI and infrastructure costs with budgeting, spend forecasts, token usage scans, and optimization suggestions.
TERMINAL
clawhub install cost-guardianπ About This Skill
cost-guardian β AI & Infrastructure Cost Tracker
Track, analyze, and optimize the total cost of running your AI agent and infrastructure. Budget alerts, spend forecasts, and concrete optimization recommendations.
Commands
Initialize
python scripts/cost-guardian.py init
Creates config and database in ~/.openclaw/workspace/costs/.Track a Cost Entry
# Track API spend
python scripts/cost-guardian.py track --provider openai --amount 12.50 --currency USD --period monthly --category apiTrack infrastructure cost
python scripts/cost-guardian.py track --provider hetzner --amount 5.00 --currency EUR --period monthly --category hostingTrack one-time cost
python scripts/cost-guardian.py track --provider cloudflare --amount 10.00 --currency USD --period once --category domainTrack electricity
python scripts/cost-guardian.py track --provider electricity --amount 15.00 --currency EUR --period monthly --category power
Scan Token Usage from Gateway Logs
# Scan recent gateway logs for token consumption per model
python scripts/cost-guardian.py scan-tokensScan specific days
python scripts/cost-guardian.py scan-tokens --days 7
Set Budget
# Monthly budget
python scripts/cost-guardian.py budget --monthly 50.00 --currency EURBudget with alert threshold (alert at 80%)
python scripts/cost-guardian.py budget --monthly 50.00 --alert-pct 80
Cost Report
# Current month report
python scripts/cost-guardian.py reportWeekly report
python scripts/cost-guardian.py report --period weekJSON output
python scripts/cost-guardian.py report --jsonSpecific month
python scripts/cost-guardian.py report --month 2026-02
Optimization Recommendations
# Get optimization suggestions
python scripts/cost-guardian.py optimizeJSON output
python scripts/cost-guardian.py optimize --json
Forecast Spend
# Forecast next 3 months
python scripts/cost-guardian.py forecastForecast next N months
python scripts/cost-guardian.py forecast --months 6JSON output
python scripts/cost-guardian.py forecast --json
Manage Subscriptions
# Add a subscription
python scripts/cost-guardian.py sub add --name "OpenRouter" --amount 20.00 --currency USD --cycle monthly --renews 2026-03-15 --category apiList subscriptions
python scripts/cost-guardian.py sub listRemove a subscription
python scripts/cost-guardian.py sub remove --name "OpenRouter"Check upcoming renewals
python scripts/cost-guardian.py sub upcoming --days 14
Status Dashboard
# Quick status overview
python scripts/cost-guardian.py statusJSON output
python scripts/cost-guardian.py status --json
Categories
api β AI model API costs (OpenAI, Anthropic, OpenRouter, etc.)hosting β VPS, cloud, domain, DNSpower β Electricity for homelabsubscription β SaaS subscriptionshardware β One-time hardware purchasesother β Everything elseOutput Modes
All commands support:
--json) β structured data for programmatic useCron Integration
Add to OpenClaw cron for automated cost tracking:
scan-tokens to track API usagereport --period week for digestreport + forecast for full analysisoptimize when looking to cut costsData Storage
All data stored in ~/.openclaw/workspace/costs/:
config.json β budget settings, preferencescosts.db β SQLite database (entries, subscriptions, token scans)Zero Dependencies
Pure Python 3 stdlib β no pip install needed. Uses sqlite3, json, datetime, pathlib.