Skip to content

fix(pricing): sync flex/priority tier keys to dated OpenAI snapshot variants - #35923

Merged
mateo-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_dated_variant_tier_pricing_sync
Aug 6, 2026
Merged

fix(pricing): sync flex/priority tier keys to dated OpenAI snapshot variants#35923
mateo-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_dated_variant_tier_pricing_sync

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Dated OpenAI snapshots lack the flex/priority pricing their base alias has
  • Pinning a snapshot silently bills service-tier traffic at standard rates

How it solves it:

  • Copies base-alias tier keys onto 9 dated snapshot entries
  • Adds a schema test that fails on any future tier-key drift

User Flow

Before: pinning a dated snapshot silently bills service-tier traffic at standard rates, undercharging priority and overcharging flex

  1. A platform engineer pins gpt-4.1-2025-04-14 for reproducible evals and sends POST https://litellm-domain/v1/chat/completions with "service_tier": "priority" under their virtual key
  2. The response body confirms OpenAI served the call at "service_tier": "priority"
  3. The x-litellm-response-cost header reads the standard rate, roughly half of what OpenAI invoices for priority processing
  4. A teammate running overnight evals on o4-mini-2025-04-16 with "service_tier": "flex" is billed double what OpenAI charges, since the 50% flex discount never applies
  5. Key budgets and the spend page at https://litellm-domain/ui/?page=usage drift further from the provider invoice with every tiered call

After: the same pinned snapshots bill the tier's real price

  1. A platform engineer pins gpt-4.1-2025-04-14 for reproducible evals and sends POST https://litellm-domain/v1/chat/completions with "service_tier": "priority" under their virtual key
  2. The response body confirms OpenAI served the call at "service_tier": "priority"
  3. The x-litellm-response-cost header reads the snapshot's priority rate, matching what the base alias gpt-4.1 charges and what OpenAI invoices
  4. The teammate's flex eval run is billed at half the standard rate, matching OpenAI's flex discount
  5. Key budgets and the spend page track the provider invoice for tiered traffic

Relevant issues

Supersedes #22086

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Both legs hit the real OpenAI API through a local proxy booted with LITELLM_LOCAL_MODEL_COST_MAP=True and this config:

model_list:
  - model_name: gpt-4.1-2025-04-14
    litellm_params:
      model: openai/gpt-4.1-2025-04-14
      api_key: os.environ/OPENAI_API_KEY
  - model_name: o4-mini-2025-04-16
    litellm_params:
      model: openai/o4-mini-2025-04-16
      api_key: os.environ/OPENAI_API_KEY

Priority tier on a pinned gpt-4.1 snapshot (same request against each proxy):

curl -sD - http://localhost:<port>/v1/chat/completions \
  -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model":"gpt-4.1-2025-04-14","service_tier":"priority","messages":[{"role":"user","content":"Reply with exactly: pong"}]}'

Before (bcce83a, base branch): OpenAI confirms "service_tier": "priority" with usage 12 prompt + 1 completion tokens, yet the proxy bills standard rates

x-litellm-response-cost: 3.2e-05   (12 x 2e-06 + 1 x 8e-06, the standard rate)

After (629c228, this PR): identical request, identical usage (12 + 1), now billed at the snapshot's synced priority keys

x-litellm-response-cost: 5.6e-05   (12 x 3.5e-06 + 1 x 1.4e-05, the priority rate)

Flex tier on a pinned o4-mini snapshot, same curl with "model":"o4-mini-2025-04-16","service_tier":"flex". Both legs returned "service_tier": "flex" with usage 11 prompt + 83 completion (64 reasoning) tokens

Before (bcce83a17e): x-litellm-response-cost: 0.0003773    (standard: 11 x 1.1e-06 + 83 x 4.4e-06)
After  (629c228b40): x-litellm-response-cost: 0.00018865   (flex, exactly 50%: 11 x 5.5e-07 + 83 x 2.2e-06)

Type

🐛 Bug Fix

Changes

OpenAI publishes flex and priority prices per model family, and LiteLLM carries them on the base aliases (gpt-4.1, gpt-4o, o3, o4-mini, gpt-5-nano, and friends), but most dated snapshot entries never received the keys. Anyone pinning a snapshot, which is the recommended practice for reproducible evals and batch jobs, got service-tier traffic billed at standard rates: undercharged for priority, overcharged for flex

This PR syncs the missing *_flex and *_priority keys from each base alias to its dated variants in model_prices_and_context_window.json and the backup copy: gpt-4.1-2025-04-14, gpt-4.1-mini-2025-04-14, gpt-4.1-nano-2025-04-14, gpt-4o-2024-08-06, gpt-4o-2024-11-20, gpt-4o-mini-2024-07-18, gpt-5-nano-2025-08-07, o3-2025-04-16, and o4-mini-2025-04-16. A key is copied only when the variant's corresponding standard-rate key exists and exactly matches the base alias, so snapshots with genuinely different pricing are left alone (gpt-4o-2024-05-13 is intentionally skipped for this reason)

tests/test_litellm/test_model_prices_schema.py gains test_dated_variants_carry_base_alias_service_tier_pricing, which walks every <name>-YYYY-MM-DD entry and fails whenever a base alias gains a tier key its price-matched snapshot lacks, so the drift cannot reappear as new tier prices land

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

…ariants

Dated snapshots like o4-mini-2025-04-16 were missing the flex and priority cost keys their base alias carries, so service-tier requests against pinned snapshots were billed at standard rates. Sync the tier keys wherever the snapshot's anchor prices match the base alias, and add a drift regression test.
@greptile-apps

greptile-apps Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR synchronizes flex and priority pricing metadata from OpenAI base aliases to price-matched dated snapshots and adds a regression test for future drift.

  • Updates the canonical and backup pricing maps consistently.
  • Adds schema coverage comparing dated snapshots with their corresponding base aliases.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
model_prices_and_context_window.json Adds service-tier pricing fields to the canonical entries for nine dated OpenAI snapshots.
litellm/model_prices_and_context_window_backup.json Mirrors the canonical service-tier pricing additions in the backup pricing map.
tests/test_litellm/test_model_prices_schema.py Adds a regression test that checks price-matched dated variants for base-alias flex and priority fields.

Reviews (2): Last reviewed commit: "fix(pricing): sync flex/priority tier ke..." | Re-trigger Greptile

Comment thread tests/test_litellm/test_model_prices_schema.py
"cache_read_input_token_cost": 5e-07,
"cache_read_input_token_cost_priority": 8.75e-07,
"input_cost_per_token": 2e-06,
"input_cost_per_token_priority": 3.5e-06,

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.

Medium: Priority pricing bypasses budget reservation

These _priority rates are used during final cost calculation, while budget_reservation.py estimates requests exclusively from input_cost_per_token and output_cost_per_token. A user can send priority requests against these models that pass admission using the lower standard estimate but consume up to roughly twice the reserved key or team budget. Update the reservation estimator to select the service-tier-specific input, output, cache, and reasoning rates from request_body["service_tier"], with the same fallback behavior as final cost calculation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reservation already ignored service_tier for the base aliases' existing priority keys; this sync doesn't widen that pre-existing gap: tier-aware reservation deserves its own PR

@veria-ai

veria-ai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

PR overview

This pull request updates OpenAI pricing metadata so flex and priority service-tier keys align with dated model snapshot variants.

One security issue remains open: priority-tier requests are admitted using lower standard-rate budget estimates but charged at higher priority rates, allowing users to exceed reserved key or team budgets by roughly twofold. The reservation logic still needs to account for service-tier-specific pricing, and no issues have yet been addressed.

Open issues (1)

Fixed/addressed: 0 · PR risk: 5/10

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_dated_variant_tier_pricing_sync (629c228) with litellm_internal_staging (732bba0)

Open in CodSpeed

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri
mateo-berri merged commit b45b4b7 into litellm_internal_staging Aug 6, 2026
78 checks passed
@mateo-berri
mateo-berri deleted the litellm_dated_variant_tier_pricing_sync branch August 6, 2026 04:09
Duxl-Ai pushed a commit to Duxl-Ai/litellm that referenced this pull request Aug 20, 2026
Seven live e2e tests covering cost-tracking regressions that currently ship
unnoticed: cache-write tokens billed at the cache-creation rate (BerriAI#34046),
per-component cost_breakdown on the spend row (BerriAI#31686), cache reads billed at
the cache-read discount on streamed calls (BerriAI#34812), cache tokens surviving the
anthropic-messages to Responses bridge (BerriAI#34957), priority-tier rates applied to
input, output and reasoning (BerriAI#35923, BerriAI#35925), the per-component response cost
headers summing to the total (BerriAI#36965), and cost injected into the final usage
frame of an /openai passthrough stream (BerriAI#36503).

Every test registers its own deployment with a distinct custom rate per
component, so a component billed at the wrong rate cannot pass. The shared
helpers in cost_rows.py encode the one thing the two surfaces disagree on: the
spend row's input_cost is gross of cache while the response's cost-input header
is net of it.
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.

2 participants