@@ -179,15 +179,68 @@ describe("Bedrock thinking effort mapping", () => {
179179 expect ( testing . buildAdditionalModelRequestFields ( model , options ) ) . toBeUndefined ( ) ;
180180 } ) ;
181181
182+ it ( "uses the model maxTokens cap for adaptive Claude thinking requests" , ( ) => {
183+ const model = bedrockModel ( {
184+ id : "us.anthropic.claude-opus-4-8" ,
185+ name : "Claude Opus 4.8" ,
186+ reasoning : true ,
187+ contextWindow : 1_000_000 ,
188+ maxTokens : 128_000 ,
189+ } ) ;
190+ const options = testing . resolveSimpleBedrockOptions ( model , { reasoning : "high" } ) ;
191+
192+ expect ( options . maxTokens ) . toBe ( 128_000 ) ;
193+ expect ( options . reasoning ) . toBe ( "high" ) ;
194+ expect ( testing . buildAdditionalModelRequestFields ( model , options ) ) . toEqual ( {
195+ thinking : { type : "adaptive" , display : "summarized" } ,
196+ output_config : { effort : "high" } ,
197+ } ) ;
198+ } ) ;
199+
200+ it . each ( [ 4096 , 8192 , 16_384 ] ) (
201+ "does not turn fallback maxTokens %s into an adaptive cap" ,
202+ ( maxTokens ) => {
203+ const model = bedrockModel ( {
204+ id : "us.anthropic.claude-opus-4-8" ,
205+ name : "Claude Opus 4.8" ,
206+ reasoning : true ,
207+ maxTokens,
208+ } ) ;
209+ const options = testing . resolveSimpleBedrockOptions ( model , { reasoning : "high" } ) ;
210+
211+ expect ( options . maxTokens ) . toBeUndefined ( ) ;
212+ expect ( options . reasoning ) . toBe ( "high" ) ;
213+ } ,
214+ ) ;
215+
216+ it ( "preserves explicit maxTokens caps for adaptive Claude thinking requests" , ( ) => {
217+ const model = bedrockModel ( {
218+ id : "us.anthropic.claude-opus-4-8" ,
219+ name : "Claude Opus 4.8" ,
220+ reasoning : true ,
221+ contextWindow : 1_000_000 ,
222+ maxTokens : 128_000 ,
223+ } ) ;
224+ const options = testing . resolveSimpleBedrockOptions ( model , {
225+ reasoning : "high" ,
226+ maxTokens : 32_000 ,
227+ } ) ;
228+
229+ expect ( options . maxTokens ) . toBe ( 32_000 ) ;
230+ } ) ;
231+
182232 it ( "forces adaptive thinking for Bedrock Mythos Preview when callers omit reasoning" , ( ) => {
183233 const model = bedrockModel ( {
184234 id : "us.anthropic.claude-mythos-preview" ,
185235 name : "US Claude Mythos Preview" ,
186236 reasoning : true ,
237+ contextWindow : 1_000_000 ,
238+ maxTokens : 128_000 ,
187239 } ) ;
188240 const options = testing . resolveSimpleBedrockOptions ( model , { } ) ;
189241
190242 expect ( options . reasoning ) . toBe ( "high" ) ;
243+ expect ( options . maxTokens ) . toBe ( 128_000 ) ;
191244 expect ( testing . buildAdditionalModelRequestFields ( model , options ) ) . toEqual ( {
192245 thinking : { type : "adaptive" , display : "summarized" } ,
193246 output_config : { effort : "high" } ,
@@ -281,6 +334,15 @@ describe("Bedrock Fable contract", () => {
281334 } as never ;
282335 }
283336
337+ it ( "uses the model maxTokens cap for simple Fable options" , ( ) => {
338+ const options = testing . resolveSimpleBedrockOptions ( fableModel ( ) , { } ) ;
339+
340+ expect ( options ) . toMatchObject ( {
341+ maxTokens : 128_000 ,
342+ reasoning : "high" ,
343+ } ) ;
344+ } ) ;
345+
284346 it ( "sends always-adaptive high effort without unsupported request controls" , async ( ) => {
285347 const send = vi . spyOn ( BedrockRuntimeClient . prototype , "send" ) . mockResolvedValue ( {
286348 $metadata : { httpStatusCode : 200 } ,
0 commit comments