From 74d2d617a050fc1e97fe1a22178db4859c9c23e3 Mon Sep 17 00:00:00 2001 From: lkshrk Date: Sat, 10 Oct 2026 03:46:06 +0200 Subject: [PATCH] fix(anthropic): index message role directly in cache control hook --- litellm/integrations/anthropic_cache_control_hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/integrations/anthropic_cache_control_hook.py b/litellm/integrations/anthropic_cache_control_hook.py index d48975b309b..c0f89cdcfdb 100644 --- a/litellm/integrations/anthropic_cache_control_hook.py +++ b/litellm/integrations/anthropic_cache_control_hook.py @@ -614,7 +614,7 @@ class AnthropicCacheControlHook(CustomPromptManagement): # 1. string content, or a tool message: insert cache control at message level. # Anthropic only accepts cache_control on the tool_result block itself, never # inside tool_result.content; the message-level marker maps onto that block. - if message.get("role") == "tool" or isinstance(message_content, str): + if message["role"] == "tool" or isinstance(message_content, str): message["cache_control"] = control # 2. list of objects - only apply to last item per Anthropic spec elif isinstance(message_content, list):