From 15a80c31f42917bf012f5e85e9074d52e4d64e73 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 431b5e10c42..5a047a09137 100644 --- a/litellm/integrations/anthropic_cache_control_hook.py +++ b/litellm/integrations/anthropic_cache_control_hook.py @@ -791,7 +791,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 the last item Claude accepts a breakpoint on elif isinstance(message_content, list):