Cost Optimization: Keep API Bills Under Control
Practical strategies for reducing OpenClaw API costs: what costs money, model routing, active hours, usage monitoring, and spending limits.
#Understanding OpenClaw Costs
OpenClaw itself is free and open-source. The costs come from the LLM API providers, Anthropic, OpenAI, Google, that power your agent's intelligence. Every time your agent processes a message, runs a heartbeat cycle, or executes a cron job, it sends tokens to the API and you pay for those tokens.
The number one complaint from new OpenClaw users is unexpected API bills. A carelessly configured agent with Claude Opus 4.6 can easily cost $200-500/month. With proper optimization, you can run a fully functional agent for $10-30/month.
#What Costs Money
| Activity | Frequency | Typical Cost per Event | Monthly Impact |
|---|---|---|---|
| Heartbeat cycles | Every 10-15 min | $0.002-0.05 | $5-200 |
| User conversations | Varies | $0.01-0.10 per message | $5-50 |
| Cron jobs | Scheduled | $0.01-0.05 per execution | $2-30 |
| Skill execution | On demand | $0.01-0.20 per invocation | $5-50 |
| Context window | Every request | Included in above | n/a |
The heartbeat is typically the largest expense because it runs continuously, even when you are not interacting with the agent.
#Cost by Model
Understanding per-token pricing helps you make informed decisions:
| Model | Input (per 1M tokens) | Output (per 1M tokens) | Relative Cost |
|---|---|---|---|
| Claude Opus 4.6 | $15.00 | $75.00 | 15x baseline |
| Claude Sonnet 4.6 | $3.00 | $15.00 | 3x baseline |
| Claude Haiku 4 | $1.00 | $5.00 | Baseline |
| GPT-5.2 | $3.00 | $12.00 | 3x baseline |
| Gemini 3.1 Pro | $2.50 | $10.00 | 2.5x baseline |
| Gemini 3 Flash | $0.10 | $0.40 | 0.1x baseline |
Claude Haiku 4 and Gemini 3 Flash provide excellent capability for routine tasks at a fraction of the cost. Gemini 3 Flash has a generous free tier. Reserve expensive models like Opus 4.6 and o3 for tasks that truly need them.
#Strategy 1: Model Routing
The single most effective cost optimization is using different models for different tasks. There is no reason to use Claude Opus 4.6 for checking whether a reminder is due.
#Recommended Model Routing Configuration
{ "model_routing": { "default": "claude-sonnet-4-6-20260217", "heartbeat": "claude-haiku-4-20260210", "quick_response": "claude-haiku-4-20260210", "complex_reasoning": "claude-sonnet-4-6-20260217", "code_generation": "claude-sonnet-4-6-20260217", "summarization": "claude-haiku-4-20260210", "creative_writing": "claude-sonnet-4-6-20260217" }}#Cost Impact of Model Routing
| Configuration | Estimated Monthly Cost |
|---|---|
| Everything on Opus 4.6 | $200-500 |
| Everything on Sonnet 4.6 | $40-100 |
| Sonnet 4.6 default + Haiku 4 heartbeat | $15-50 |
| Haiku 4 default + Sonnet 4.6 for complex tasks | $10-30 |
| Gemini 3 Flash heartbeat + Haiku 4 default | $5-15 |
#Automatic Routing with Smart Escalation
OpenClaw can automatically determine when a cheaper model is insufficient and escalate:
{ "model_routing": { "default": "claude-haiku-4-20260210", "smart_escalation": { "enabled": true, "escalation_model": "claude-sonnet-4-6-20260217", "escalation_triggers": [ "complex_task_detected", "multi_step_reasoning", "code_generation", "long_form_writing", "user_requested" ], "max_escalations_per_hour": 10 } }}With smart escalation, Haiku handles 80-90% of interactions, and Sonnet only activates when needed. This can cut costs by 60-70% compared to using Sonnet for everything.
#Strategy 2: Optimize the Heartbeat
The heartbeat is your biggest cost lever. See the Heartbeat & Cron Guide for detailed configuration.
#Quick Wins
Switch heartbeat to Haiku:
{ "heartbeat": { "model": "claude-haiku-4-20260210" }}Savings: 80-95% of heartbeat costs.
Increase the interval:
{ "heartbeat": { "interval_minutes": 30 }}Savings: 50% (compared to 15-minute interval).
Set active hours:
{ "heartbeat": { "active_hours": { "start": "08:00", "end": "22:00", "timezone": "America/New_York" }, "interval_minutes": 15, "sleep_interval_minutes": 120 }}Savings: 30-40% by reducing overnight cycles.
Combine all three optimizations:
Using Haiku, 30-minute intervals during active hours (8 AM - 10 PM), and 2-hour intervals overnight reduces heartbeat costs from ~$200/month (Opus, 10-min) to ~$3/month.
#Strategy 3: Limit Context Window Size
Every request includes conversation history (context). Longer context means more input tokens and higher costs. Configure maximum context to control this:
{ "context": { "max_history_messages": 20, "max_context_tokens": 4096, "summarize_old_context": true, "summary_model": "claude-haiku-4-20260210" }}max_history_messages: Keep only the last N messages in contextmax_context_tokens: Hard cap on context size in tokenssummarize_old_context: When true, old messages are summarized rather than included verbatimsummary_model: Use a cheap model for summarization
Context summarization is particularly effective for long conversations. Instead of sending 50 messages of history (expensive), OpenClaw summarizes them into a paragraph (cheap) and includes only recent messages verbatim.
#Strategy 4: Set Spending Limits
#Provider-Level Limits
Set spending limits directly on each provider's dashboard:
- Anthropic: Console > Settings > Limits > Monthly spending limit
- OpenAI: Platform > Settings > Limits > Usage limit
- Google: Cloud Console > Billing > Budgets & alerts
#OpenClaw-Level Limits
Configure spending awareness in OpenClaw:
{ "cost_management": { "daily_budget": 5.00, "monthly_budget": 50.00, "alert_at_percentage": 80, "action_on_limit": "downgrade_model", "downgrade_to": "claude-haiku-4-20260210", "notification_channel": "telegram" }}When the daily or monthly budget is approaching:
- At 80%: Send an alert to your notification channel
- At 100%: Downgrade to the cheapest model (Haiku) instead of stopping entirely
This ensures your agent keeps running but stops using expensive models when the budget is exhausted.
#Strategy 5: Optimize Cron Jobs
Each cron job is an API call. Review your cron jobs and optimize:
#Use Appropriate Models
| Cron Job Type | Recommended Model |
|---|---|
| Email check | Haiku 4 |
| Calendar briefing | Haiku 4 |
| News summarization | Sonnet 4.6 |
| Weekly review | Sonnet 4.6 |
| Simple monitoring | Haiku 4 |
| Complex analysis | Sonnet 4.6 (sparingly) |
#Reduce Frequency
Do you really need to check email every 15 minutes? Every hour is usually sufficient for most users.
#Consolidate Jobs
Instead of three separate morning cron jobs (email, calendar, weather), combine them into one:
Schedule: 0 8 * * *Task: "Morning briefing: Check my unread emails, today's calendar,and the weather forecast. Give me everything in one summary."One API call instead of three.
#Pause Unnecessary Jobs
Review each job and ask: "Is this still providing value?" Pause or remove jobs that are not. There is no cron pause: pausing a job is disable, and the docs say to "Use openclaw automations enable <job-id> to resume scheduled runs."
#Strategy 6: Monitor Usage
You cannot optimize what you do not measure. Regularly check your usage:
#Daily Usage Report
There is no top-level openclaw usage command and no --last flag. openclaw gateway usage-cost will "Fetch usage-cost summaries from session logs", and the window is --days, which defaults to 30:
API Usage (Last 24 Hours)=========================Total tokens: 45,832Estimated cost: $1.23Breakdown: Heartbeat: 12,400 tokens ($0.15) Conversations: 28,200 tokens ($0.89) Cron jobs: 5,232 tokens ($0.19)By model: claude-haiku-4: 32,100 tokens ($0.32) claude-sonnet-4.6: 13,732 tokens ($0.97)#Weekly Totals
There is no documented --trend flag. Widen the window instead, and add --all-agents to "Aggregate across all configured agents" or --agent <id> for one of them:
Daily Cost Trend (Last 7 Days): Mon: $1.45 ████████████████ Tue: $0.98 ███████████ Wed: $2.31 █████████████████████████ Thu: $1.12 ████████████ Fri: $0.87 ██████████ Sat: $0.43 █████ Sun: $0.52 ██████Average: $1.10/dayProjected monthly: $33.00#Set Up Usage Alerts
There is no openclaw config edit. Ask the CLI where the live file is: openclaw config file "Prints the active config file path", and you open that path in your editor.
{ "cost_management": { "alerts": [ { "type": "daily_spend", "threshold": 3.00, "channel": "telegram", "message": "Daily spending exceeded $3. Current: {amount}" }, { "type": "unusual_spike", "threshold_multiplier": 3.0, "channel": "telegram", "message": "Unusual usage spike detected: {details}" } ] }}#Strategy 7: Use Free and Cheaper Providers
#Google Gemini Free Tier
Gemini 3 Flash has a generous free tier that covers many heartbeat and lightweight tasks:
- 15 requests per minute
- 1 million tokens per minute
- 1,500 requests per day
Configure Gemini as your heartbeat model:
{ "heartbeat": { "model": "gemini-3-flash" }, "providers": { "google": { "api_key": "your-key", "enabled": true } }}#Mix Providers for Cost Optimization
{ "model_routing": { "heartbeat": "gemini-3-flash", "quick_response": "gpt-5.2", "default": "claude-sonnet-4-6-20260217", "complex_reasoning": "claude-sonnet-4-6-20260217" }}This uses the cheapest provider for each task category, potentially reducing costs by 50-70%.
#Monthly Cost Estimates by Use Case
#Light Personal Use ($5-15/month)
- Haiku default model
- 30-minute heartbeat with active hours
- 2-3 cron jobs
- 10-20 messages per day
#Moderate Personal Use ($15-40/month)
- Sonnet 4.6 default, Haiku 4 heartbeat
- 15-minute heartbeat with active hours
- 5-10 cron jobs
- 30-50 messages per day
#Heavy / Professional Use ($40-100/month)
- Sonnet 4.6 default, Opus 4.6 for complex tasks
- 10-minute heartbeat
- 10+ cron jobs
- 100+ messages per day
#Unoptimized ($200-500/month)
- Opus 4.6 for everything
- 10-minute heartbeat, 24/7
- No active hours
- No model routing
The difference between an optimized and unoptimized configuration can be 10-20x in monthly costs. Spend 20 minutes configuring model routing and heartbeat settings, it pays for itself immediately.
#Cost Optimization Checklist
- Heartbeat uses Haiku 4 or Gemini 3 Flash (not Sonnet or Opus)
- Heartbeat interval is 15 minutes or more
- Active hours are configured to reduce overnight cycles
- Model routing is configured for different task types
- Smart escalation is enabled
- Context window size is limited
- Spending limits are set on provider dashboards
- OpenClaw cost alerts are configured
- Cron jobs use appropriate models (Haiku 4 for simple tasks)
- Unnecessary cron jobs are paused or removed
- Usage is monitored weekly
- Consolidated cron jobs where possible
#Next Steps
- Heartbeat & Cron Configuration: detailed heartbeat tuning
- API Key Setup: configure multiple providers for cost optimization
- Understanding Skills: skills affect cost through API usage
- Troubleshooting: when cost limits cause unexpected behavior