Skip to content

Commit f5fe620

Browse files
fix: preserve cache_control on /v1/responses content blocks
_transform_responses_api_content_to_chat_completion_content rebuilt content blocks with only type+text, dropping cache_control. The Anthropic adapter (add_cache_control_to_content) never sees it, so cache is never seeded for /v1/responses. Fix: copy cache_control from the source item when present (mirrors the existing pattern for tools). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0675e94 commit f5fe620

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

litellm/responses/litellm_completion_transformation/transformation.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,14 +1286,15 @@ def _transform_responses_api_content_to_chat_completion_content(
12861286
text_value = item.get("text")
12871287
if text_value is None:
12881288
continue
1289-
content_list.append(
1290-
{
1291-
"type": LiteLLMCompletionResponsesConfig._get_chat_completion_request_content_type(
1292-
item.get("type") or "text"
1293-
),
1294-
"text": text_value,
1295-
}
1296-
)
1289+
content_block: Dict[str, Any] = {
1290+
"type": LiteLLMCompletionResponsesConfig._get_chat_completion_request_content_type(
1291+
item.get("type") or "text"
1292+
),
1293+
"text": text_value,
1294+
}
1295+
if item.get("cache_control"):
1296+
content_block["cache_control"] = item["cache_control"]
1297+
content_list.append(content_block)
12971298
return content_list
12981299
else:
12991300
raise ValueError(f"Invalid content type: {type(content)}")

0 commit comments

Comments
 (0)