fix: strip models/ prefix from Google Gemini model names for correct cost calculation#5592
Open
ink-the-squid wants to merge 1 commit intoHelicone:mainfrom
Open
fix: strip models/ prefix from Google Gemini model names for correct cost calculation#5592ink-the-squid wants to merge 1 commit intoHelicone:mainfrom
ink-the-squid wants to merge 1 commit intoHelicone:mainfrom
Conversation
|
@ink-the-squid 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.
Problem
Google's Gemini API returns model names with a
models/prefix in the request body (e.g.,models/gemini-3-pro-preview). The new cost registry performs exact match lookups expecting bare model names likegemini-3-pro-preview, so these lookups fail.When the registry lookup fails, cost calculation falls back to the legacy pricing system, which lacks
prompt_cache_write_tokenpricing. This causes cache write tokens to be incorrectly charged at the standard input token rate ($2/1M) instead of using the registry'scacheMultipliers.Fix
Strip the
models/prefix from Google model names in three locations:modelMapper.ts→getModelFromRequest()— normalizes the model name extracted from the request bodymodelMapper.ts→getModelFromResponse()— normalizes the model name extracted from the response (includingmodelVersion)ResponseBodyHandler.ts— normalizesproviderModelIdbefore passing tomodelCostBreakdownFromRegistry()This ensures the cost registry always receives clean model names for lookup, enabling correct cache token pricing via the new registry system.
Context
Reported by a customer experiencing incorrect cache pricing for Google Gemini models. Cache write tokens were being charged at the input rate instead of at the correct cache write rate defined in the cost registry.