Skip to content

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
ink-the-squid:fix/strip-google-models-prefix
Open

fix: strip models/ prefix from Google Gemini model names for correct cost calculation#5592
ink-the-squid wants to merge 1 commit intoHelicone:mainfrom
ink-the-squid:fix/strip-google-models-prefix

Conversation

@ink-the-squid
Copy link
Contributor

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 like gemini-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_token pricing. This causes cache write tokens to be incorrectly charged at the standard input token rate ($2/1M) instead of using the registry's cacheMultipliers.

Fix

Strip the models/ prefix from Google model names in three locations:

  1. modelMapper.tsgetModelFromRequest() — normalizes the model name extracted from the request body
  2. modelMapper.tsgetModelFromResponse() — normalizes the model name extracted from the response (including modelVersion)
  3. ResponseBodyHandler.ts — normalizes providerModelId before passing to modelCostBreakdownFromRegistry()

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.

@vercel
Copy link

vercel bot commented Feb 20, 2026

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

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

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.

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.

1 participant