Skip to content

fix: remove hardcoded discounts - #2554

Merged
steebchen merged 2 commits into
mainfrom
remove-hardcoded-discount
Jun 7, 2026
Merged

steebchen merged 2 commits into
mainfrom
remove-hardcoded-discount

Conversation

@steebchen

@steebchen steebchen commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

  • remove static provider/model discount fields from the model catalog and DB mapping schema
  • route pricing and provider selection through admin/global discount records only
  • remove hardcoded discount displays from admin, public model pages, calculators, and generated API types

Validation

  • pnpm format
  • pnpm vitest run packages/actions/src/models.spec.ts --no-file-parallelism
  • pnpm test:unit
  • pnpm build

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed pricing calculation logic by removing discount field from model pricing data and cost computations.
  • UI Updates

    • Simplified cost simulator and pricing displays by removing "% off" discount badges and discount-related indicators.
    • Updated models and providers tables to remove discount column and show base pricing information instead.
  • API Changes

    • Updated /models admin endpoint response to exclude discount field and include pricing details (inputPrice, outputPrice, requestPrice).

@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This PR removes the discount field from the entire pricing pipeline: dropping it from the database schema, type definitions, API responses, cost calculations, UI rendering, and model configurations. The core getEffectiveDiscount function is simplified by removing its hardcoded fallback parameter, and pricing is now computed directly from input/output/request price fields without discount application.

Changes

Discount Field Removal & Simplification

Layer / File(s) Summary
Database schema and type contracts
packages/db/migrations/1780857793_free_longshot.sql, packages/db/migrations/meta/_journal.json, packages/db/src/schema.ts, packages/db/src/seed.ts, packages/models/src/models.ts
Migration drops discount column from model_provider_mapping; schema removes discount fields from ProviderRegion and ProviderModelMapping types; seed generation no longer assigns discount values.
Discount resolution helper simplification
packages/db/src/discount-helpers.ts
getEffectiveDiscount signature simplified to remove hardcodedDiscount parameter; fallback behavior now returns { discount: "0", source: "none" } instead of using passed hardcoded values; EffectiveDiscount.source changes from "hardcoded" to "none".
API endpoint pricing fields
apps/api/src/routes/admin.ts, apps/api/src/routes/internal-models.ts
/models endpoint response updated to return inputPrice, outputPrice, requestPrice instead of discount; /internal/models computes discount directly from global discount without mapping fallback.
Gateway cost calculation and tests
apps/gateway/src/lib/costs.ts, apps/gateway/src/lib/costs.spec.ts
getEffectiveDiscount called without hardcoded discount parameter; test mock simplified to return fixed { discount: "0", source: "none" } regardless of inputs.
Provider selection and cost calculation actions
packages/actions/src/get-cheapest-from-available-providers.ts, packages/actions/src/get-cheapest-model-for-provider.ts, packages/actions/src/validate-provider-key.ts
All pricing computations stop applying discount multipliers; model selection uses undiscounted average prices; getProviderSelectionPrice type narrowed to exclude discount.
Action pricing tests cleanup
packages/actions/src/models.spec.ts
Removes import of getProviderDefinition; deletes discount-validation tests; removes discount-path assertions; updates price expectations.
Model sync worker discount removal
apps/worker/src/services/sync-models.ts
Removes discount field from both update and insert paths for modelProviderMapping database writes.
UI model detail pages discount handling
apps/ui/src/app/models/[name]/[provider]/opengraph-image.tsx, apps/ui/src/app/models/[name]/[provider]/page.tsx, apps/ui/src/app/models/[name]/page.tsx, apps/ui/src/app/providers/[id]/page.tsx
Provider discount computed directly from globalDiscount without fallback to mapping discount; OpenGraph image discount resolves to undefined if global discount not found; provider detail rendering sets discount to null.
UI cost and token calculation components
apps/ui/src/components/cost-simulator/cost-simulator-client.tsx, apps/ui/src/components/enterprise/cost-calculator.tsx, apps/ui/src/components/token-cost-calculator/token-cost-calculator-client.tsx
All pricing calculations remove discount application; gateway cost computed directly from base request price; discount UI labels and "% off" displays removed; price aggregation uses raw price fields.
Shared model selector pricing aggregation
packages/shared/src/components/model-selector.tsx
Request pricing no longer applies discount computation; minimum price aggregation uses readPrice helper on raw price fields instead of computing discounted prices.
UI component type updates for discount field
apps/ui/src/components/models/adapt-model.ts, apps/ui/src/components/models/model-comparison.tsx, apps/ui/src/components/models/model-provider-card.tsx, apps/ui/src/components/models/provider-card.tsx
ProviderWithInfo interface updated to include optional discount?: string | null field for type correctness.
Admin interface discount UI removal
ee/admin/src/app/discounts/page.tsx, ee/admin/src/components/models-table.tsx
Discount column removed from models table; formatDiscount helper deleted; discount badge rendering replaced with conditional token/request pricing display; discounts page messaging updated to describe automatic application without precedence language.
Model definition cleanup - discount removal
packages/models/src/models/alibaba.ts, packages/models/src/models/bytedance.ts, packages/models/src/models/deepseek.ts, packages/models/src/models/google.ts, packages/models/src/models/openai.ts, packages/models/src/models/zai.ts
Removes hardcoded discount field values from 60+ provider configurations across all model definition files (Qwen, Bytedance, DeepSeek, Gemini, OpenAI, Zhipu/GLM).
Model type and interface cleanup
packages/models/src/types.ts
Removes discount field from ModelWithPricing.providers[] type definition.
OpenGraph image category filter update
apps/ui/src/components/models/category-og-image.tsx
Updates categoryConfigs.discounted.countFilter to always return false, making discounted model category count 0.

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • smakosh
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: remove hardcoded discounts' directly and clearly describes the main objective of the changeset: removing static discount fields from the codebase and database.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove-hardcoded-discount

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 and usage tips.

…ount

# Conflicts:
#	packages/db/migrations/meta/_journal.json
@steebchen
steebchen marked this pull request as ready for review June 7, 2026 18:51
Copilot AI review requested due to automatic review settings June 7, 2026 18:51
@steebchen
steebchen enabled auto-merge June 7, 2026 18:51

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines 300 to +301
if (hasPositiveTokenPrice) {
return new Decimal(inputPrice ?? "0")
.plus(outputPrice ?? "0")
.div(2)
.times(discountMultiplier);
return new Decimal(inputPrice ?? "0").plus(outputPrice ?? "0").div(2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 discount from model catalog types/definitions and from the model_provider_mapping DB 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.

Comment on lines 128 to 132
// 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,
},
Comment on lines 300 to 304
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) {
@steebchen
steebchen added this pull request to the merge queue Jun 7, 2026
@steebchen
steebchen removed this pull request from the merge queue due to a manual request Jun 7, 2026
@steebchen
steebchen merged commit afda1ae into main Jun 7, 2026
17 of 18 checks passed
@steebchen
steebchen deleted the remove-hardcoded-discount branch June 7, 2026 19:04
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