@@ -34,6 +34,8 @@ import {
3434 ApiProviderError ,
3535 inferBedrockInvokeTargetKind ,
3636 parseBedrockBaseModelId ,
37+ resolveBedrockInvokeTargetId ,
38+ resolveBedrockMaxOutputTokensOverride ,
3739 resolveBedrockModelInfo ,
3840 shouldUseBedrock1MContext ,
3941 stripBedrock1MContextSuffix ,
@@ -379,7 +381,9 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
379381 // parseBaseModelId strips cross-region inference prefixes (e.g. `us.`, `eu.`) and the
380382 // synthetic `:1m` dropdown suffix.
381383 const baseModelId = this . parseBaseModelId ( modelConfig . id )
382- const requiresAdaptiveThinking = BEDROCK_ADAPTIVE_THINKING_MODEL_IDS . includes ( baseModelId as any )
384+ const requiresAdaptiveThinking = BEDROCK_ADAPTIVE_THINKING_MODEL_IDS . includes (
385+ baseModelId as ( typeof BEDROCK_ADAPTIVE_THINKING_MODEL_IDS ) [ number ] ,
386+ )
383387
384388 // Determine if thinking should be enabled
385389 // metadata?.thinking?.enabled: Explicitly enabled through API metadata (direct request)
@@ -443,7 +447,7 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
443447 const configuredTargetForIndicator =
444448 this . options . awsBedrockInvokeTarget || this . options . awsCustomArn || modelConfig . id
445449 const is1MContextEnabled =
446- BEDROCK_1M_CONTEXT_MODEL_IDS . includes ( baseModelId as any ) &&
450+ BEDROCK_1M_CONTEXT_MODEL_IDS . includes ( baseModelId as ( typeof BEDROCK_1M_CONTEXT_MODEL_IDS ) [ number ] ) &&
447451 shouldUseBedrock1MContext ( {
448452 targetId : configuredTargetForIndicator ,
449453 baseModelId,
@@ -456,11 +460,14 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
456460 // the fine-grained-tool-streaming beta, so we must omit anthropic_beta entirely
457461 // for those models. Older Claudes silently accept (and effectively ignore) them,
458462 // so we keep the current behavior for them.
459- const skipAnthropicBetaFlags = BEDROCK_NATIVE_1M_CONTEXT_MODEL_IDS . includes ( baseModelId as any )
463+ const skipAnthropicBetaFlags = BEDROCK_NATIVE_1M_CONTEXT_MODEL_IDS . includes (
464+ baseModelId as ( typeof BEDROCK_NATIVE_1M_CONTEXT_MODEL_IDS ) [ number ] ,
465+ )
460466
461467 // Determine if service tier should be applied (checked later when building payload)
462468 const useServiceTier =
463- this . options . awsBedrockServiceTier && BEDROCK_SERVICE_TIER_MODEL_IDS . includes ( baseModelId as any )
469+ this . options . awsBedrockServiceTier &&
470+ BEDROCK_SERVICE_TIER_MODEL_IDS . includes ( baseModelId as ( typeof BEDROCK_SERVICE_TIER_MODEL_IDS ) [ number ] )
464471 if ( useServiceTier ) {
465472 logger . info ( "Service tier specified for Bedrock request" , {
466473 ctx : "bedrock" ,
@@ -1133,6 +1140,14 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
11331140 return parseBedrockBaseModelId ( modelId )
11341141 }
11351142
1143+ private getScopedMaxOutputTokensOverride ( ) : number | undefined {
1144+ return resolveBedrockMaxOutputTokensOverride ( {
1145+ currentTargetId : resolveBedrockInvokeTargetId ( this . options ) ,
1146+ overrideTargetId : this . options . awsModelMaxOutputTokensTargetId ,
1147+ maxOutputTokensOverride : this . options . awsModelMaxOutputTokens ,
1148+ } )
1149+ }
1150+
11361151 //Prompt Router responses come back in a different sequence and the model used is in the response and must be fetched by name
11371152 getModelById ( modelId : string , modelType ?: string ) : { id : BedrockModelId | string ; info : ModelInfo } {
11381153 let model
@@ -1143,8 +1158,8 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
11431158 modelMaxTokens : this . options . modelMaxTokens ,
11441159 contextWindowOverride : this . options . awsModelContextWindow ,
11451160 // Empirically detected per-config max output tokens (from the "Detect" probe in the
1146- // settings UI) widens the static cap so downstream request builders pick it up too .
1147- maxOutputTokensOverride : this . options . awsModelMaxOutputTokens ,
1161+ // settings UI) widens the static cap only for the exact AWS target that was probed .
1162+ maxOutputTokensOverride : this . getScopedMaxOutputTokensOverride ( ) ,
11481163 } )
11491164
11501165 if ( resolved . baseModelId in bedrockModels ) {
@@ -1227,7 +1242,9 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
12271242 const baseIdForGlobal = this . parseBaseModelId ( modelConfig . id )
12281243 if (
12291244 this . options . awsUseGlobalInference &&
1230- BEDROCK_GLOBAL_INFERENCE_MODEL_IDS . includes ( baseIdForGlobal as any )
1245+ BEDROCK_GLOBAL_INFERENCE_MODEL_IDS . includes (
1246+ baseIdForGlobal as ( typeof BEDROCK_GLOBAL_INFERENCE_MODEL_IDS ) [ number ] ,
1247+ )
12311248 ) {
12321249 modelConfig . id = `global.${ baseIdForGlobal } `
12331250 }
@@ -1244,7 +1261,10 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
12441261 // Check if 1M context is enabled for supported Claude 4 models
12451262 // Use parseBaseModelId to handle cross-region inference prefixes
12461263 const baseModelId = this . parseBaseModelId ( modelConfig . id )
1247- if ( BEDROCK_1M_CONTEXT_MODEL_IDS . includes ( baseModelId as any ) && this . options . awsBedrock1MContext ) {
1264+ if (
1265+ BEDROCK_1M_CONTEXT_MODEL_IDS . includes ( baseModelId as ( typeof BEDROCK_1M_CONTEXT_MODEL_IDS ) [ number ] ) &&
1266+ this . options . awsBedrock1MContext
1267+ ) {
12481268 // Update context window and pricing to 1M tier when 1M context beta is enabled
12491269 const tier = modelConfig . info . tiers ?. [ 0 ]
12501270 modelConfig . info = {
@@ -1268,7 +1288,12 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
12681288
12691289 // Apply service tier pricing if specified and model supports it
12701290 const baseModelIdForTier = this . parseBaseModelId ( modelConfig . id )
1271- if ( this . options . awsBedrockServiceTier && BEDROCK_SERVICE_TIER_MODEL_IDS . includes ( baseModelIdForTier as any ) ) {
1291+ if (
1292+ this . options . awsBedrockServiceTier &&
1293+ BEDROCK_SERVICE_TIER_MODEL_IDS . includes (
1294+ baseModelIdForTier as ( typeof BEDROCK_SERVICE_TIER_MODEL_IDS ) [ number ] ,
1295+ )
1296+ ) {
12721297 const pricingMultiplier = BEDROCK_SERVICE_TIER_PRICING [ this . options . awsBedrockServiceTier ]
12731298 if ( pricingMultiplier && pricingMultiplier !== 1.0 ) {
12741299 // Apply pricing multiplier to all price fields
0 commit comments