@@ -314,7 +314,11 @@ async def test_cache_point_adds_cache_control(allow_model_requests: None):
314314 {
315315 'role' : 'user' ,
316316 'content' : [
317- {'text' : 'Some context to cache' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
317+ {
318+ 'text' : 'Some context to cache' ,
319+ 'type' : 'text' ,
320+ 'cache_control' : {'type' : 'ephemeral' , 'ttl' : '5m' },
321+ },
318322 {'text' : 'Now the question' , 'type' : 'text' },
319323 ],
320324 }
@@ -339,8 +343,8 @@ async def test_cache_point_multiple_markers(allow_model_requests: None):
339343
340344 assert content == snapshot (
341345 [
342- {'text' : 'First chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
343- {'text' : 'Second chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' }},
346+ {'text' : 'First chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' , 'ttl' : '5m' }},
347+ {'text' : 'Second chunk' , 'type' : 'text' , 'cache_control' : {'type' : 'ephemeral' , 'ttl' : '5m' }},
344348 {'text' : 'Question' , 'type' : 'text' },
345349 ]
346350 )
@@ -389,7 +393,7 @@ async def test_cache_point_with_image_content(allow_model_requests: None):
389393 {
390394 'source' : {'type' : 'url' , 'url' : 'https://example.com/image.jpg' },
391395 'type' : 'image' ,
392- 'cache_control' : {'type' : 'ephemeral' },
396+ 'cache_control' : {'type' : 'ephemeral' , 'ttl' : '5m' },
393397 },
394398 {'text' : 'What is in this image?' , 'type' : 'text' },
395399 ]
@@ -573,7 +577,9 @@ async def test_anthropic_cache_all_text_message(allow_model_requests: None):
573577 content = messages [0 ]['content' ]
574578 assert isinstance (content , list )
575579 assert len (content ) == 1 # pyright: ignore[reportUnknownArgumentType]
576- assert content [0 ] == snapshot ({'type' : 'text' , 'text' : 'test prompt' , 'cache_control' : {'type' : 'ephemeral' }})
580+ assert content [0 ] == snapshot (
581+ {'type' : 'text' , 'text' : 'test prompt' , 'cache_control' : {'type' : 'ephemeral' , 'ttl' : '5m' }}
582+ )
577583
578584
579585async def test_anthropic_cache_all_with_multiple_messages (allow_model_requests : None ):
@@ -617,7 +623,7 @@ async def test_anthropic_cache_all_with_multiple_messages(allow_model_requests:
617623 # Second user message should have cache_control
618624 last_user_content = messages [2 ]['content' ]
619625 assert isinstance (last_user_content , list )
620- assert last_user_content [0 ]['cache_control' ] == {'type' : 'ephemeral' }
626+ assert last_user_content [0 ]['cache_control' ] == snapshot ( {'type' : 'ephemeral' , 'ttl' : '5m' })
621627
622628
623629async def test_anthropic_cache_all_combined_with_other_cache_settings (allow_model_requests : None ):
@@ -649,17 +655,17 @@ def my_tool(value: str) -> str: # pragma: no cover
649655
650656 # Check tools have cache_control
651657 tools = completion_kwargs ['tools' ]
652- assert tools [0 ]['cache_control' ] == {'type' : 'ephemeral' }
658+ assert tools [0 ]['cache_control' ] == snapshot ( {'type' : 'ephemeral' })
653659
654660 # Check system has cache_control
655661 system = completion_kwargs ['system' ]
656- assert system [0 ]['cache_control' ] == {'type' : 'ephemeral' }
662+ assert system [0 ]['cache_control' ] == snapshot ( {'type' : 'ephemeral' })
657663
658664 # Check last message has cache_control
659665 messages = completion_kwargs ['messages' ]
660666 last_message_content = messages [- 1 ]['content' ]
661667 assert isinstance (last_message_content , list )
662- assert last_message_content [0 ]['cache_control' ] == {'type' : 'ephemeral' }
668+ assert last_message_content [0 ]['cache_control' ] == snapshot ( {'type' : 'ephemeral' , 'ttl' : '5m' })
663669
664670
665671async def test_async_request_text_response (allow_model_requests : None ):
0 commit comments