fix(server): keep usage pricing aliases distinct #5810
main fromrefs/pull/5810/head·opened View on GitHubWhat Changed#
- Separate exact provider-qualified rates, bare aliases, and the public model count.
- Resolve qualified model names only through their exact provider key.
- Prefer a canonical bare rate, allow one unambiguous provider fallback, and leave ambiguous collisions unpriced.
- Make case/whitespace-normalized collisions deterministic instead of document-order dependent.
- Keep aliases from inflating
pricing.knownModels.
Why#
The rate parser currently strips provider prefixes before insertion, so LiteLLM entries ending in the same model name overwrite one another. JSON order can change base and cache pricing, including replacing a canonical cache-read rate with full input price.
Closes #5797
Verification#
- 16 focused pricing and aggregation tests passed after review fixes.
- Targeted formatting and lint passed.
- Server typecheck passed; only pre-existing unrelated Effect suggestions remain.
- Branch rebased on current
upstream/main.
Checklist#
- This PR is small and focused
- I explained what changed and why
- No UI changes
Implemented with gpt-5.6-sol in T3 Code through the Codex harness.
Note
Fix lookupRate to keep provider-qualified and bare alias entries distinct in RateTable#
- Restructures
RateTablein usagePricing.ts from a flatMap<string, ModelRate>into an object withexactRates,bareAliases, andmodelCount, so provider-qualified and bare alias entries are stored separately. parseRateTablenow drops ambiguous normalized duplicates (no canonical provenance) and only creates bare aliases for canonical or unambiguous entries.lookupRateno longer falls back from a missing provider-qualified key to a bare alias; bare lookups still resolve viaexactRatesthenbareAliases.UsageServiceswitches fromMap.sizetorateTableModelCount()so alias-only entries are excluded from model counts and rate-status decisions.- Behavioral Change: provider-qualified model lookups that previously matched a bare alias will now return null if no exact entry exists.
Note
Medium Risk Changes how transcript model names map to LiteLLM rates, so some costs may shift from priced to unpriced (or vice versa) for ambiguous or provider-qualified names.
Overview Fixes LiteLLM usage pricing so provider-qualified model keys no longer overwrite each other when normalized to the same bare name.
RateTable is no longer a single Map; it now holds exactRates, optional bareAliases, and modelCount. parseRateTable indexes entries by the full normalized key, resolves duplicate spellings only when one row matches the canonical key (otherwise drops the key), and adds a bare alias only for a canonical bare entry or a single unambiguous provider-qualified candidate. lookupRate uses exact keys for provider/model lookups (no bare fallback on miss); bare names still resolve via exact then alias. UsageService uses emptyRateTable, rateTableModelCount, and reports knownModels from exact entries only.
Adds usagePricing.test.ts for alias/collision behavior; aggregation tests build rates via parseRateTable.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Needs human review
This PR modifies pricing lookup logic in the usage/billing infrastructure. Changes to billing and pricing code paths require human review regardless of apparent simplicity, as they can affect cost calculations for users.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Note
🤖 GPT-6 Astra (preview) responding on behalf of Theo
This was closed as part of an automated cleanup pass. If you believe it was closed in error, reply here and we will get it reopened.
Closing as superseded by #8806, which is on main. Pricing now keeps provider-qualified keys distinct, preserves canonical rates, and rejects conflicting bare aliases without falling back across missing qualified keys. The separate model-count and normalized-collision cases remain available in this branch, but do not require replacing the shipped rate lookup.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
73cbbf5f-9a6e-4139-a8e2-f7d88a635b69You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share