troubleshooting openclaw costs tokens optimization api-usage

Why OpenClaw Is Burning Through Your API Tokens (And How to Fix It)

OpenClaw costing more than expected? Context dragging, cron burns, and no compaction are likely the cause. Here's how to cut your API spend.

Why OpenClaw Is Burning Through Your API Tokens (And How to Fix It)

TL;DR: Your context window is probably getting dragged across every message, multiplying your token costs. Reset sessions, enable compaction, and audit your cron jobs.

The Problem

There's no error message for this one — just a surprisingly large bill from Anthropic, OpenAI, or whoever you're using. You set up OpenClaw, used it for a week, and somehow burned through $50+ in API tokens for what felt like casual chatting.

$ anthropic usage
Current month: $47.23
Average daily: $6.75

That's way more than you expected. And it's going to keep climbing.

(GitHub #1594)

Why This Happens

How context windows actually work (the short version)

Every time you send a message to Claude or GPT, the API doesn't just see your latest message. It sees the entire conversation history — every message you've sent, every response, every tool call, every file content. All of it gets sent as one big payload.

Here's the kicker: you're billed for the full context on every single message.

So if your conversation is 50,000 tokens long and you send "ok thanks", you're paying for 50,000 + 2 tokens of input. The "ok thanks" costs almost nothing — the 50,000 tokens of history costs you ~$0.15-0.75 depending on the model.

Now imagine that happening 50 times a day across a session that never resets.

The three cost killers

1. Context dragging

OpenClaw maintains persistent sessions. That's a feature — it means your AI remembers your earlier conversations. But it also means the context window grows with every message. After a day of chatting, you might have a 100K+ token context that gets sent with every new message.

2. Cron job burns

If you've set up cron jobs or heartbeat checks (like periodic email checks, calendar reminders, etc.), each one triggers a full API call with the current session context. A heartbeat running every 30 minutes with a 50K token context = ~$10-15/day just on heartbeats.

3. No compaction

Without compaction, old messages stay in the context forever. A conversation about last Tuesday's dinner is still being sent to the API when you ask about today's weather.

How to Fix It

Fix 1: Reset your session regularly

The simplest cost reduction. Start a fresh session to clear the context:

openclaw session reset

Or set up automatic session resets:

{
  "session": {
    "maxTokens": 80000,
    "autoReset": true,
    "resetThreshold": 100000
  }
}

This automatically resets the session when it hits 100K tokens, preventing runaway context growth.

Fix 2: Enable context compaction

Compaction summarizes older messages so you keep the important context without paying to re-send every word:

{
  "session": {
    "compaction": {
      "enabled": true,
      "threshold": 60000,
      "targetTokens": 20000
    }
  }
}

When the context hits 60K tokens, OpenClaw will compress it down to ~20K tokens by summarizing older exchanges. You keep the context, but pay for much less.

Fix 3: Audit your cron jobs

List what's running:

openclaw cron list

For each cron job, ask yourself:

  • Does this need to run this often?
  • Does this need the full conversation context?
  • Could this run with a separate, smaller session?

Reduce frequency:

{
  "heartbeat": {
    "intervalMinutes": 120
  }
}

Switching from 30-minute to 2-hour heartbeats cuts that cost by 75%.

Use isolated sessions for cron:

{
  "cron": {
    "jobs": {
      "email-check": {
        "schedule": "0 */4 * * *",
        "isolatedSession": true
      }
    }
  }
}

Isolated sessions don't carry your main conversation context, so each cron run is cheap.

Fix 4: Use a cheaper model for background tasks

Not everything needs Claude Opus or GPT-4. Route background tasks to cheaper models:

{
  "cron": {
    "defaultModel": "claude-haiku-3-20250506"
  }
}

Haiku is ~10-20x cheaper than Opus for simple tasks like checking email or running health checks.

Fix 5: Monitor your usage

Add a cost tracking reminder so you're not surprised:

# Check Anthropic usage
curl -s https://api.anthropic.com/v1/usage \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01"

Or set up billing alerts on your provider's dashboard:

Quick cost comparison

Scenario Monthly Cost (est.)
Casual use, regular resets $5-15
Heavy use, no compaction $30-80
Heavy use + 30min heartbeats $50-150+
Heavy use + compaction + optimized cron $10-25

How to Prevent It

  • Enable compaction from day one. There's no downside — your AI still has context, it just costs less.
  • Start with long heartbeat intervals (2-4 hours) and only increase frequency if you actually need it.
  • Check your bill weekly for the first month. Token costs are unintuitive until you've calibrated.
  • Use Haiku/smaller models for anything that doesn't need top-tier reasoning.

The Easy Way

lobsterfarm is a managed hosting service for OpenClaw — deployment, updates, and support handled for you.

Get started with lobsterfarm →

Skip the setup. Start using your AI assistant today.

lobsterfarm gives you a fully managed OpenClaw instance — one click, your own server, running 24/7.