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: collapse image_url blocks whose payload lacks a url instead of forwarding them
Yucheng Zhuc3c9903ba522
diff --git a/litellm/llms/deepseek/chat/transformation.py b/litellm/llms/deepseek/chat/transformation.pyindex e167819a65c..ea19a7c7ddf 100644--- a/litellm/llms/deepseek/chat/transformation.py+++ b/litellm/llms/deepseek/chat/transformation.py@@ -179,11 +179,21 @@ class DeepSeekChatConfig(OpenAIGPTConfig):return Falseblock_type: Final = block.get("type")if block_type == "image_url":- return block.get("image_url") is not None+ return DeepSeekChatConfig._is_image_url_payload(block.get("image_url"))if block_type == "text":return isinstance(block.get("text"), str)return False+ @staticmethod+ def _is_image_url_payload(payload: object) -> bool:+ """A url string or an object carrying one, per the OpenAI image_url shape."""+ if isinstance(payload, str):+ return bool(payload)+ if not isinstance(payload, Mapping):+ return False+ url: Final = payload.get("url")+ return isinstance(url, str) and bool(url)+def _with_search_results_text_block(self, message: AllMessageValues, content: Sequence[object]) -> AllMessageValues:"""Appends the message's search_results text as a trailing text block,diff --git a/tests/test_litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py b/tests/test_litellm/llms/deepseek/chat/test_deepseek_chat_transformation.pyindex ba6ee4d6663..3f93264d0d0 100644--- a/tests/test_litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py+++ b/tests/test_litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py@@ -267,6 +267,36 @@ class TestDeepSeekVisionMultimodalContent:assert result[0]["content"] == "hi"+ def test_image_block_empty_payload_object_collapses(self):+ for payload in ({}, {"url": ""}, {"detail": "auto"}, None, 42):+ messages = [+ {+ "role": "user",+ "content": [{"type": "text", "text": "hi"}, {"type": "image_url", "image_url": payload}],+ }+ ]++ result = self.config._transform_messages(messages, model=self.VISION_MODEL)++ assert result[0]["content"] == "hi"++ def test_image_block_string_payload_forwarded(self):+ messages = [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "what is this?"},+ {"type": "image_url", "image_url": "https://example.com/image.jpg"},+ ],+ }+ ]++ result = self.config._transform_messages(messages, model=self.VISION_MODEL)++ content = result[0]["content"]+ assert isinstance(content, list)+ assert content[1]["image_url"] == {"url": "https://example.com/image.jpg"}+def test_text_block_missing_text_field_collapses(self):messages = [{