From 77aa69cb2b6f9ac7d3346bea90bab4ef4175ac00 Mon Sep 17 00:00:00 2001 From: TobiMayr Date: Thu, 9 Jul 2026 16:40:32 +0200 Subject: [PATCH] style(responses): extract cache_control into a named variable, trim comment Per style review: the message-building branch read cache_control 3 different ways in 5 lines (.get() twice, then [] indexing once), unlike the sibling tool-call-output/function-call functions this PR touches, which each extract it into a named variable up front (output_cache_control, function_call_cache_control). Matched that convention here too. Also trimmed the 3-line inline comment to one line, matching the file's usual comment length for similarly subtle behavior. --- .../transformation.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index 70a4bd12ca7..65cd1e6d7c6 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -1427,15 +1427,14 @@ class LiteLLMCompletionResponsesConfig: content ), ) - if input_item.get("cache_control"): - msg["cache_control"] = input_item.get("cache_control") - # Also propagate to the last content element for providers - # that read cache_control from content blocks (Anthropic, Bedrock), - # unless that block already carries its own cache_control. + input_item_cache_control = input_item.get("cache_control") + if input_item_cache_control: + msg["cache_control"] = input_item_cache_control + # Also set on the last content block for providers (Anthropic, Bedrock) that read cache_control there. if isinstance(msg["content"], list) and len(msg["content"]) > 0: last_element = msg["content"][-1] if isinstance(last_element, dict) and "cache_control" not in last_element: - last_element["cache_control"] = input_item["cache_control"] + last_element["cache_control"] = input_item_cache_control return [msg] @staticmethod