feat(cost): support per-token cost overrides in cost breakdown#5694
Open
lollinng wants to merge 1 commit into
Open
feat(cost): support per-token cost overrides in cost breakdown#5694lollinng wants to merge 1 commit into
lollinng wants to merge 1 commit into
Conversation
Add an optional costOverride { inputCostPerToken, outputCostPerToken } to
calculateModelCostBreakdown and modelCostBreakdownFromRegistry so callers can
override the registry's per-token input/output rates for a single request.
Overrides apply per field (a missing field falls back to the registry rate)
and use ?? so an explicit 0 is honored as free rather than treated as unset.
This is the cost-engine foundation for header-driven cost overrides (Helicone#5172).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@lollinng is attempting to deploy a commit to the Helicone Team on Vercel. A member of the Team first needs to authorize it. |
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.
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.
Ticket
Closes #5172
Component(s)
@helicone-package/cost)Type of change
What this does
#5172 asks for per-request cost overrides via headers (
Helicone-Input-Token-Cost/Helicone-Output-Token-Cost), because OpenRouter costs vary by the underlying provider and the registry's single rate is wrong for those requests.This adds the cost-engine foundation that feature needs: an optional
costOverrideoncalculateModelCostBreakdownandmodelCostBreakdownFromRegistry:??so an explicit0is honored as a free rate rather than treated as unsetUnit is per-token USD, matching
ModelPricingin the registry, so the value multiplies token counts directly with no conversion.How it was tested
jest __tests__/cost/modelCostFromRegistry.test.tspasses (22 tests), including 4 new cases: both-field override, per-field partial override with registry fallback, the zero-override-is-free case (guards the??vs||choice), and the no-override registry path.Proposed wiring (follow-up; I'd like your input first)
To make the headers take effect end to end, the override needs threading from the request into both cost paths:
worker/src/lib/models/HeliconeHeaders.ts(reject negative / non-numeric -> ignore)ProxyForwarder.ts, and stash it intoheliconeMetaso the authoritative async cost calc in jawn (ResponseBodyHandler.ts) honors it tooI scoped this PR to the cost engine because two points are unspecified in the issue and worth your call before I wire the proxy and jawn paths:
calculateModelCostBreakdownreturnsnullwhen the registry has no config for a model, so an override alone won't price a model that isn't in the registry. If OpenRouter pass-through models with no registry entry are in scope, that needs an explicit branchHappy to follow up with the worker + jawn wiring and the header doc once you confirm the units and the unknown-model behavior.