mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
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:
parent
a06113ec82
commit
eda628b762
1 changed files with 12 additions and 8 deletions
|
|
@ -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)}")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue