@@ -351,7 +351,7 @@ const extractLanguageModelKeyValuePairs = async (
351351} ;
352352
353353type AnthropicThinkingConfig = NonNullable < AnthropicProviderOptions [ 'thinking' ] > ;
354- const anthropicThinkingConfigCache = new Map < string , AnthropicThinkingConfig > ( ) ;
354+ const anthropicThinkingConfigCache = new Map < string , AnthropicThinkingConfig | undefined > ( ) ;
355355
356356/**
357357 * Resolves the `thinking` provider option we pass to the
@@ -380,7 +380,10 @@ const tryResolveAnthropicThinkingConfig = async ({
380380 return anthropicThinkingConfigCache . get ( cacheKey ) ;
381381 }
382382
383- const thinkingConfig = await ( async ( ) => {
383+ const {
384+ thinkingConfig,
385+ shouldCache
386+ } = await ( async ( ) : Promise < { thinkingConfig : AnthropicThinkingConfig | undefined , shouldCache : boolean } > => {
384387 try {
385388 // `@ai-sdk/anthropic` expects `baseURL` to include the `/v1` path segment,
386389 // whereas the SDK client appends `/v1` itself — so strip a trailing `/v1`
@@ -407,30 +410,48 @@ const tryResolveAnthropicThinkingConfig = async ({
407410
408411 const thinking = capabilities . thinking ;
409412 if ( thinking . supported === false ) {
410- return undefined ;
413+ return {
414+ thinkingConfig : undefined ,
415+ shouldCache : true
416+ } ;
411417 }
412418
413419 if ( thinking . types . adaptive . supported ) {
414420 return {
415- type : "adaptive" ,
416- display : "summarized" ,
417- } satisfies AnthropicThinkingConfig ;
421+ thinkingConfig : {
422+ type : "adaptive" ,
423+ display : "summarized" ,
424+ } satisfies AnthropicThinkingConfig ,
425+ shouldCache : true ,
426+ } ;
418427 }
419428
420429 if ( thinking . types . enabled . supported ) {
421430 return {
422- type : "enabled" ,
423- budgetTokens : env . ANTHROPIC_THINKING_BUDGET_TOKENS ,
424- } satisfies AnthropicThinkingConfig ;
431+ thinkingConfig : {
432+ type : "enabled" ,
433+ budgetTokens : env . ANTHROPIC_THINKING_BUDGET_TOKENS ,
434+ } satisfies AnthropicThinkingConfig ,
435+ shouldCache : true ,
436+ } ;
425437 }
438+
439+ return {
440+ thinkingConfig : undefined ,
441+ shouldCache : true
442+ } ;
426443 } catch ( error ) {
427444 Sentry . captureException ( error ) ;
428445 logger . warn ( `Failed to fetch Anthropic model capabilities for '${ modelId } '. Omitting the thinking option. ${ error } ` ) ;
446+ return {
447+ thinkingConfig : undefined ,
448+ shouldCache : false
449+ } ;
429450 }
430451 } ) ( ) ;
431452
432453
433- if ( thinkingConfig ) {
454+ if ( shouldCache ) {
434455 anthropicThinkingConfigCache . set ( cacheKey , thinkingConfig ) ;
435456 }
436457
0 commit comments