From eda628b7620cde488d1220b8f49364132201faa8 Mon Sep 17 00:00:00 2001 From: Guilherme Pires Date: Fri, 13 Feb 2026 10:02:48 -0800 Subject: [PATCH] Preserve cache_control in Responses API content transformation When transforming Responses API input items to Chat Completion messages, the content block builder was only copying 'type' and 'text' from text items, dropping 'cache_control'. This prevented Anthropic prompt caching from working through the Responses API (aresponses), since the cache_control directive never reached the Anthropic request. Fix: check for cache_control on each text content item and preserve it in the transformed Chat Completion content block. --- .../transformation.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index 08e31c59662..b272fb92891 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -1189,14 +1189,18 @@ class LiteLLMCompletionResponsesConfig: text_value = item.get("text") if text_value is None: continue - content_list.append( - { - "type": LiteLLMCompletionResponsesConfig._get_chat_completion_request_content_type( - item.get("type") or "text" - ), - "text": text_value, - } - ) + text_block: Dict[str, Any] = { + "type": LiteLLMCompletionResponsesConfig._get_chat_completion_request_content_type( + item.get("type") or "text" + ), + "text": text_value, + } + # Preserve cache_control for providers that + # support prompt caching (e.g. Anthropic). + cache_control = item.get("cache_control") + if cache_control is not None: + text_block["cache_control"] = cache_control + content_list.append(text_block) return content_list else: raise ValueError(f"Invalid content type: {type(content)}")