fix(cost): apply tier pricing for openai/azure/openrouter/helicone (#5690)#5691
Open
Anuj7411 wants to merge 1 commit into
Open
fix(cost): apply tier pricing for openai/azure/openrouter/helicone (#5690)#5691Anuj7411 wants to merge 1 commit into
Anuj7411 wants to merge 1 commit into
Conversation
…elicone#5690) getThresholdValueFunction only had cases for vertex, google-ai-studio, anthropic and xai; openai/azure/openrouter/helicone fell to the default () => 0, so getPricingTier always picked the cheapest base tier and higher-context tiers were never applied. As a result, large-context requests on these providers (e.g. gpt-5.4 over 272K tokens) were under-charged. Adds the missing provider cases (mirroring xai) and a regression test for gpt-5.4 over 272K tokens. Fixes Helicone#5690 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
|
@Anuj7411 is attempting to deploy a commit to the Helicone Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Hey team, gentle nudge whenever someone has a sec 🙂 small one-file change (mirrors the existing xai handler in the same switch) and the bug currently under-charges large-context openai calls by ~40% on gpt-5.4 over 272k tokens. Happy to answer anything if useful. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #5690.
packages/cost/models/calculate-cost.ts→getThresholdValueFunction(provider)only handledvertex,google-ai-studio,anthropicandxai. Every other provider — includingopenai,azure,openrouterandhelicone— fell todefault: () => 0. SincegetPricingTierselects the highest tier whosethreshold <= value, a constant0always picked the cheapest base tier, so higher-context tiers were unreachable for those providers.Concrete impact:
gpt-5.4(packages/cost/models/authors/openai/gpt-5.4/endpoints.ts) has a base tier and athreshold: 272000tier (input 2×, output 1.5×). For anopenaigpt-5.4request withinput=300000, output=50000:300000 × 0.000005 + 50000 × 0.0000225 = $2.625300000 × 0.0000025 + 50000 × 0.000015 = $1.50(~43% under)The same tiered config exists for the
azure,openrouterandheliconevariants ofgpt-5.4, all unhandled.Change
Adds
openai/azure/openrouter/heliconecases togetThresholdValueFunction, mirroring the existingxaihandler — the threshold value is the total prompt size (usage.input + (usage.cacheDetails?.cachedInput ?? 0)). ForcachedInputCost, the same total prompt size is used so the cached-input rate also tier-switches at the configured threshold.Test
Adds a regression test in
packages/__tests__/cost/modelCostFromRegistry.test.ts's existingdescribe("threshold-based pricing")block:openaigpt-5.4withinput=300000, output=50000→ asserts the >272K tier rates (inputCost === 300000 * 0.000005,outputCost === 50000 * 0.0000225).Without this PR's source change, that test computes the base-tier values (
$0.75/$0.75) and fails. With the fix it passes. (I wasn't able to spin up jest on Windows locally — runningnpx jest __tests__/from/packageserrored on a missingts-jestpreset in this checkout — but the change is mechanical: it adds 4 provider keys to the same switch that already handlesxaiidentically and is exercised by the existing Anthropic 250K test at lines 299-323.)Scope
No behaviour change for any currently-handled provider (
vertex,google-ai-studio,anthropic,xai); they keep their own threshold functions. Models onopenai/azure/openrouter/heliconethat don't define a higher-threshold tier are unaffected —getPricingTiersimply picks the base tier as before.Related context
PR #5268 introduced the threshold mechanism and wired the four providers above; the openai-shaped providers weren't wired at the same time, which is what surfaces here.
🤖 Generated with Claude Code