OpenClaw Manual OpenClaw
Optimization 10 min read

OpenClaw Model Selection and Cost Optimization Guide

Compare AI models for OpenClaw, understand pricing, and learn strategies to optimize costs while maintaining quality responses.

O

OpenClaw Manuals

Tutorial Authors

Understanding AI Model Pricing

AI models charge based on tokens - chunks of text that are roughly 4 characters or 0.75 words. You pay for both:

  • Input tokens : The text you send (your message + conversation history)
  • Output tokens : The text the model generates (responses)

Available Models in OpenClaw

OpenClaw primarily supports Anthropic's Claude models, with optional support for other providers.

Claude Models (Anthropic)

| Model | Input Price | Output Price | Best For | |-------|-------------|--------------|----------| | Claude 3.5 Haiku | $0.25/1M | $1.25/1M | Quick tasks, high volume | | Claude 3.5 Sonnet | $3.00/1M | $15.00/1M | Balanced performance | | Claude Sonnet 4 | $3.00/1M | $15.00/1M | Complex reasoning | | Claude Opus 4 | $15.00/1M | $75.00/1M | Most capable, research |

Prices as of early 2026. Check Anthropic's pricing page for current rates.

Cost Comparison Example

For a typical conversation with 1,000 input tokens and 500 output tokens:

| Model | Input Cost | Output Cost | Total | |-------|------------|-------------|-------| | Claude 3.5 Haiku | $0.00025 | $0.000625 | $0.000875 | | Claude 3.5 Sonnet | $0.003 | $0.0075 | $0.0105 | | Claude Opus 4 | $0.015 | $0.0375 | $0.0525 |

Haiku is 12x cheaper than Sonnet and 60x cheaper than Opus!

Choosing the Right Model

Use Claude 3.5 Haiku When:

  • Responding to simple questions
  • Quick lookups and facts
  • High-volume messaging (WhatsApp, Telegram)
  • Cost is a primary concern
  • Speed matters more than depth
json
// ~/.openclaw/openclaw.json
{
  "model": {
    "default": "claude-3-5-haiku"
  }
}

Use Claude 3.5 Sonnet / Sonnet 4 When:

  • Writing assistance needed
  • Code generation or review
  • Moderate complexity tasks
  • Balance of quality and cost
  • Most everyday use cases
json
// ~/.openclaw/openclaw.json
{
  "model": {
    "default": "claude-sonnet-4"
  }
}

Use Claude Opus 4 When:

  • Complex analysis required
  • Research and deep reasoning
  • Critical business decisions
  • Quality is paramount
  • Cost is not a concern
json
// ~/.openclaw/openclaw.json
{
  "model": {
    "default": "claude-opus-4"
  }
}

Dynamic Model Routing

OpenClaw can automatically select models based on the task:

json
// ~/.openclaw/openclaw.json
{
  "model": {
    "routing": {
      "enabled": true,
      "rules": [
        {
          "pattern": "^(hi|hello|hey|thanks|ok|bye)",
          "model": "claude-3-5-haiku"
        },
        {
          "pattern": "(code|function|bug|error|programming)",
          "model": "claude-sonnet-4"
        },
        {
          "pattern": "(analyze deeply|complex|thorough)",
          "model": "claude-opus-4"
        },
        {
          "pattern": ".*",
          "model": "claude-3-5-sonnet"
        }
      ]
    }
  }
}

Cost Optimization Strategies

1. Reduce Context Length

Conversation history adds up fast. Limit how much is sent:

json
// ~/.openclaw/openclaw.json
{
  "model": {
    "context": {
      "maxMessages": 10,
      "maxContextTokens": 4000,
      "summarizeOldMessages": true,
      "summaryThreshold": 20
    }
  }
}

2. Enable Response Caching

Cache identical queries to avoid repeat API calls:

json
// ~/.openclaw/openclaw.json
{
  "gateway": {
    "caching": {
      "enabled": true,
      "ttl": 3600,
      "maxSize": 1000
    }
  }
}

3. Set Token Limits

Prevent unexpectedly long (expensive) responses:

json
// ~/.openclaw/openclaw.json
{
  "model": {
    "maxOutputTokens": 1024,
    "channelLimits": {
      "whatsapp": 500,
      "discord": 1500,
      "telegram": 800
    }
  }
}

4. Implement Usage Quotas

Set daily/monthly spending limits:

json
// ~/.openclaw/openclaw.json
{
  "model": {
    "quotas": {
      "daily": {
        "enabled": true,
        "maxTokens": 100000,
        "maxCost": 1.00,
        "warningThreshold": 0.80
      },
      "monthly": {
        "enabled": true,
        "maxCost": 20.00
      }
    }
  }
}

5. Use Prompt Compression

Reduce input tokens with smarter prompts:

json
// ~/.openclaw/openclaw.json
{
  "model": {
    "optimization": {
      "compressPrompts": true,
      "compactSystemPrompt": true,
      "deltaContext": true
    }
  }
}

Monitoring Costs

Real-Time Usage

bash
# View current usage
openclaw stats

# Output:
# Today's Usage:
#   Input tokens:  45,230
#   Output tokens: 12,450
#   Estimated cost: $0.23
#
# This month:
#   Total tokens: 1,234,567
#   Estimated cost: $8.45

Detailed Reports

bash
# Generate cost report
openclaw stats --report monthly

# Export to CSV
openclaw stats --export costs.csv --period 30d

Set Up Alerts

json
// ~/.openclaw/openclaw.json
{
  "notifications": {
    "costAlerts": {
      "enabled": true,
      "thresholds": [
        { "amount": 5.00, "action": "notify" },
        { "amount": 10.00, "action": "warn" },
        { "amount": 20.00, "action": "pause" }
      ]
    }
  }
}

Cost-Saving Configuration Templates

Budget-Conscious Setup

json
// Optimized for minimal cost
{
  "model": {
    "default": "claude-3-5-haiku",
    "maxOutputTokens": 512,
    "context": {
      "maxMessages": 5,
      "maxContextTokens": 2000
    },
    "quotas": {
      "daily": {
        "enabled": true,
        "maxCost": 0.50
      }
    }
  },
  "gateway": {
    "caching": {
      "enabled": true,
      "ttl": 7200
    }
  }
}

Estimated cost: ~$5-10/month with moderate use

Balanced Setup

json
// Good balance of quality and cost
{
  "model": {
    "default": "claude-3-5-sonnet",
    "maxOutputTokens": 1024,
    "context": {
      "maxMessages": 15,
      "maxContextTokens": 4000,
      "summarizeOldMessages": true
    },
    "routing": {
      "enabled": true,
      "rules": [
        { "pattern": "^(hi|hello|thanks|bye|ok)", "model": "claude-3-5-haiku" },
        { "pattern": ".*", "model": "claude-3-5-sonnet" }
      ]
    }
  },
  "gateway": {
    "caching": {
      "enabled": true,
      "ttl": 3600
    }
  }
}

Estimated cost: ~$15-30/month with moderate use

Quality-First Setup

json
// Maximum quality, cost secondary
{
  "model": {
    "default": "claude-sonnet-4",
    "maxOutputTokens": 4096,
    "context": {
      "maxMessages": 30,
      "maxContextTokens": 16000
    },
    "routing": {
      "enabled": true,
      "rules": [
        { "pattern": "(analyze|research|complex|detailed)", "model": "claude-opus-4" },
        { "pattern": ".*", "model": "claude-sonnet-4" }
      ]
    }
  }
}

Estimated cost: ~$50-100/month with moderate use

Multi-Provider Setup (Advanced)

Use multiple providers to optimize costs:

json
// ~/.openclaw/openclaw.json
{
  "providers": {
    "anthropic": {
      "apiKey": "${ANTHROPIC_API_KEY}",
      "models": ["claude-3-5-haiku", "claude-sonnet-4"]
    },
    "openai": {
      "apiKey": "${OPENAI_API_KEY}",
      "models": ["gpt-4o-mini"]
    }
  },
  "model": {
    "routing": {
      "enabled": true,
      "rules": [
        { "pattern": "^(hi|hello|what time)", "provider": "openai", "model": "gpt-4o-mini" },
        { "pattern": ".*", "provider": "anthropic", "model": "claude-3-5-sonnet" }
      ]
    }
  }
}

Tips for Reducing Costs

  1. Be specific in prompts - Vague prompts lead to longer responses
  2. Use system prompts wisely - Keep them concise
  3. Clear context periodically - Don't let history grow unbounded
  4. Cache common queries - FAQs, greetings, etc.
  5. Monitor usage weekly - Catch unexpected spikes early
  6. Use Haiku for testing - Switch to Sonnet for production

Calculating Your Expected Costs

Use this formula:

Monthly Cost = (Daily Messages × Avg Input Tokens × Input Price) +
               (Daily Messages × Avg Output Tokens × Output Price) × 30

Example for 50 messages/day with Claude 3.5 Sonnet:

  • Avg input: 800 tokens
  • Avg output: 400 tokens
Input:  50 × 800 × ($3/1M) × 30 = $3.60
Output: 50 × 400 × ($15/1M) × 30 = $9.00
Total: ~$12.60/month

Next Steps