Skip to content

Commit c0e2c5e

Browse files
roomote-v0[bot]roomotedaniel-lxs
authored
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 <roomote@roocode.com> Co-authored-by: Daniel <57051444+daniel-lxs@users.noreply.github.com>
1 parent c1e0cdc commit c0e2c5e

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/api/providers/gemini.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,7 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
286286
outputTokens: number
287287
cacheReadTokens?: number
288288
}) {
289-
if (!info.inputPrice || !info.outputPrice || !info.cacheReadsPrice) {
290-
return undefined
291-
}
292-
289+
// For models with tiered pricing, prices might only be defined in tiers
293290
let inputPrice = info.inputPrice
294291
let outputPrice = info.outputPrice
295292
let cacheReadsPrice = info.cacheReadsPrice
@@ -306,6 +303,16 @@ export class GeminiHandler extends BaseProvider implements SingleCompletionHandl
306303
}
307304
}
308305

306+
// Check if we have the required prices after considering tiers
307+
if (!inputPrice || !outputPrice) {
308+
return undefined
309+
}
310+
311+
// cacheReadsPrice is optional - if not defined, treat as 0
312+
if (!cacheReadsPrice) {
313+
cacheReadsPrice = 0
314+
}
315+
309316
// Subtract the cached input tokens from the total input tokens.
310317
const uncachedInputTokens = inputTokens - cacheReadTokens
311318

0 commit comments

Comments
 (0)