✍️ Blog Post

OpenClaw Cost Optimization Guide: Cut AI Inference Spend Without Cutting Capability

7 min read

Running OpenClaw in production is powerful. The flip side: unchecked AI inference spend can balloon fast when you have crons firing every hour, multi-agent pipelines chaining tool calls, and a dozen skills hitting frontier models on every request. I run OpenClaw on a Mac mini and manage roughly 15 active crons across five sites. Getting costs under control took deliberate architecture — not just switching to cheaper models.

This guide covers the exact techniques I use: model tiering, budget caps, local Ollama fallbacks, prompt caching, and session hygiene. By the end you will have a cost-aware OpenClaw setup that keeps frontier model calls for the work that actually needs them.

Understand Where Your Spend Goes

Before optimizing, instrument. OpenClaw logs token usage per session if you enable diagnostics. Run this to get a snapshot of your last 24 hours of model usage:

openclaw sessions list --since 24h --format json | python3 -c "
import json, sys
data = json.load(sys.stdin)
for s in data:
    model = s.get('model', 'unknown')
    tokens = s.get('tokensIn', 0) + s.get('tokensOut', 0)
    print(model, tokens)
"

Group by model to find the top spenders. In my setup, the nightly research crons were the biggest line item — each one was spinning up claude-sonnet-4 for tasks that a local model handles fine.

Also check your skill files for any hardcoded model overrides. A skill that pins anthropic/claude-opus-4 for a simple summarization task will cost 10x more than the same task on haiku or a local model.

Model Tiering: Match Model to Task

The single highest-leverage change is model tiering. Not every task needs a frontier model. Here is the tier structure I use:

  • Tier 1 — Local (Ollama/gemma3:12b): background crons, summarization, classification, data normalization, heartbeat checks. Zero token cost.
  • Tier 2 — Claude Haiku or GPT-4o-mini: drafting, light research, tool-call routing, short-context Q&A. Low cost, fast latency.
  • Tier 3 — Claude Sonnet or GPT-4o: judgment calls, multi-step planning, content that ships publicly, anything with legal or financial stakes.
  • Tier 4 — Claude Opus or GPT-5: deep reasoning, architecture decisions, complex code generation. Reserve sparingly.

In your OpenClaw config, set a per-session model default and only override up when the task demands it. The config pattern looks like this (openclaw.json, agents section):

# agents.defaults.model sets the fleet-wide default
# agents.sessions overrides per named session
# Example: research-agent uses haiku, content-writer uses sonnet
openclaw config set agents.defaults.model ollama/gemma3:12b
openclaw config set agents.sessions.research-agent.model anthropic/claude-haiku-4
openclaw config set agents.sessions.content-writer.model anthropic/claude-sonnet-4-6

For cron-triggered sessions, set the model explicitly in the cron config rather than relying on the agent default. This prevents accidental Opus calls when you update the default for interactive sessions.

Budget Caps and Hard Limits

OpenClaw supports per-session and per-agent spend limits. Set them. A runaway loop or a skill that enters a retry spiral can consume hundreds of dollars in minutes without a cap.

Configure budget caps via the CLI:

# Daily fleet cap, per-session cap, per-cron cap
openclaw config set agents.budgets.daily 5.00
openclaw config set agents.budgets.perSession 0.50
openclaw config set agents.budgets.perCron 0.25

When a session hits its cap, OpenClaw pauses it and logs the event to your Telegram channel (or whatever messaging plugin you have configured). You get notified before the damage is done.

Practical thresholds from my setup: nightly crons cap at $0.10 each, interactive sessions at $1.00, and the daily fleet total is $8.00. I have not hit the fleet cap in three months — the per-session caps catch anything abnormal first.

Also set a token-per-turn limit to prevent context explosion from malformed tool responses feeding back into the model repeatedly:

openclaw config set agents.limits.maxTokensPerTurn 8000
openclaw config set agents.limits.maxTurnsPerSession 20

Local Ollama Fallbacks

Running Ollama locally is the most effective cost reduction for background work. A gemma3:12b model handles classification, summarization, data extraction, and simple Q&A at zero token cost. Setup takes about 10 minutes.

Install Ollama and pull the model:

brew install ollama
ollama pull gemma3:12b
ollama serve

Register it in OpenClaw by adding it as a provider in your openclaw.json. Use the CLI to set the provider endpoint and model alias:

openclaw config set models.providers.ollama.type ollama
openclaw config set models.providers.ollama.baseUrl http://localhost:11434
openclaw config set models.providers.ollama.models.0.id gemma3:12b
openclaw config set models.providers.ollama.models.0.alias ollama/gemma3:12b

Then route your background crons to the local model:

openclaw config set crons.daily-summarizer.model ollama/gemma3:12b
openclaw config set crons.daily-summarizer.schedule "0 6 * * *"
openclaw config set crons.daily-summarizer.skill summarize

I moved my heartbeat crons, YouTube queue verification, and site health checks to gemma3:12b. That alone cut my daily token spend by about 40%.

One caveat: local models do not handle complex multi-step reasoning or long-context tasks well. Keep them on structured, bounded inputs. If a task involves more than three tool calls or requires creative judgment, step up to at least Haiku.

For more on local model integration patterns, see the OpenClaw Local LLM Integration guide.

Prompt Caching and Context Hygiene

Prompt caching is available on Anthropic models (Claude) and reduces costs significantly when you have repeated system prompts or static context blocks. OpenClaw can cache the first N tokens of a system prompt automatically when caching is enabled.

Enable it per agent session:

openclaw config set agents.sessions.content-writer.promptCaching true

With a 2000-token system prompt and caching enabled, you pay for those tokens once per cache lifetime (roughly 5 minutes on Anthropic) instead of on every turn. For a session with 10 turns, that is a 2000-token reduction per turn — meaningful on Sonnet pricing.

Context hygiene matters just as much. Long context windows are expensive. Every token in the conversation history is re-sent with each turn. For long-running research sessions, periodically summarize and reset:

openclaw sessions summarize --session-id <session-id> --compress

This replaces the conversation history with a condensed summary, cutting context size by 60-80% while preserving continuity. I run this automatically in my research skills after 10 turns.

Also audit your system prompts. I found 3000 tokens of redundant context in my SOUL.md that was being injected into every session. Trimming it to the essential 800 tokens cut context costs by 15% fleet-wide.

Multi-Model Routing Strategies

For tasks where you need a capable model but want to minimize cost, consider routing: start with a cheaper model, escalate only when the cheaper model cannot handle it. OpenClaw supports a cost-aware routing strategy that classifies task complexity based on input length, tool count, and complexity hints from your skill.

Set up tiered routing:

openclaw config set routing.strategy cost-aware
# Tier definitions: low complexity uses local, medium uses haiku, high uses sonnet
openclaw config set routing.tiers.0.model ollama/gemma3:12b
openclaw config set routing.tiers.0.maxComplexity low
openclaw config set routing.tiers.1.model anthropic/claude-haiku-4
openclaw config set routing.tiers.1.maxComplexity medium
openclaw config set routing.tiers.2.model anthropic/claude-sonnet-4-6
openclaw config set routing.tiers.2.maxComplexity high

For a deep dive on routing patterns, see Multi-Model Routing Strategies.

Cron Consolidation

Crons that fire every 15 minutes but do light work are often better merged into a single hourly cron that batches the checks. Every cron startup has overhead: session init, system prompt injection, tool registration. Consolidating from six 15-minute crons into two 30-minute crons cut my startup overhead costs by about 25%.

Audit your cron schedule with:

openclaw crons list --format table

Look for crons with short intervals doing simple checks. Candidates for consolidation: heartbeat checks, queue length monitors, status polls, and lightweight data fetches. These can all run in a single session sequentially with minimal overhead.

For the full cron automation guide including scheduling patterns, see OpenClaw Cron Automation Guide.

Monitoring and Alerting

Set up spend monitoring so you know when something is off before you get the invoice. OpenClaw exposes metrics via the diagnostics endpoint if you have the Prometheus plugin enabled:

curl http://localhost:3000/api/diagnostics/prometheus | grep openclaw_tokens

Wire this to a simple alert: if token spend in the last hour exceeds your hourly threshold, fire a Telegram notification. I use a Python cron that reads the Prometheus output and sends an alert if spend is trending over daily cap divided by 24:

python3 ~/.openclaw/workspace/tools/spend-monitor.py --threshold 0.33 --notify telegram

This gives you real-time visibility instead of surprise end-of-month bills.

FAQ

Q: What is the biggest single change that reduces OpenClaw costs?
A: Moving background crons to a local Ollama model. Zero token cost for heartbeats, queue checks, and summarization — typically 30-50% of total fleet spend.

Q: Can I set different budget caps for different skills?
A: Yes. Budget caps can be set at the agent, session, or cron level in openclaw.json. Skill-level caps are enforced by adding a budget field to the skill config.

Q: Does prompt caching work with all models?
A: No. As of 2026, prompt caching is supported on Anthropic Claude models (Haiku, Sonnet, Opus) and some OpenAI models. Check your provider documentation. Ollama models do not support it.

Q: How do I know if my local Ollama model is being used instead of a cloud model?
A: Run openclaw sessions list --since 1h --format json and check the model field on each session. Ollama sessions show ollama/gemma3:12b or your local model alias.

Q: What is the lowest I can realistically get OpenClaw costs while keeping it useful?
A: With local models for background work, Haiku for drafting, and Sonnet reserved for judgment tasks, a full fleet running 20+ crons daily can operate for under $3/day. My current spend is about $2.40/day across the full setup.

Start with the model tier audit — look at your last 24 hours of session logs, identify the high-cost sessions, and ask whether each one actually needed a frontier model. Most do not. Route the cheap work locally, reserve the expensive models for decisions that matter, and set budget caps before you forget. Spend surprises are always preventable.

Ready to go deeper? The OpenClaw for DevOps guide covers cost-aware infrastructure automation patterns including selective model routing for monitoring vs. remediation tasks.