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.
This commit is contained in:
Guilherme Pires 2026-02-13 10:02:48 -08:00
parent a06113ec82
commit eda628b762

View file

@ -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)}")