Repository navigation
fix(pricing): price fast-mode and dot-notation Anthropic model ids - #1593
Merged
Merged
Conversation
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]>
Contributor
There was a problem hiding this comment.
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
4 tasks done
This was referenced Jul 22, 2026
|
|
||
| _cache: list[dict] | None = None | ||
|
|
||
| # Model ids already warned about as unmatched, so each id logs once per |
Member
There was a problem hiding this comment.
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]>
Xinwei He (XinweiHe)
approved these changes
Jul 22, 2026
arthur du (ka1kqi)
force-pushed
the
fix/anthropic-fast-mode-pricing
branch
from
July 22, 2026 19:45
7b4e4f9 to
251ed16
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1581
Problem
A customer's
anthropic/claude-opus-4.8-fastspans recorded no cost. Two independent causes:-fastmodel slug. No entry matched it.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
claude-opus-4-8-fastentry: 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).4[.-]8etc.) 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:
claude-3.5-sonnet/claude-3.5-haikuare 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_cardguard, 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-fastinto the standard entry), plus a lock that every fast price stays exactly 2x standard.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_costfast/standard ratio exactly 2.000, and adversarial probes held (-fastestno-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
claude-opus-4-8-fastat exactly 2xclaude-opus-4-8for input/output/cache.claude-opus-4-7-fastat 6xclaude-opus-4-7for historical fast spans.4[.-]8,3[.-]5); Bedrock/Vertex branches stay dashed.Migration
syncStandardPrices; restart worker/agent services.Written for commit 7b4e4f9. Summary will update on new commits.