fix: remove hardcoded discounts - #2554
Conversation
|
Caution Review failedPull request was closed or merged during review WalkthroughThis PR removes the ChangesDiscount Field Removal & Simplification
🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…ount # Conflicts: # packages/db/migrations/meta/_journal.json
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 464f4d3e2f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (hasPositiveTokenPrice) { | ||
| return new Decimal(inputPrice ?? "0") | ||
| .plus(outputPrice ?? "0") | ||
| .div(2) | ||
| .times(discountMultiplier); | ||
| return new Decimal(inputPrice ?? "0").plus(outputPrice ?? "0").div(2); |
There was a problem hiding this comment.
Apply discounts before comparing provider prices
When an admin/global discount makes a provider cheaper, routing still compares the undiscounted list price here, even though billing later applies the discount via getEffectiveDiscount. All gateway callers of getCheapestFromAvailableProviders (for example the chat auto-routing path) use this helper to pick the provider, so a globally discounted provider can be skipped in favor of a provider that only appears cheaper before the discount is applied. This regresses discounted routing now that the hardcoded discount multiplier was removed from the selection price.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR removes “hardcoded” provider/model discount fields from the static model catalog and the model_provider_mapping database schema, shifting discount handling to admin-configured discount records (global/org) and cleaning up discount-related UI/API surfaces accordingly.
Changes:
- Remove
discountfrom model catalog types/definitions and from themodel_provider_mappingDB schema + seeding/sync. - Strip hardcoded discount logic from pricing displays, calculators, and selection helpers/tests.
- Adjust API/admin/UI types and endpoints to reflect the new discount source (discount records).
Reviewed changes
Copilot reviewed 38 out of 43 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/shared/src/components/model-selector.tsx | Removes mapping-level discount price formatting/aggregation. |
| packages/models/src/types.ts | Removes discount from ModelWithPricing provider entries. |
| packages/models/src/models/zai.ts | Deletes hardcoded discounts from ZAI mappings. |
| packages/models/src/models/openai.ts | Deletes hardcoded discounts from an OpenAI mapping. |
| packages/models/src/models/google.ts | Deletes hardcoded discounts from Google mappings. |
| packages/models/src/models/deepseek.ts | Deletes hardcoded discounts from DeepSeek mappings. |
| packages/models/src/models/bytedance.ts | Deletes hardcoded discounts from ByteDance mappings. |
| packages/models/src/models/alibaba.ts | Deletes hardcoded discounts from Alibaba mappings. |
| packages/models/src/models.ts | Removes discount from model catalog mapping/region interfaces. |
| packages/db/src/seed.ts | Stops seeding model_provider_mapping.discount. |
| packages/db/src/schema.ts | Drops discount column from model_provider_mapping table schema. |
| packages/db/src/discount-helpers.ts | Removes “hardcoded” fallback discount source from effective discount lookup. |
| packages/db/migrations/meta/_journal.json | Registers migration to drop the discount column. |
| packages/db/migrations/1780857793_free_longshot.sql | Drops discount column from model_provider_mapping. |
| packages/actions/src/validate-provider-key.ts | Removes discount-adjusted pricing from validation model selection. |
| packages/actions/src/models.spec.ts | Removes discount-related routing tests and updates expectations. |
| packages/actions/src/get-cheapest-model-for-provider.ts | Removes discount multiplier from cheapest-model computation. |
| packages/actions/src/get-cheapest-from-available-providers.ts | Removes discount multiplier from provider selection price computation. |
| ee/admin/src/lib/api/v1.d.ts | Updates generated admin API types to remove discount from model stats mapping. |
| ee/admin/src/components/models-table.tsx | Removes discount column/badge from the admin models table UI. |
| ee/admin/src/app/discounts/page.tsx | Updates copy to remove “hardcoded discount” references. |
| apps/worker/src/services/sync-models.ts | Stops syncing discount into model-provider mappings. |
| apps/ui/src/lib/api/v1.d.ts | Updates generated UI API types to remove discount from model stats mapping. |
| apps/ui/src/components/token-cost-calculator/token-cost-calculator-client.tsx | Removes hardcoded discount application/display in calculator comparisons. |
| apps/ui/src/components/models/provider-card.tsx | Adds optional discount to augmented provider type (supports DB-driven discount data). |
| apps/ui/src/components/models/model-provider-card.tsx | Adds optional discount to augmented provider type (supports DB-driven discount data). |
| apps/ui/src/components/models/model-comparison.tsx | Adds optional discount to augmented provider type (supports DB-driven discount data). |
| apps/ui/src/components/models/category-og-image.tsx | Removes hardcoded discount-based filtering for “discounted” category OG image. |
| apps/ui/src/components/models/adapt-model.ts | Adds optional discount to augmented provider type (supports DB-driven discount data). |
| apps/ui/src/components/models-supported.tsx | Forces discount field to null when rendering static “supported models” data. |
| apps/ui/src/components/enterprise/cost-calculator.tsx | Removes mapping discount impact from enterprise cost calculator UI. |
| apps/ui/src/components/cost-simulator/cost-simulator-client.tsx | Removes mapping discount impact from simulator UI (text + image). |
| apps/ui/src/app/providers/[id]/page.tsx | Stops exposing mapping-level discounts on provider page model mappings. |
| apps/ui/src/app/models/[name]/page.tsx | Uses DB-driven provider discount only (no mapping fallback). |
| apps/ui/src/app/models/[name]/[provider]/page.tsx | Uses DB-driven provider discount only (no mapping fallback). |
| apps/ui/src/app/models/[name]/[provider]/opengraph-image.tsx | Removes mapping discount fallback when computing OG discount. |
| apps/playground/src/lib/api/v1.d.ts | Updates generated playground API types to remove discount from model stats mapping. |
| apps/gateway/src/lib/costs.ts | Removes passing hardcoded discount into effective discount lookup. |
| apps/gateway/src/lib/costs.spec.ts | Updates mocking/expectations for new getEffectiveDiscount signature. |
| apps/code/src/lib/api/v1.d.ts | Updates generated code app API types to remove discount from model stats mapping. |
| apps/api/src/routes/internal-models.ts | Applies global discounts from discount records into returned mappings. |
| apps/api/src/routes/admin.ts | Removes discount field from model stats schema/query output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Lucide "Percent" icon path | ||
| iconSvgPath: | ||
| "M19 5L5 19 M9 6.5a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z M20 17.5a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z", | ||
| countFilter: (m) => { | ||
| const providers = m.providers as ProviderModelMapping[]; | ||
| return providers.some((p) => p.discount && Number(p.discount) > 0); | ||
| }, | ||
| countFilter: () => false, | ||
| }, |
| if (hasPositiveTokenPrice) { | ||
| return new Decimal(inputPrice ?? "0") | ||
| .plus(outputPrice ?? "0") | ||
| .div(2) | ||
| .times(discountMultiplier); | ||
| return new Decimal(inputPrice ?? "0").plus(outputPrice ?? "0").div(2); | ||
| } | ||
|
|
||
| if (requestPrice !== undefined && !hasPositiveTokenPrice) { |
Summary
Validation
Summary by CodeRabbit
Release Notes
Bug Fixes
UI Updates
API Changes
/modelsadmin endpoint response to exclude discount field and include pricing details (inputPrice,outputPrice,requestPrice).