OpenClaw model costs

How to reduce AI token usage with OpenClaw

To reduce AI token usage with OpenClaw, run /context detail on a repeatable task and find the largest input you can shorten. Prune stale tool results if they fill the prompt, or use /compact if earlier messages take up most of the space. Use /usage tokens before and after the change to compare input, output and cache counts on the same model.

Last updated · Published

By CWYN · Checked against docs, not run · OpenClaw token use and context reports (as of )

1. Measure one task

Pick a task you can repeat on the same model. Record these readings before you change its prompt or settings.

  • /usage tokens adds a per-reply footer with the turn's token and cache details. Record the input, output and any cache reads or writes across the task.
  • /status shows the session model, context usage, last response's input and output tokens, and cost when available.
  • /context detail breaks down workspace instructions, tool schemas, skill metadata and transcript history. Use it to find the largest contributor.
  • /context map shows those contributors as a treemap. Send a normal message first so there is a cached run report to display.

/usage cost gives a local summary from session logs. If the amount differs from your invoice, reconcile OpenClaw usage with your provider bill for the same account, model and period. Usage commands and context reports (as of ).

Estimate your own monthly bill with the free AI cost calculator.

2. Reduce what each turn carries

Workspace files. OpenClaw rebuilds its system prompt on each run. Check /context list for raw size, injected size and truncation marks before editing. Keep the instructions you need every turn in AGENTS.md. The default limits are 20,000 characters per file (agents.defaults.bootstrapMaxChars) and 60,000 characters in total (agents.defaults.bootstrapTotalMaxChars). Start with a file whose injected portion is large. Check where AGENTS.md was cut off. Bootstrap limits and context inspection (as of ).

Skills and tools. The prompt includes the skill list. Keep each description to one line under 160 characters and put the procedure in the skill instructions, which load on demand. Ask tools for the matching rows or log lines instead of a full dump. For screenshot-heavy sessions, lower agents.defaults.imageMaxDimensionPx and check that you can still read the detail needed for the task. Writing skill descriptions and OpenClaw token use (as of ).

Model choice. Try a cheaper model for verbose exploratory work or background tasks. Compare the cost per usable result, including retries. Compare model prices, then set the default model. For other calls, check the fallback order, subagent model and scheduled jobs. OpenClaw cost guidance (as of ).

3. Cache the part that repeats

OpenClaw's cost-first baseline pairs cacheRetention: "short" with contextPruning.mode: "cache-ttl". On a direct Anthropic route, short retention uses the five-minute prompt cache. Put durable instructions, tool definitions and policy first so the beginning of the prompt stays the same as the conversation changes. Pick the model and thinking level at the start of the session. A model switch starts a new cache, and changing the thinking level can also break reuse. Prompt caching and retention (as of ).

If you use cacheRetention: "long" for Anthropic's one-hour cache, a useful automation running every 55m in the same persistent session can keep that history warm. An isolated job cannot warm another conversation. Count every extra turn and cache write over the same period. Keep the cadence only if the total cost falls. Persistent-session timing and cache lifetimes (as of ).

When upgrading a Gateway with legacy heartbeat settings, run openclaw doctor --fix before starting the upgraded Gateway. Edit or disable the migrated job in Automations. Migrate a heartbeat or diagnose missing cache reads. OpenClaw heartbeat migration (as of ).

4. Prune tool output or compact history

Prune when old tool results dominate. OpenClaw disables context pruning by default. Enable it to trim stale tool results from the next model request while retaining the full transcript on disk. This example lets a client-side route consider pruning on the next request after an idle hour. The provider cache lifetime is a separate setting.

agents:
  defaults:
    contextPruning:
      mode: "cache-ttl"
      ttl: "1h"

The built-in pruning TTL is five minutes, and the bundled Anthropic plugin seeds one hour. On client-side routes, pruning waits for expiry and skips a pass below roughly 30% context use. Soft trimming keeps the beginning and end of a large result. Under heavier pressure, hard clearing can replace it with a placeholder. Image blocks stay intact. Direct Anthropic API-key calls using anthropic-messages at the standard endpoint use server-side clearing with token thresholds independent of this timer. Context pruning settings and pruning by provider route (as of ).

Compact when the conversation itself dominates. Run /compact to write a persistent summary of older messages. By default, agents.defaults.compaction.keepRecentTokens keeps the most recent 20,000 tokens intact. Include the summarizing call when you compare costs. Check the cost of the compaction model. OpenClaw compaction (as of ).

What do cache reads save on the same workload?

Use the calculator's opening workload and the monthly worksheet's model, Claude Sonnet 4.6, on a direct Anthropic API key. These token counts are assumptions. The per-turn figures are averages across a session. 10 turns × (500 system + 400 history + 100 user) = 10,000 input tokens per session. 10 × 100 output = 1,000 output tokens per session. At 4 sessions a day × 30 days, both cases cover 120 sessions.

The uncached case bills all input at the regular rate. For the cached case, the calculator assumes follow-ups arrive within five minutes and each turn adds the same amount of new context. Once the prefix reaches the model's cache minimum, new cacheable input is billed as a five-minute write and eligible repeated input as a read. Each input token appears in exactly one billing category. Rates are USD per million tokens. Anthropic pricing for Claude Sonnet 4.6 (as of ).

Without caching

  • Regular input. 1,200,000 tokens × $3 ÷ 1M ≈ $3.60
  • Output. 120,000 tokens × $15 ÷ 1M ≈ $1.80

30-day token cost $5.40.

With cache reads and writes

  • Regular input. 327,273 tokens × $3 ÷ 1M ≈ $0.98
  • Cache reads. 654,545 tokens × $0.3 ÷ 1M ≈ $0.20
  • Cache writes (5m). 218,182 tokens × $3.75 ÷ 1M ≈ $0.82
  • Output. 120,000 tokens × $15 ÷ 1M ≈ $1.80

30-day token cost $3.80.

The difference is $1.60 over 30 days. Displayed counts round to whole tokens and totals use unrounded charges. Include the cost of any extra automation turns when you compare your own bills.

For your own comparison, repeat the task after changing one setting. The weekly worksheet in the OpenClaw Token Bill Kit gives you a place to record what each run cost and where the figures came from.

To include hosting and other charges alongside model usage, use the OpenClaw monthly cost worksheet.

What changes the number?

  • Caching. Check how much input was read, written or billed at the regular rate after an idle gap.
  • Tool-result size. Count how many subsequent turns carry a large search result or log.
  • Bootstrap size. Compare the injected sizes before and after shortening workspace files.
  • Compaction. Count the summary call alongside the smaller requests that follow it.
  • Cron or automation cadence. Add every scheduled model turn over the period you compare.
  • Model choice. Match each call, including background work, to the rates of the model that handled it.

OpenClaw token accounting and compaction behavior (as of ).

OpenClaw token usage FAQ

Which memory files add to the prompt?

OpenClaw can inject the root MEMORY.md when present. Lowercase memory.md is legacy repair input and is never injected. Daily files in memory/*.md load on demand through memory tools. Workspace memory and token use (as of ).

How much of one tool result can reach the model?

The live cap is 16,000 characters for context windows below 100,000 tokens, 32,000 at 100,000 or more, and 64,000 at 200,000 or more. A single result is also capped at 30% of the context window. Returning only the lines you need keeps the next prompt smaller even below those caps. Tool-result limits (as of ).

Why does /usage full show tokens without a cost?

OpenClaw estimates cost from the model's configured USD rates per million tokens for input, output, cache reads and cache writes. If both pricing and a recorded amount are missing, the footer omits the cost. Use the provider's usage record to fill the gap. Usage cost estimates (as of ).

Next steps

Price your own token usage

Use the free AI cost calculator

Choose OpenClaw, API key and your model. Enter your session counts, input and output, then compare your cache reads and writes with an uncached run.

Track the next bill

The OpenClaw Token Bill Kit ($24.95) is an optional paid kit with a weekly bill review worksheet and routing and cache settings.