@@ -57,6 +57,7 @@ import {
5757 vercelAiGatewayDefaultModelId ,
5858 BEDROCK_1M_CONTEXT_MODEL_IDS ,
5959 deepInfraDefaultModelId ,
60+ getVertexAdjustedModelInfo ,
6061} from "@roo-code/types"
6162
6263import type { ModelRecord , RouterModels } from "@roo/api"
@@ -225,86 +226,13 @@ function getSelectedModel({
225226 return { id, info : undefined }
226227 }
227228
228- // Region-aware, tiered pricing for Vertex Claude Sonnet models
229- // Source: https://cloud.google.com/vertex-ai/generative-ai/pricing
230- //
231- // Rules implemented:
232- // - Sonnet 4 pricing is the same globally in all regions
233- // • Under 200k Input Tokens:
234- // Input: $3, Output: $15, Cache Write: $3.75, Cache Hit: $0.30
235- // • Over 200k Input Tokens ([1m] variants or largeInputTierEnabled):
236- // Input: $6, Output: $22.50, Cache Write: $7.50, Cache Hit: $0.60
237- //
238- // - Sonnet 4.5 has different pricing per region and per input context size
239- // • Global region (all regions except us-east5, europe-west1, asia-southeast1)
240- // - Under 200k Input Tokens:
241- // Input: $3.00, Output: $15.00, Cache Write: $3.75, Cache Hit: $0.30
242- // - Over 200k Input Tokens ([1m] variants or largeInputTierEnabled):
243- // Input: $6.00, Output: $22.50, Cache Write: $7.50, Cache Hit: $0.60
244- // • Regional (us-east5, europe-west1, asia-southeast1)
245- // - Under 200k Input Tokens:
246- // Input: $3.30, Output: $16.50, Cache Write: $4.13, Cache Hit: $0.33
247- // - Over 200k Input Tokens ([1m] variants or largeInputTierEnabled):
248- // Input: $6.60, Output: $24.75, Cache Write: $8.25, Cache Hit: $0.66
249- //
250- // We derive "over 200k" from Roo's explicit [1m] model variants, the selected Vertex region,
251- // or the generic largeInputTierEnabled setting.
252- const region = apiConfiguration . vertexRegion ?? "global"
253- const is1m = id . endsWith ( "[1m]" ) || apiConfiguration . largeInputTierEnabled === true
254- const isSonnet45 = id . startsWith ( "claude-sonnet-4-5@20250929" )
255- const isSonnet4 = id . startsWith ( "claude-sonnet-4@20250514" )
256- const regionalPricingRegions = new Set ( [ "us-east5" , "europe-west1" , "asia-southeast1" ] )
257- const useRegionalPricing = regionalPricingRegions . has ( region )
229+ // Delegate pricing and 1M context adjustments to shared types helper
230+ const info = getVertexAdjustedModelInfo ( id , baseInfo , {
231+ region : apiConfiguration . vertexRegion ?? "global" ,
232+ largeInputTierEnabled : apiConfiguration . largeInputTierEnabled === true ,
233+ } )
258234
259- let adjustedInfo : ModelInfo = baseInfo as ModelInfo
260-
261- if ( isSonnet45 ) {
262- if ( is1m ) {
263- // Over 200k (1M beta)
264- adjustedInfo = {
265- ...baseInfo ,
266- contextWindow : 1_000_000 ,
267- inputPrice : useRegionalPricing ? ( 6.6 as number ) : ( 6.0 as number ) ,
268- outputPrice : useRegionalPricing ? ( 24.75 as number ) : ( 22.5 as number ) ,
269- cacheWritesPrice : useRegionalPricing ? ( 8.25 as number ) : ( 7.5 as number ) ,
270- cacheReadsPrice : useRegionalPricing ? ( 0.66 as number ) : ( 0.6 as number ) ,
271- } as ModelInfo
272- } else {
273- // Under 200k
274- adjustedInfo = {
275- ...baseInfo ,
276- contextWindow : 200_000 ,
277- inputPrice : useRegionalPricing ? ( 3.3 as number ) : ( 3.0 as number ) ,
278- outputPrice : useRegionalPricing ? ( 16.5 as number ) : ( 15.0 as number ) ,
279- cacheWritesPrice : useRegionalPricing ? ( 4.13 as number ) : ( 3.75 as number ) ,
280- cacheReadsPrice : useRegionalPricing ? ( 0.33 as number ) : ( 0.3 as number ) ,
281- } as ModelInfo
282- }
283- } else if ( isSonnet4 ) {
284- if ( is1m ) {
285- // Over 200k (1M beta) - global pricing
286- adjustedInfo = {
287- ...baseInfo ,
288- contextWindow : 1_000_000 ,
289- inputPrice : 6.0 as number ,
290- outputPrice : 22.5 as number ,
291- cacheWritesPrice : 7.5 as number ,
292- cacheReadsPrice : 0.6 as number ,
293- } as ModelInfo
294- } else {
295- // Under 200k - global pricing
296- adjustedInfo = {
297- ...baseInfo ,
298- contextWindow : 200_000 ,
299- inputPrice : 3.0 as number ,
300- outputPrice : 15.0 as number ,
301- cacheWritesPrice : 3.75 as number ,
302- cacheReadsPrice : 0.3 as number ,
303- } as ModelInfo
304- }
305- }
306-
307- return { id, info : adjustedInfo }
235+ return { id, info }
308236 }
309237 case "gemini" : {
310238 const id = apiConfiguration . apiModelId ?? geminiDefaultModelId
0 commit comments