Skip to content

fix(usage): Opus 4.5+ priced at pre-4.5 rates → ~3x cost overcount #155

@manzil-infinity180

Description

@manzil-infinity180

Summary

internal/usage/pricing.go has a single opus-4 rate entry at pre-4.5 prices and matches model IDs by case-insensitive substring. So claude-opus-4-5 / 4-6 / 4-7 / 4-8 all match opus-4 and get billed at the old rate — but Anthropic cut Opus prices sharply starting with Opus 4.5 (Nov 2025).

Evidence

  • aflock table: opus-4 = $15 in / $75 out / $1.50 cache-read / $18.75 cache-write per Mtok; matched by substring (~pricing.go:84).
  • Actual Opus 4.5+ rates: $5 / $25 / $0.50 / $6.25 per Mtok (Opus 4 / 4.1 / 3 stay at $15 / $75 / $1.50 / $18.75).
  • Cross-checked against Datadog lapdog's table (DataDog/dd-apm-test-agentddapm_test_agent/claude_cost_tracker.py), which sources from pi-ai models.generated.js — the same data Claude Code's own /usage uses.

Impact (real Opus 4.8 session)

tokens: 3.9k in · 3.5k out · 214.3k cache-read · 12.3k cache-write

  • aflock (old rates): ≈ $0.87
  • correct (4.5+ rates): ≈ $0.29 ← matches Claude Code /usage ($0.2908)

→ ~3× overcount. Under API key this feeds maxSpendUSD enforcement, so a session can be falsely aborted/denied well under its real budget.

Fix

  • Split the Opus family: legacy keys (opus-4, opus-4-1, opus-3) keep old rates; add opus-4-5 / 4-6 / 4-7 / 4-8 at $5 / $25 / $0.50 / $6.25.
  • Make matching prefer the longest/most-specific prefix, not the first substring hit, so opus-4-8 doesn't fall into opus-4.
  • (Optional) add Anthropic's >200K-token long-context premium tier — lapdog models this via volume-tiered _PriceTier bounds.

Independent of the broader accounting redesign — shippable on its own.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmediumMedium severity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions