The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(factory.py): don't pass cache control if not set
Krrish Dholakiaad90871ad6bb
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.pyindex 15c8cc275cf..e8d8456ed77 100644--- a/litellm/litellm_core_utils/prompt_templates/factory.py+++ b/litellm/litellm_core_utils/prompt_templates/factory.py@@ -1254,7 +1254,6 @@ def convert_function_to_anthropic_tool_invoke(id=str(uuid.uuid4()),name=_name,input=json.loads(_arguments) if _arguments else {},- cache_control=None,)]return anthropic_tool_invoke@@ -1309,14 +1308,16 @@ def convert_to_anthropic_tool_invoke(_anthropic_tool_use_param = AnthropicMessagesToolUseParam(type="tool_use",- id=get_attribute_or_key(tool, "id"),- name=get_attribute_or_key(get_attribute_or_key(tool, "function"), "name"),+ id=cast(str, get_attribute_or_key(tool, "id")),+ name=cast(+ str,+ get_attribute_or_key(get_attribute_or_key(tool, "function"), "name"),+ ),input=json.loads(get_attribute_or_key(get_attribute_or_key(tool, "function"), "arguments")),- cache_control=None,)_content_element = add_cache_control_to_content(diff --git a/litellm/types/llms/anthropic.py b/litellm/types/llms/anthropic.pyindex 003c0bc62d8..781d3caa9ff 100644--- a/litellm/types/llms/anthropic.py+++ b/litellm/types/llms/anthropic.py@@ -52,7 +52,7 @@ class AnthropicMessagesTextParam(TypedDict, total=False):cache_control: Optional[Union[dict, ChatCompletionCachedContent]]-class AnthropicMessagesToolUseParam(TypedDict):+class AnthropicMessagesToolUseParam(TypedDict, total=False):type: Required[Literal["tool_use"]]id: strname: strdiff --git a/tests/llm_translation/test_prompt_factory.py b/tests/llm_translation/test_prompt_factory.pyindex 5ccc2e3aac2..f994acc3301 100644--- a/tests/llm_translation/test_prompt_factory.py+++ b/tests/llm_translation/test_prompt_factory.py@@ -345,7 +345,7 @@ def test_anthropic_cache_controls_tool_calls_pt():assert translated_messages[1]["role"] == "assistant"for content_item in translated_messages[1]["content"]:if content_item["type"] == "tool_use":- assert content_item["cache_control"] is None+ assert "cache_control" not in content_itemassert content_item["name"] == "get_weather"assert translated_messages[2]["role"] == "user"