Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): keep usage pricing aliases distinct #5810

Closedcaezium(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5810/headopened View on GitHub

What 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 RateTable in usagePricing.ts from a flat Map<string, ModelRate> into an object with exactRates, bareAliases, and modelCount, so provider-qualified and bare alias entries are stored separately.
  • parseRateTable now drops ambiguous normalized duplicates (no canonical provenance) and only creates bare aliases for canonical or unambiguous entries.
  • lookupRate no longer falls back from a missing provider-qualified key to a bare alias; bare lookups still resolve via exactRates then bareAliases.
  • UsageService switches from Map.size to rateTableModelCount() 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.
Macroscope summarized c3b1d5c.

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.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c3b1d5c4530cf702e25fdf3f0bd82022eaa7687d. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 73cbbf5f-9a6e-4139-a8e2-f7d88a635b69

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. 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).
    4. 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.

Sign in to join this conversation.