openclaw - 💡(How to fix) Fix cost.cacheWrite field wrong by ~5 orders of magnitude for claude-opus-4-7 (missing price table entry) [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70416Fetched 2026-04-23 07:25:04
View on GitHub
Comments
1
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
cross-referenced ×2commented ×1

On claude-opus-4-7 responses, openclaw's computed usage.cost.cacheWrite (and related per-category cost fields) appear to be using an incorrect or uninitialized price multiplier. Observed values are around $1.9×10⁻⁵ per million tokens, which is ~5 orders of magnitude below any real Anthropic price tier.

Downstream effects: openclaw usage-cost and per-session cost estimates are unusable; session logs' cost.total field is effectively zero for any Opus 4.7 activity.

Root Cause

Root cause (hypothesis)

Fix Action

Fix

Add the correct per-token rates for claude-opus-4-7 to the pricing table:

  • Input: (current Opus 4.7 input rate per million tokens, consult Anthropic's published pricing)
  • Output: (current Opus 4.7 output rate)
  • Cache read: 0.1× input
  • Cache creation 5m: 1.25× input
  • Cache creation 1h: 2× input

Also recommend adding a defensive fallback: when computing cost for a model id not in the price table, log a warning rather than silently returning near-zero values. This makes future model additions more obvious when they're missed.

Code Example

{
  "usage": {
    "input": 6,
    "output": 15,
    "cacheRead": 45612,
    "cacheWrite": 285595,
    "totalTokens": 331228,
    "cost": {
      "input": 9E-11,
      "output": 1.125E-9,
      "cacheRead": 6.8418E-8,
      "cacheWrite": 0.00000535490625,
      "total": 0.000005424539249999999
    }
  }
}
RAW_BUFFERClick to expand / collapse

usage.cost field is wrong by ~5 orders of magnitude for claude-opus-4-7

Summary

On claude-opus-4-7 responses, openclaw's computed usage.cost.cacheWrite (and related per-category cost fields) appear to be using an incorrect or uninitialized price multiplier. Observed values are around $1.9×10⁻⁵ per million tokens, which is ~5 orders of magnitude below any real Anthropic price tier.

Downstream effects: openclaw usage-cost and per-session cost estimates are unusable; session logs' cost.total field is effectively zero for any Opus 4.7 activity.

Evidence

Single captured assistant turn on Opus 4.7:

{
  "usage": {
    "input": 6,
    "output": 15,
    "cacheRead": 45612,
    "cacheWrite": 285595,
    "totalTokens": 331228,
    "cost": {
      "input": 9E-11,
      "output": 1.125E-9,
      "cacheRead": 6.8418E-8,
      "cacheWrite": 0.00000535490625,
      "total": 0.000005424539249999999
    }
  }
}

Math check:

  • cacheWrite: 285,595 tokens, reported cost $0.00000535490625 → implies $1.875×10⁻⁵/M.
  • Expected at cacheRetention: "long" (1h TTL, 2× input price): for a $5/M input model that's $10/M. For a $15/M input model that's $30/M.
  • Either way, the reported value is off by ~5 orders of magnitude.

Same session shows correct cost calculations for earlier turns on claude-opus-4-6:

  • cacheWrite: 25716 tokens, cost $0.160725$6.25/M (1.25× input at $5/M → correct for 5m TTL).

So the pricing table has Opus 4.6 entries but not Opus 4.7 entries, and Opus 4.7 is falling through to a default / zero-initialized entry that gives near-zero costs.

Root cause (hypothesis)

openclaw maintains a per-model pricing table used to convert usage token counts → cost estimates for session logs and CLI reports. The claude-opus-4-7 entry is either missing, or present with zero/near-zero values.

This doesn't affect Anthropic's actual billing — Anthropic charges based on their own rates regardless of what openclaw computes. It only affects openclaw's internal cost reporting.

Fix

Add the correct per-token rates for claude-opus-4-7 to the pricing table:

  • Input: (current Opus 4.7 input rate per million tokens, consult Anthropic's published pricing)
  • Output: (current Opus 4.7 output rate)
  • Cache read: 0.1× input
  • Cache creation 5m: 1.25× input
  • Cache creation 1h: 2× input

Also recommend adding a defensive fallback: when computing cost for a model id not in the price table, log a warning rather than silently returning near-zero values. This makes future model additions more obvious when they're missed.

Environment

  • openclaw 2026.4.20-beta.2
  • Claude Opus 4.7 (claude-opus-4-7)
  • Authentication: Anthropic API key (not subscription)

Scope

Trivial fix — adding price-table entries and the fallback warning should be under 20 LOC. Happy to submit the PR once Anthropic's current Opus 4.7 pricing is confirmed (I don't want to guess numbers from the outside and introduce another wrong entry).


Spotted while investigating cache cost behavior, with diagnostic assistance from Claude.

extent analysis

TL;DR

Add the correct per-token rates for claude-opus-4-7 to the pricing table and implement a defensive fallback to log warnings for missing model IDs.

Guidance

  • Verify the current Opus 4.7 pricing from Anthropic's published rates to ensure accuracy.
  • Update the pricing table with the correct input, output, cache read, and cache creation rates for claude-opus-4-7.
  • Implement a defensive fallback to log warnings when computing cost for a model ID not in the price table.
  • Test the changes with a sample session to ensure correct cost calculations.

Example

{
  "pricingTable": {
    "claude-opus-4-7": {
      "input": 5, // current Opus 4.7 input rate per million tokens
      "output": 10, // current Opus 4.7 output rate
      "cacheRead": 0.5, // 0.1× input
      "cacheCreation5m": 6.25, // 1.25× input
      "cacheCreation1h": 10 // 2× input
    }
  }
}

Notes

The fix is specific to the claude-opus-4-7 model and does not affect other models or Anthropic's actual billing. The defensive fallback will help prevent similar issues in the future.

Recommendation

Apply the workaround by adding the correct pricing table entries and implementing the defensive fallback. This will ensure accurate cost reporting for claude-opus-4-7 and prevent silent errors for future model additions.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix cost.cacheWrite field wrong by ~5 orders of magnitude for claude-opus-4-7 (missing price table entry) [1 comments, 1 participants]