From c0e2c5ef5bda6d7d01bda6c2ad137a91cee53ea3 Mon Sep 17 00:00:00 2001 From: "roomote[bot]" <219738659+roomote[bot]@users.noreply.github.com> Date: Fri, 19 Sep 2025 22:49:42 -0400 Subject: [PATCH] fix: apply tiered pricing for Gemini models via Vertex AI (#8018) * fix: apply tiered pricing for Gemini models via Vertex AI - Modified calculateCost method to handle models where cacheReadsPrice is only defined in tiers - Added comprehensive tests for Vertex AI tiered pricing calculation - Fixes issue where local cost calculation always showed highest tier rates Fixes #8017 * Delete src/api/providers/__tests__/vertex-tiered-pricing.spec.ts --------- Co-authored-by: Roo Code Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com> --- src/api/providers/gemini.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/api/providers/gemini.ts b/src/api/providers/gemini.ts index 775d763a05..573adda879 100644 --- a/src/api/providers/gemini.ts +++ b/src/api/providers/gemini.ts @@ -286,10 +286,7 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl outputTokens: number cacheReadTokens?: number }) { - if (!info.inputPrice || !info.outputPrice || !info.cacheReadsPrice) { - return undefined - } - + // For models with tiered pricing, prices might only be defined in tiers let inputPrice = info.inputPrice let outputPrice = info.outputPrice let cacheReadsPrice = info.cacheReadsPrice @@ -306,6 +303,16 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl } } + // Check if we have the required prices after considering tiers + if (!inputPrice || !outputPrice) { + return undefined + } + + // cacheReadsPrice is optional - if not defined, treat as 0 + if (!cacheReadsPrice) { + cacheReadsPrice = 0 + } + // Subtract the cached input tokens from the total input tokens. const uncachedInputTokens = inputTokens - cacheReadTokens