Skip to content

Commit c6d8aaf

Browse files
committed
feat: generalize "over 200k" large input tier across providers and apply in selection logic (Vertex, Anthropic, Gemini, Bedrock)
1 parent e32d1bf commit c6d8aaf

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

packages/types/src/provider-settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ const baseProviderSettingsSchema = z.object({
181181

182182
// Model verbosity.
183183
verbosity: verbosityLevelsSchema.optional(),
184+
185+
// Generic large input tier toggle applied across providers that define tiers
186+
// When enabled, Roo will select the highest contextWindow tier (e.g. "over 200k" / "1M") if available.
187+
largeInputTierEnabled: z.boolean().optional(),
184188
})
185189

186190
// Several of the providers share common model config properties.

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ function getSelectedModel({
201201
}
202202

203203
// Apply 1M context for Claude Sonnet 4 / 4.5 when enabled
204-
if (BEDROCK_1M_CONTEXT_MODEL_IDS.includes(id as any) && apiConfiguration.awsBedrock1MContext && baseInfo) {
204+
if (
205+
BEDROCK_1M_CONTEXT_MODEL_IDS.includes(id as any) &&
206+
baseInfo &&
207+
(apiConfiguration.awsBedrock1MContext || apiConfiguration.largeInputTierEnabled)
208+
) {
205209
// Create a new ModelInfo object with updated context window
206210
const info: ModelInfo = {
207211
...baseInfo,
@@ -228,24 +232,25 @@ function getSelectedModel({
228232
// - Sonnet 4 pricing is the same globally in all regions
229233
// • Under 200k Input Tokens:
230234
// Input: $3, Output: $15, Cache Write: $3.75, Cache Hit: $0.30
231-
// • Over 200k Input Tokens ([1m] variants):
235+
// • Over 200k Input Tokens ([1m] variants or largeInputTierEnabled):
232236
// Input: $6, Output: $22.50, Cache Write: $7.50, Cache Hit: $0.60
233237
//
234238
// - Sonnet 4.5 has different pricing per region and per input context size
235239
// • Global region (all regions except us-east5, europe-west1, asia-southeast1)
236240
// - Under 200k Input Tokens:
237241
// Input: $3.00, Output: $15.00, Cache Write: $3.75, Cache Hit: $0.30
238-
// - Over 200k Input Tokens ([1m] variants):
242+
// - Over 200k Input Tokens ([1m] variants or largeInputTierEnabled):
239243
// Input: $6.00, Output: $22.50, Cache Write: $7.50, Cache Hit: $0.60
240244
// • Regional (us-east5, europe-west1, asia-southeast1)
241245
// - Under 200k Input Tokens:
242246
// Input: $3.30, Output: $16.50, Cache Write: $4.13, Cache Hit: $0.33
243-
// - Over 200k Input Tokens ([1m] variants):
247+
// - Over 200k Input Tokens ([1m] variants or largeInputTierEnabled):
244248
// Input: $6.60, Output: $24.75, Cache Write: $8.25, Cache Hit: $0.66
245249
//
246-
// We derive "over 200k" from Roo's explicit [1m] model variants and the selected Vertex region.
250+
// We derive "over 200k" from Roo's explicit [1m] model variants, the selected Vertex region,
251+
// or the generic largeInputTierEnabled setting.
247252
const region = apiConfiguration.vertexRegion ?? "global"
248-
const is1m = id.endsWith("[1m]")
253+
const is1m = id.endsWith("[1m]") || apiConfiguration.largeInputTierEnabled === true
249254
const isSonnet45 = id.startsWith("claude-sonnet-4-5@20250929")
250255
const isSonnet4 = id.startsWith("claude-sonnet-4@20250514")
251256
const regionalPricingRegions = new Set(["us-east5", "europe-west1", "asia-southeast1"])
@@ -258,6 +263,7 @@ function getSelectedModel({
258263
// Over 200k (1M beta)
259264
adjustedInfo = {
260265
...baseInfo,
266+
contextWindow: 1_000_000,
261267
inputPrice: useRegionalPricing ? (6.6 as number) : (6.0 as number),
262268
outputPrice: useRegionalPricing ? (24.75 as number) : (22.5 as number),
263269
cacheWritesPrice: useRegionalPricing ? (8.25 as number) : (7.5 as number),
@@ -267,6 +273,7 @@ function getSelectedModel({
267273
// Under 200k
268274
adjustedInfo = {
269275
...baseInfo,
276+
contextWindow: 200_000,
270277
inputPrice: useRegionalPricing ? (3.3 as number) : (3.0 as number),
271278
outputPrice: useRegionalPricing ? (16.5 as number) : (15.0 as number),
272279
cacheWritesPrice: useRegionalPricing ? (4.13 as number) : (3.75 as number),
@@ -278,6 +285,7 @@ function getSelectedModel({
278285
// Over 200k (1M beta) - global pricing
279286
adjustedInfo = {
280287
...baseInfo,
288+
contextWindow: 1_000_000,
281289
inputPrice: 6.0 as number,
282290
outputPrice: 22.5 as number,
283291
cacheWritesPrice: 7.5 as number,
@@ -287,6 +295,7 @@ function getSelectedModel({
287295
// Under 200k - global pricing
288296
adjustedInfo = {
289297
...baseInfo,
298+
contextWindow: 200_000,
290299
inputPrice: 3.0 as number,
291300
outputPrice: 15.0 as number,
292301
cacheWritesPrice: 3.75 as number,
@@ -299,8 +308,21 @@ function getSelectedModel({
299308
}
300309
case "gemini": {
301310
const id = apiConfiguration.apiModelId ?? geminiDefaultModelId
302-
const info = geminiModels[id as keyof typeof geminiModels]
303-
return { id, info }
311+
const baseInfo = geminiModels[id as keyof typeof geminiModels]
312+
if (baseInfo && apiConfiguration.largeInputTierEnabled && baseInfo.tiers && baseInfo.tiers.length > 0) {
313+
// Select the highest contextWindow tier and apply its pricing overrides
314+
const highTier = baseInfo.tiers.reduce((acc, t) => (t.contextWindow > acc.contextWindow ? t : acc))
315+
const info: ModelInfo = {
316+
...baseInfo,
317+
contextWindow: highTier.contextWindow,
318+
inputPrice: highTier.inputPrice ?? baseInfo.inputPrice,
319+
outputPrice: highTier.outputPrice ?? baseInfo.outputPrice,
320+
cacheWritesPrice: highTier.cacheWritesPrice ?? baseInfo.cacheWritesPrice,
321+
cacheReadsPrice: highTier.cacheReadsPrice ?? baseInfo.cacheReadsPrice,
322+
}
323+
return { id, info }
324+
}
325+
return { id, info: baseInfo }
304326
}
305327
case "deepseek": {
306328
const id = apiConfiguration.apiModelId ?? deepSeekDefaultModelId
@@ -448,7 +470,7 @@ function getSelectedModel({
448470
if (
449471
provider === "anthropic" &&
450472
(id === "claude-sonnet-4-20250514" || id === "claude-sonnet-4-5") &&
451-
apiConfiguration.anthropicBeta1MContext &&
473+
(apiConfiguration.anthropicBeta1MContext || apiConfiguration.largeInputTierEnabled) &&
452474
baseInfo
453475
) {
454476
// Type assertion since we know claude-sonnet-4-20250514 and claude-sonnet-4-5 have tiers

0 commit comments

Comments
 (0)