Ray Fu, ex-Meta senior engineer and AI automation educator

Ray Fu

I'm an Ex Meta Senior Engineer that makes content and teaches OpenClaw and AI Automations.

stan.store/raycfu

How to save money on tokens with Openclaw guide

Don't want to figure this out alone? I walk members through every step inside the community. Join the Skool → skool.com/raycfu

Why OpenClaw Burns Through Tokens So Fast

OpenClaw isn't like using ChatGPT or Claude in the browser. Those products charge you a flat monthly fee. OpenClaw charges per token through the API, and everything it does costs tokens. The more powerful your setup, the more tokens it eats. There are six reasons this spirals fast.

1. Context Accumulation (40-50% of your bill)

This is the biggest cost driver and almost nobody catches it until they see the bill.

Every time you chat with OpenClaw, the entire conversation history gets saved in JSONL files inside your .openclaw/agents.main/sessions/ directory. Here's the problem: with every new request, OpenClaw sends the entire conversation history to the AI model. Not just your latest message. Everything.

One user reported their main session context was already eating up 56-58% of a 400K token window. So even for a simple question like "what time is it," OpenClaw was processing over 200,000 tokens of cached context before it could even start answering. Every interaction was hitting hundreds of thousands of tokens in cacheRead alone.

The longer your session runs, the worse it gets. It grows exponentially.

You can check your current session size anytime:

openclaw /status

If you see context usage above 50%, you're bleeding money on every message.

2. Tool Output Storage (20-30% of your bill)

OpenClaw stores every tool call output into the session records. So if you ask it to check your project structure and it traverses your whole directory, tens of thousands of lines of file listings get saved into the session history. From that point on, every message you send also includes all of that useless directory output being re-sent to the model.

The worst offenders are commands like config.schema (dumps massive JSON), status --all (full system status), directory traversal with find (entire file trees), and log exports (complete logs dumped into records). One developer asked OpenClaw to check a project structure and watched it spit out tens of thousands of lines of file lists, all saved to the session history and re-sent with every message after that.

3. System Prompt Overhead (10-15% of your bill)

OpenClaw uses a complex system prompt that includes your persona settings, tools list, security rules, and user preferences. This prompt typically runs 5,000 to 10,000 tokens and gets re-sent with every API call.

Anthropic offers prompt caching that charges only 10% for cache hits, but the cache has a time-to-live limit. Anthropic's cache expires after 5 minutes. OpenAI's expires after 1 hour. If you're not using OpenClaw continuously, every "cold start" after a gap bills you at full price for the entire system prompt.

4. Multi-Round Reasoning (10-15% of your bill)

OpenClaw is great at completing complex tasks on its own. But each step in a complex task is a separate API call, and each call carries the full context.

Something as simple as "organize today's emails and create to-do items" triggers 5-10 separate API calls. It calls the email skill to get the list, analyzes each email, figures out priority, calls your task manager to create items, and generates a summary. Each of those calls ships the full session context along with it.

5. Wrong Model for the Job (5-10% of your bill, but easy to fix)

A lot of people default to Claude Opus 4.5 or Sonnet 4.5 for everything. The price gap between models is wild:

  • Claude Opus 4.5: $15 per million input tokens, $75 per million output tokens
  • Claude Sonnet 4.5: $3 per million input tokens, $15 per million output tokens
  • Claude Haiku 4.5: $1 per million input tokens, $5 per million output tokens
  • Gemini 2.5 Flash: $0.15 per million input tokens, $0.60 per million output tokens

That's up to a 100x price difference. Using Opus to check the weather is just throwing money away.

6. Heartbeat and Background Tasks (5-10% of your bill)

OpenClaw's heartbeat feature lets the AI wake up on its own and run scheduled tasks. What most people don't realize is that every heartbeat trigger is a full API call, each trigger carries the full session context, and if you misconfigure it, it can fire every few minutes.

One user set up email checking every 5 minutes. By the end of the day, the heartbeat alone had eaten through $50 in API costs. They didn't even send a single message themselves.

How to Cut Your Bill by 60-80%

Now that you know where the money goes, here's how to stop the bleeding. These are ordered by impact. Start at the top.

Strategy 1: Reset Sessions Regularly (Saves 40-60%)

This is the highest-impact change you can make, and it takes 10 seconds.

When your session context bloats, reset it. Don't let conversations run forever. After you finish a task, start fresh.

Three ways to do it:

Method 1: Reset within the chat

openclaw "reset session"

Method 2: Delete session files directly

rm -rf ~/.openclaw/agents.main/sessions/*.jsonl

Method 3: Use the compact command to compress

openclaw /compact

Simple rule: one task, one session. Finish the task, reset, start fresh. This alone can cut your bill in half.

Strategy 2: Isolate Large Output Operations (Saves 20-30%)

Never run commands that produce large outputs in your main session. If you need to check system config, traverse a directory, or dump logs, do it in a separate debug session so the output doesn't pollute your main context.

Wrong (runs in main session, output stays forever):

openclaw "show full system config"

Right (isolated session, output stays contained):

openclaw --session debug "show full system config"

Then just copy the small piece you actually need back into your main session. Keeps your main context lean.

Strategy 3: Smart Model Routing (Saves 50-80%)

This is the second biggest win. Stop using your most expensive model for everything.

Configure your openclaw.json to route tasks to the right model:

{

"agents": {

"defaults": {

"model": {

"primary": "anthropic/claude-sonnet-4",

"fallback": "anthropic/claude-haiku-4"

}

}

}

}

Think of it this way. Use Haiku or Gemini Flash for daily tasks, simple questions, format conversions, and quick lookups. Use Sonnet for normal work, code generation, and moderate reasoning. Only pull out Opus for complex reasoning, creative work, and critical decisions.

If you're running everything on Opus right now and switch 80% of your calls to Haiku, you'll cut costs by 90% on those calls with barely any quality difference for simple tasks.

Strategy 4: Optimize Cache Hit Rates (Saves 30-50%)

Anthropic's prompt caching charges only 10% for cache hits versus full price for cache misses. The trick is keeping the cache warm.

{

"agents": {

"defaults": {

"cache-ttl": 3600,

"temperature": 0.2

}

}

}

Two tips here. Set a low temperature (0.2) because it improves cache hit rates. And configure your heartbeat interval to be slightly less than the cache TTL. This keeps the cache "warm" so you never pay full price for a cold start on the system prompt.

Strategy 5: Limit the Context Window (Saves 20-40%)

By default, OpenClaw uses the full 400K context window. You almost certainly don't need this. Dropping it to 50K-100K cuts the cost per request significantly.

{

"agents": {

"defaults": {

"contextTokens": 50000,

"compaction": "aggressive"

}

}

}

A smaller context window means less data re-sent with every message, which means lower cost on every interaction. Aggressive compaction tells OpenClaw to summarize older context instead of carrying it at full fidelity.

One thing to watch out for though. This is exactly what caused the Summer Yue inbox deletion incident. During compaction, her safety instruction got summarized away and the bot lost the rule entirely. If you use aggressive compaction, put your critical safety rules in a MEMORY.md file (which survives compaction) instead of in chat messages (which don't).

Strategy 6: Run Local Models for Simple Tasks (Saves 60-80%)

Set up Ollama to handle simple tasks locally with zero API cost:

{

"models": {

"providers": {

"ollama": {

"baseUrl": "http://localhost:11434",

"models": ["llama3.3", "qwen2.5"]

}

}

},

"routing": {

"simple_queries": "ollama/llama3.3"

}

}

Local models cost nothing per token. They work great for simple format conversions, quick lookups, basic Q&A, and anything that doesn't need a frontier model. The tradeoff is quality. Local models aren't as sharp as Claude or GPT-4 for complex reasoning. But for the 40-60% of tasks that are straightforward, they're free.

Strategy 7: Control Your Heartbeat and Cron Jobs

Go through every automated task and ask whether the frequency actually makes sense.

Email checking every 5 minutes is almost never necessary. Every 30-60 minutes works fine for most people. Twitter reply checking every 10 minutes might be reasonable if you're running an active account, but every 2 minutes is just burning cash.

Here's the math. Every heartbeat trigger is a full API call with full context. If your context is 200K tokens and you're triggering every 5 minutes, that's 57.6 million tokens per day just on heartbeats. At Sonnet pricing, that's roughly $170/day doing absolutely nothing.

Increase your intervals, use cheaper models for heartbeat checks, and make sure your heartbeat runs in a clean session with minimal context.

Strategy 8: Monitor Your Spend in Real Time

Don't wait for the bill. Track your usage as you go.

Check current session status:

openclaw /status

Enable per-response usage display:

openclaw /usage full

Check cost summary:

openclaw /usage cost

Set billing alerts on your API provider dashboard. Anthropic, OpenAI, and Google all let you set spending limits and alerts. But here's the thing: set a hard cap that actually kills the service when you hit a threshold, not just an alert. Alerts alone aren't enough. The $82K Gemini API theft victim had alerts configured, but they fired after the damage was already done.

Strategy 9: Use API Relay Services

Services like OpenRouter aggregate multiple model providers behind a single API. You get built-in caching that can improve hit rates, the ability to switch between providers without reconfiguring OpenClaw, unified billing across models, and sometimes lower pricing through caching optimizations.

Configure OpenRouter as your provider:

{

"models": {

"providers": {

"openrouter": {

"type": "openai",

"baseUrl": "https://openrouter.ai/api/v1",

"apiKey": "YOUR_OPENROUTER_KEY"

}

}

}

}

Strategy 10: Secure Your API Keys (Saves You From Catastrophe)

This isn't about optimization. It's about not going bankrupt. A stolen API key can cost you tens of thousands of dollars overnight.

Never store API keys in plain text config files. Use environment variables:

export ANTHROPIC_API_KEY="sk-..."

export OPENAI_API_KEY="sk-..."

Even better, use OpenClaw's built-in SecretRef system or macOS Keychain integration so keys never touch the filesystem.

Set hard billing caps on every API provider. Not alerts. Hard caps that actually stop the service.

Run OpenClaw in Docker with restricted network access so if something goes wrong, the damage stays contained.

Rotate your API keys regularly, and immediately if you think anything might be compromised.

Real-World Cost Comparison

Here's what full optimization looks like in practice, based on reported user data:

  • Session management: $50/month down to $20/month (60% savings)
  • Model switching: $80/month down to $25/month (69% savings)
  • Cache optimization: $40/month down to $20/month (50% savings)
  • Local model fallback: $30/month down to $5/month (83% savings)
  • Total: $150/month down to $35/month (77% savings)

One power user went from $150/month to $35/month by stacking all of these together.

The Quick-Start Checklist

If you do nothing else, do these five things today:

  1. Run openclaw /status and check your context usage percentage. If it's above 50%, reset your session right now.
  2. Switch your default model from Opus to Sonnet or Haiku. You can always bump up to Opus for specific complex tasks.
  3. Set contextTokens to 50000 and compaction to aggressive in your config.
  4. Set hard billing caps on your API provider dashboard. Not alerts. Hard caps.
  5. Put your critical safety rules in MEMORY.md, not in chat messages that can get compacted away.

These five changes take less than 10 minutes and should cut your bill by at least 50%.

What a Well-Optimized Setup Actually Costs

For reference, most well-configured OpenClaw setups running daily automations, cron jobs, and multi-tool integrations land between $30-80/month in API costs after optimization. If you're spending more than $100/month for personal use, something is almost certainly misconfigured. Revisit your session management, model routing, and heartbeat intervals before spending another dollar.

You just read the full playbook. Most people will close this tab and never implement it. The ones who do usually hit a wall around the technical setup and quit.

Inside the Skool, I walk you through the exact build step-by-step, troubleshoot your setup live in the community, and share the scripts and templates I use to actually land paying clients.

If you want the shortcut instead of the long way around:

Join the Skool →