@@ -1531,6 +1531,82 @@ describe("ProviderTransform.message - claude w/bedrock custom inference profile"
15311531} )
15321532
15331533
1534+ describe ( "ProviderTransform.message - first system block gets 1h TTL when flag set" , ( ) => {
1535+ const anthropicModel = {
1536+ id : "anthropic/claude-sonnet-4-6" ,
1537+ providerID : "anthropic" ,
1538+ api : {
1539+ id : "claude-sonnet-4-6" ,
1540+ url : "https://api.anthropic.com" ,
1541+ npm : "@ai-sdk/anthropic" ,
1542+ } ,
1543+ capabilities : {
1544+ temperature : true ,
1545+ reasoning : false ,
1546+ attachment : true ,
1547+ toolcall : true ,
1548+ input : { text : true , audio : false , image : true , video : false , pdf : true } ,
1549+ output : { text : true , audio : false , image : false , video : false , pdf : false } ,
1550+ interleaved : false ,
1551+ } ,
1552+ cost : { input : 0.003 , output : 0.015 , cache : { read : 0.0003 , write : 0.00375 } } ,
1553+ limit : { context : 200000 , output : 8192 } ,
1554+ status : "active" ,
1555+ options : { } ,
1556+ headers : { } ,
1557+ } as any
1558+
1559+ test ( "first system block gets 1h TTL when extendedTTL is true" , ( ) => {
1560+ const msgs = [
1561+ { role : "system" , content : "Block 1" } ,
1562+ { role : "system" , content : "Block 2" } ,
1563+ { role : "user" , content : "Hello" } ,
1564+ ] as any [ ]
1565+
1566+ const result = ProviderTransform . message ( msgs , anthropicModel , { extendedTTL : true } ) as any [ ]
1567+
1568+ expect ( result [ 0 ] . providerOptions . anthropic . cacheControl ) . toEqual ( { type : "ephemeral" , ttl : "1h" } )
1569+ } )
1570+
1571+ test ( "first system block gets default ephemeral when extendedTTL is not set" , ( ) => {
1572+ const msgs = [
1573+ { role : "system" , content : "Block 1" } ,
1574+ { role : "system" , content : "Block 2" } ,
1575+ { role : "user" , content : "Hello" } ,
1576+ ] as any [ ]
1577+
1578+ const result = ProviderTransform . message ( msgs , anthropicModel , { } ) as any [ ]
1579+
1580+ expect ( result [ 0 ] . providerOptions . anthropic . cacheControl ) . toEqual ( { type : "ephemeral" } )
1581+ } )
1582+
1583+ test ( "second system block always gets default ephemeral TTL" , ( ) => {
1584+ const msgs = [
1585+ { role : "system" , content : "Block 1" } ,
1586+ { role : "system" , content : "Block 2" } ,
1587+ { role : "user" , content : "Hello" } ,
1588+ ] as any [ ]
1589+
1590+ const result = ProviderTransform . message ( msgs , anthropicModel , { extendedTTL : true } ) as any [ ]
1591+
1592+ expect ( result [ 1 ] . providerOptions . anthropic . cacheControl ) . toEqual ( { type : "ephemeral" } )
1593+ } )
1594+
1595+ test ( "conversation messages get default ephemeral TTL even with extendedTTL" , ( ) => {
1596+ const msgs = [
1597+ { role : "system" , content : "System" } ,
1598+ { role : "user" , content : "Hello" } ,
1599+ { role : "assistant" , content : "Hi" } ,
1600+ { role : "user" , content : "World" } ,
1601+ ] as any [ ]
1602+
1603+ const result = ProviderTransform . message ( msgs , anthropicModel , { extendedTTL : true } ) as any [ ]
1604+
1605+ const last = result [ result . length - 1 ]
1606+ expect ( last . providerOptions . anthropic . cacheControl ) . toEqual ( { type : "ephemeral" } )
1607+ } )
1608+ } )
1609+
15341610describe ( "ProviderTransform.message - cache control on gateway" , ( ) => {
15351611 const createModel = ( overrides : Partial < any > = { } ) =>
15361612 ( {
0 commit comments