# Save Money on Your OpenClaw Bot

You're using my API keys. Let's not burn through them. This guide cuts your costs 5x on tasks that don't need the expensive model.

## The Two Models

| Model | Alias | Cost | Use For |
|-------|-------|------|---------|
| Claude Opus 4 | `opus` | $15/$75 per 1M tokens | Direct chat, complex reasoning, coding |
| Claude Sonnet 4.5 | `sonnet` | $3/$15 per 1M tokens | Cron jobs, reminders, simple tasks |

Sonnet is **5x cheaper** and handles 90% of background tasks just fine.

## Step 1: Add Sonnet to Your Config

Patch your config to include both models:

```json
{
  "agents": {
    "defaults": {
      "models": {
        "anthropic/claude-sonnet-4-5": {
          "alias": "sonnet",
          "params": { "cacheRetention": "long" }
        },
        "anthropic/claude-opus-4-6": {
          "alias": "opus",
          "params": { "cacheRetention": "long" }
        }
      },
      "model": {
        "primary": "anthropic/claude-sonnet-4-5",
        "fallbacks": ["anthropic/claude-opus-4-6"]
      }
    }
  }
}
```

**Important:** The model ID format is `anthropic/claude-sonnet-4-5` (lowercase, hyphens). NOT `Claude Sonnet 4.5` (that will break your bot).

### How to Apply

**Option A: Config patch (if your bot supports it)**
Use `gateway(action="config.patch")` with the JSON above.

**Option B: Edit the file directly**
Find your config at `~/.openclaw/openclaw.json` (or `/data/.openclaw/openclaw.json` in Docker).

After editing, restart:
- Systemd: `systemctl --user restart openclaw-gateway`
- Docker: `docker restart <container-name>`
- Signal: `kill -USR1 <pid>` (hot reload)

## Step 2: Set Cron Jobs to Sonnet

Every cron job with `payload.kind: "agentTurn"` accepts a `model` field. Add it:

```json
{
  "payload": {
    "kind": "agentTurn",
    "message": "Your task here...",
    "model": "sonnet"
  }
}
```

### What Should Run on Sonnet

- Morning digests and summaries
- Reminders and alerts
- Git pushes and cleanup tasks
- Health checks and monitoring
- Data syncing and dashboard updates
- Simple web searches
- File operations and organization

### What Should Stay on Opus

- Direct conversation with you (keep as primary or switch per-session)
- Complex coding and debugging
- Multi-step reasoning tasks
- Anything where quality really matters

## Step 3: Enable Prompt Caching

The `cacheRetention: "long"` setting in Step 1 gives you 1-hour prompt caching. This means repeated system prompts (which are huge in OpenClaw) get cached instead of re-processed every turn.

| Setting | Cache Duration | Default |
|---------|---------------|---------|
| `"none"` | No caching | - |
| `"short"` | 5 minutes | Yes (API key auth) |
| `"long"` | 1 hour | No (must enable) |

With `"long"` caching, you'll see `cacheRead` in your token usage instead of `input`, at 90% discount.

## Step 4: Use Subagents on Sonnet

When spawning background tasks:

```
sessions_spawn(task="...", model="sonnet")
```

This runs the task on Sonnet in an isolated session. Great for research, summaries, and anything that doesn't need Opus-level reasoning.

## Quick Checklist

- [ ] Both models in `agents.defaults.models` with correct IDs
- [ ] `cacheRetention: "long"` on both models
- [ ] All cron jobs have `"model": "sonnet"` in their payload
- [ ] Primary model set to whichever you want for direct chat
- [ ] Fallback configured so if one model is down, the other picks up

## Model ID Reference

Always use these exact strings. Typos will break your bot.

```
anthropic/claude-opus-4-6      (alias: opus)
anthropic/claude-sonnet-4-5    (alias: sonnet)
```

Do NOT use: `Claude Sonnet 4.5`, `claude-sonnet-4`, `anthropic/claude-sonnet-4`, or any other variation.

---

Questions? Message mattlor.
