Troubleshooting High Api Costs

Reducing API Costs

LLM API calls can get expensive quickly, especially with autonomous agents that make many requests. Here are proven strategies to control costs without sacrificing agent capability.

Cost Monitoring

# View current month's API spending
openclaw costs summary

# Set a daily spending limit
openclaw config set costs.dailyLimit 5.00

# Enable cost alerts
openclaw config set costs.alertThreshold 3.00

Cost Reduction Strategies

1. Use the Right Model for the Task

Not every task needs GPT-4 or Claude Opus. Configure model routing to use cheaper models for simple tasks:

{
  "modelRouting": {
    "simple": "gpt-4o-mini",
    "complex": "gpt-4o",
    "coding": "claude-sonnet"
  }
}

2. Enable Response Caching

Cache responses for repeated queries to avoid redundant API calls:

{
  "caching": {
    "enabled": true,
    "ttlMinutes": 60,
    "maxEntries": 1000
  }
}

3. Limit Context Window

Reduce token usage by trimming conversation history and limiting context sent to the model:

4. Use Local Models

For tasks that do not require frontier model capability, run a local model via Ollama or LM Studio to eliminate API costs entirely.

ClawScan
Automatically detect and fix issues with your OpenClaw setup.
Explore ClawScan →