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>
This commit is contained in:
roomote[bot] 2025-09-19 22:49:42 -04:00 committed by GitHub
parent c1e0cdc3cd
commit c0e2c5ef5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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