Skip to content

fix(pricing): price fast-mode and dot-notation Anthropic model ids - #1593

Merged
Xinwei He (XinweiHe) merged 2 commits into
mainfrom
fix/anthropic-fast-mode-pricing
Jul 22, 2026
Merged

Xinwei He (XinweiHe) merged 2 commits into
mainfrom
fix/anthropic-fast-mode-pricing

Conversation

@ka1kqi

@ka1kqi arthur du (ka1kqi) commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1581

Problem

A customer's anthropic/claude-opus-4.8-fast spans recorded no cost. Two independent causes:

  1. No fast rate card. Fast mode is a real, separately priced tier — $10/$50 per MTok on Opus 4.8, exactly 2x standard — that some gateways expose as a distinct -fast model slug. No entry matched it.
  2. Dot notation. Gateways spell versions with dots (claude-opus-4.8); our first-party patterns only accepted dashes. This zeroed costs for every current-gen Anthropic model for that customer, not just fast traffic.

Change

  • New claude-opus-4-8-fast entry: input/output/cacheRead/cacheWrite/cacheWrite1h all exactly 2x the standard Opus 4.8 entry, matching Anthropic's published fast-mode rates (cache multipliers apply on top of the fast base, per their pricing docs).
  • Dot-tolerant first-party patterns (4[.-]8 etc.) on the 7 current-gen Anthropic entries. Bedrock/Vertex pattern branches keep dashes (those platforms genuinely use dashes).

Also adopted from #1587 by Muhammad Hassaan (@hassaanch23) (co-author credit on the commit), who independently built the same fix and caught two things this PR originally lacked:

  • An Opus 4.7 fast entry ($30/$150 = 6x standard, cache derived from the fast base) — prices historical fast spans from before Anthropic's 2026-07-24 removal of 4.7 fast. A dedicated test locks it at 6x so neither tier's rate can be copy-forwarded to the other.
  • Legacy 3.x dot tolerance (claude-3.5-sonnet / claude-3.5-haiku are real old gateway slugs), first-party alternative only.

Deliberately excluded: Opus 4.6 fast (bills standard since 2026-06-29; adding it would over-charge — now enforced by a test_opus_4_6_has_no_fast_card guard, also adopted from #1587).

Complementary to #1566 (gateway prefix stripping, #1556) and independent of it: that PR normalizes openrouter/anthropic/... prefixes, this one adds the fast rate card and dot tolerance those normalized strings still need.

Note on rollout: prices reach the backend via the startup sync (syncStandardPrices) into Postgres, so the new entry takes effect when the worker/agent services next start — no manual migration needed.

Tests

  • TestClaudeFastAndDotNotationIds: 12 model-id cases — including all four repro strings from Cost is $0 for OpenRouter's anthropic/claude-opus-4.8-fast — no fast rate card, and dot-notation versions don't match #1581 (anthropic/claude-opus-4.8-fast, anthropic/claude-opus-4.8, anthropic/claude-sonnet-4.6, and the dash form) — each asserting resolution to the exact expected entry and that exactly one pattern matches (guards the undercharge trap where a loosened pattern could swallow -fast into the standard entry), plus a lock that every fast price stays exactly 2x standard.
  • Full suite: uv run pytest tests/worker/tokens/ -q — 241 passed.

Runtime verification

Exercised the real deploy pipeline against a throwaway database: prisma migrations → actual syncStandardPrices() run (88 models synced, fast entry landed with all 5 price rows) → Python worker's DB-backed lookup. All customer strings priced correctly, calculate_cost fast/standard ratio exactly 2.000, and adversarial probes held (-fastest no-match, gateway-prefixed strings left to the prefix-stripping PR, Bedrock/Vertex ids unchanged).

🤖 Generated with Claude Code


Summary by cubic

Fixes zero-cost Anthropic spans by pricing fast mode and accepting dot-notation model ids. Also logs a warning once per unmatched model id so unpriced spans are visible.

  • Bug Fixes

    • Added claude-opus-4-8-fast at exactly 2x claude-opus-4-8 for input/output/cache.
    • Added claude-opus-4-7-fast at 6x claude-opus-4-7 for historical fast spans.
    • First‑party Anthropic patterns accept dot or dash in versions (e.g., 4[.-]8, 3[.-]5); Bedrock/Vertex branches stay dashed.
    • Warn once per unmatched model id (bounded) when no pricing entry matches.
  • Migration

    • No manual steps. Prices sync on startup via syncStandardPrices; restart worker/agent services.

Written for commit 7b4e4f9. Summary will update on new commits.

Review in cubic

Fast mode is a separately priced tier (2x standard on Opus 4.8) that some
gateways expose as a distinct -fast model slug, and gateways commonly spell
model versions with dots (claude-opus-4.8) where our patterns only accepted
dashes. Both forms previously matched no pricing entry, so span costs were
silently left unset.

Adds a claude-opus-4-8-fast entry (input/output/cache all exactly 2x the
standard entry, per Anthropic's published fast-mode rates) and dot-tolerant
first-party patterns on the seven current-gen Anthropic entries. Bedrock and
Vertex pattern branches keep dashes, which those platforms genuinely use.

Co-Authored-By: Claude Fable 5 <[email protected]>
@ka1kqi
arthur du (ka1kqi) requested a review from a team July 17, 2026 22:05

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant GW as Customer Gateway
    participant API as Worker API
    participant Pricing as get_model_price()
    participant Cache as Price Cache
    participant Logger as Worker Logger

    Note over GW,Logger: Pricing Lookup Flow for Anthropic Model IDs

    GW->>API: Span with model id (e.g., "anthropic/claude-opus-4.8-fast")

    API->>Pricing: get_model_price("anthropic/claude-opus-4.8-fast")

    Pricing->>Cache: Iterate cached price entries with match patterns

    alt Model matches dot-notation or fast-mode pattern
        Cache-->>Pricing: Matched entry (e.g., claude-opus-4-8-fast with 2x prices)
        Pricing-->>API: Return price dict with name, input/output/cache rates
    else Model id is empty string
        Cache-->>Pricing: No match
        Pricing-->>API: Return None (no warning logged)
    else Model id unmatched (not empty, no pattern matches)
        Cache-->>Pricing: No match
        Pricing->>Pricing: Check _warned_unmatched_models set
        alt First time seeing this model id
            Pricing->>Pricing: Add model id to warned set
            Pricing->>Logger: WARNING "No pricing entry matched model '...'"
        else Model id already warned
            Pricing->>Pricing: Skip logging (dedup)
        end
        opt Warned set exceeds cap (1000)
            Pricing->>Pricing: Clear warned set to bound memory
        end
        Pricing-->>API: Return None
    end

    Note over GW,Logger: Model ID Patterns Resolved

    Note over Cache: Anthropic patterns use [.-] for version dots<br/>Bedrock/Vertex branches remain dashed-only
Loading

Re-trigger cubic

Comment thread backend/worker/tokens/pricing.py Outdated

_cache: list[dict] | None = None

# Model ids already warned about as unmatched, so each id logs once per

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this logic

…ot ids

Adopted from a parallel community fix for the same defect: the prior
Opus tier's fast mode is separately priced at 6x standard (not the
current tier's 2x — the premium dropped between versions, so neither
rate can be copy-forwarded to the other), and legacy 3.x model ids
also circulate in dot notation. Historical fast spans from the prior
tier now price correctly, and 3.x dot slugs resolve.

Patterns follow the existing convention: dot tolerance on the
first-party alternative only, and fast entries are distinct rate
cards that standard patterns cannot swallow.

Co-authored-by: hassaanch23 <[email protected]>

Co-Authored-By: Claude Fable 5 <[email protected]>
@ka1kqi
arthur du (ka1kqi) force-pushed the fix/anthropic-fast-mode-pricing branch from 7b4e4f9 to 251ed16 Compare July 22, 2026 19:45
@XinweiHe
Xinwei He (XinweiHe) merged commit 78b921b into main Jul 22, 2026
22 checks passed
@XinweiHe
Xinwei He (XinweiHe) deleted the fix/anthropic-fast-mode-pricing branch July 22, 2026 20:34
Satyam Chhetri (Satyam296) added a commit to Satyam296/traceroot that referenced this pull request Jul 23, 2026
…guous

ka1kqi suggested applying the same "exactly one pattern matches" idiom
used in traceroot-ai#1593's fast-mode/dot-notation tests to this PR's stripped
outputs. get_model_price returns the first entry that matches and
stops, so if a stripped model id ever collided with two catalog
entries, the bug would hide behind whichever happens to be first in
cache order. This re-runs the same exact/regex matching independently,
counting all matches instead of short-circuiting, over all 16
GATEWAY_PREFIX_CASES.

Purely additive: 220/220 tests pass (204 existing + 16 new).
Hao Yan (dark-sorceror) pushed a commit that referenced this pull request Jul 31, 2026
…icing

fix(pricing): price fast-mode and dot-notation Anthropic model ids
Hao Yan (dark-sorceror) pushed a commit that referenced this pull request Jul 31, 2026
…icing

fix(pricing): price fast-mode and dot-notation Anthropic model ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cost is $0 for OpenRouter's anthropic/claude-opus-4.8-fast — no fast rate card, and dot-notation versions don't match

2 participants