Skip to content

feat: add tiered pricing for gemini-2.5-pro - #2741

Merged
dcbartlett merged 4 commits into
cline:mainfrom
monotykamary:feat/gemini-tiered-pricing
Apr 9, 2025
Merged

dcbartlett merged 4 commits into
cline:mainfrom
monotykamary:feat/gemini-tiered-pricing

Conversation

@monotykamary

@monotykamary monotykamary commented Apr 8, 2025 •

Copy link
Copy Markdown
Contributor

Description

This PR introduces tiered pricing calculation and display for the gemini-2.5-pro-preview-03-25 model based on input token count.

Changes:

  • src/shared/api.ts:
    • Added a PriceTier interface.
    • Updated ModelInfo to include optional inputPriceTiers and outputPriceTiers arrays.
    • Modified the gemini-2.5-pro-preview-03-25 definition to use these tiers, reflecting the $1.25/$2.50 input and $10.00/$15.00 output pricing based on a 200k input token threshold.
  • src/utils/cost.ts:
    • Refactored calculateApiCostInternal to determine effective input/output prices based on tiers if available, using a new totalInputTokensForPricing parameter.
    • Updated calculateApiCostOpenAI to pass the total input tokens for tier lookup.
  • webview-ui/src/components/settings/ApiOptions.tsx:
    • Updated ModelInfoView to display tiered pricing clearly, with each tier on a new indented line.
    • Refactored rendering logic to use <span> and Fragment for better layout and spacing control.

Test Procedure

  1. Select "Google Gemini" as the API Provider in settings.
  2. Choose the gemini-2.5-pro-preview-03-25 model.
  3. Observe the "Model Info" section below the dropdown.
  4. Verify that the Input and Output prices are displayed with two tiers each:
    • Input: <= 200k tokens ($1.25/M) and > 200k tokens ($2.50/M)
    • Output: <= 200k tokens ($10.00/M) and > 200k tokens ($15.00/M) (based on input tokens)
  5. Verify the formatting matches the final screenshot (compact spacing).
  6. (Optional) If possible, trigger API calls with prompts below and above 200k tokens and verify the cost calculation reflects the correct tier pricing in any relevant logs or usage tracking.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update

Pre-flight Checklist

  • Changes are limited to a single feature, bugfix or chore (split larger changes into separate PRs)
  • Tests are passing (npm test) and code is formatted and linted (npm run format && npm run lint) (Based on pre-commit hook success)
  • I have created a changeset using npm run changeset (Required for user-facing changes - Please run this if needed)
  • I have reviewed contributor guidelines

Screenshots

Final UI showing tiered pricing for Gemini model in settings.
image

Additional Notes

This change generalizes the pricing structure to support future models with tiered costs.

@changeset-bot

changeset-bot Bot commented Apr 8, 2025 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2381fcd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ellipsis-dev ellipsis-dev Bot left a comment

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.

❌ Changes requested. Reviewed everything up to f5a9949 in 2 minutes and 59 seconds

More details
  • Looked at 246 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 6 drafted comments based on config settings.
1. src/utils/cost.ts:15
  • Draft comment:
    Assumes tiers are sorted in ascending order by tokenLimit. Consider verifying/sorting them to ensure correct tier lookup.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
    The comment identifies a real potential issue - unsorted tiers could lead to incorrect pricing. However, this seems like something that should be validated when creating/setting the tiers, not every time we look them up. The comment also doesn't provide clear direction on where/how to implement the validation.
    The issue could be serious if it leads to incorrect pricing. The suggestion to sort tiers could be a valid solution.
    While pricing correctness is important, this validation belongs at the data layer where tiers are defined/loaded, not in the cost calculation function. The current comment location puts the fix in the wrong place.
    Delete the comment because it suggests adding validation in the wrong place and doesn't provide clear, actionable guidance.
2. webview-ui/src/components/settings/ApiOptions.tsx:1608
  • Draft comment:
    The tiered pricing rendering code assumes inputPriceTiers (and similarly outputPriceTiers) are provided in the expected sorted order. Consider adding a comment or safeguard if order isn’t guaranteed.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
3. src/utils/cost.ts:15
  • Draft comment:
    The non-null assertion on totalInputTokensForPricing is safe due to the preceding check, but consider omitting '!' for clarity.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50%
    None
4. webview-ui/src/components/settings/ApiOptions.tsx:1564
  • Draft comment:
    Avoid hard-coding the callback URL domain ('saoudrizwan.claude-dev') in getOpenRouterAuthUrl; consider externalizing or parameterizing for production use.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
5. webview-ui/src/components/settings/ApiOptions.tsx:1605
  • Draft comment:
    The check for Gemini models uses Object.keys(geminiModels).includes(selectedModelId). Using the provider value (e.g. selectedProvider === 'gemini') might be more robust.
  • Reason this comment was not posted:
    Comment was on unchanged code.
6. webview-ui/src/components/settings/ApiOptions.tsx:1577
  • Draft comment:
    The tier formatting helper (formatTiers) is well written; consider memoizing its result if the tiers rarely change, to optimize re-renders.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50%
    None

Workflow ID: wflow_U6EcK3Y5j56HvT7K


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Comment thread src/utils/cost.ts Outdated
Comment thread src/shared/api.ts
- Clarify token limit display using full numbers instead of 'k'.
- Specify price unit as '/million tokens' for better understanding.
@frostbournesb
frostbournesb self-requested a review April 9, 2025 01:27
Comment thread src/utils/cost.ts
Comment thread webview-ui/src/components/settings/ApiOptions.tsx
@dcbartlett
dcbartlett merged commit b470229 into cline:main Apr 9, 2025
@saoudrizwan

Copy link
Copy Markdown
Contributor

thank you 🙏

canvrno pushed a commit that referenced this pull request May 2, 2025
* feat: add tiered pricing for gemini-2.5-pro

* fix: ensure price tiers are sorted before lookup

* refactor: remove old prices

* refactor(settings): improve model tier pricing display clarity

- Clarify token limit display using full numbers instead of 'k'.
- Specify price unit as '/million tokens' for better understanding.
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.

5 participants