Skip to content

fix(cost): apply tier pricing for openai/azure/openrouter/helicone (#5690)#5691

Open
Anuj7411 wants to merge 1 commit into
Helicone:mainfrom
Anuj7411:Anuj7411/issue-5690-openai-tiered-pricing
Open

fix(cost): apply tier pricing for openai/azure/openrouter/helicone (#5690)#5691
Anuj7411 wants to merge 1 commit into
Helicone:mainfrom
Anuj7411:Anuj7411/issue-5690-openai-tiered-pricing

Conversation

@Anuj7411

@Anuj7411 Anuj7411 commented Jun 6, 2026

Copy link
Copy Markdown

What

Fixes #5690.

packages/cost/models/calculate-cost.tsgetThresholdValueFunction(provider) only handled vertex, google-ai-studio, anthropic and xai. Every other provider — including openai, azure, openrouter and helicone — fell to default: () => 0. Since getPricingTier selects the highest tier whose threshold <= value, a constant 0 always 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 a threshold: 272000 tier (input 2×, output 1.5×). For an openai gpt-5.4 request with input=300000, output=50000:

  • Expected: 300000 × 0.000005 + 50000 × 0.0000225 = $2.625
  • Actual (pre-fix): base tier → 300000 × 0.0000025 + 50000 × 0.000015 = $1.50 (~43% under)

The same tiered config exists for the azure, openrouter and helicone variants of gpt-5.4, all unhandled.

Change

Adds openai / azure / openrouter / helicone cases to getThresholdValueFunction, mirroring the existing xai handler — the threshold value is the total prompt size (usage.input + (usage.cacheDetails?.cachedInput ?? 0)). For cachedInputCost, 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 existing describe("threshold-based pricing") block:

  • openai gpt-5.4 with input=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 — running npx jest __tests__/ from /packages errored on a missing ts-jest preset in this checkout — but the change is mechanical: it adds 4 provider keys to the same switch that already handles xai identically 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 on openai / azure / openrouter / helicone that don't define a higher-threshold tier are unaffected — getPricingTier simply 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

…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>

@greptile-apps greptile-apps 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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

@Anuj7411 is attempting to deploy a commit to the Helicone Team on Vercel.

A member of the Team first needs to authorize it.

@Anuj7411

Copy link
Copy Markdown
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.

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.

[Bug]: Cost calculation never applies higher-tier (>threshold) pricing for OpenAI / Azure / OpenRouter

1 participant