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 Azure-OpenAI Vision API Compliance (#12075)
Davis Featherstone51074ffcae98
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.pyindex e74c1a0eddb..c99c0ae726e 100644--- a/litellm/litellm_core_utils/prompt_templates/factory.py+++ b/litellm/litellm_core_utils/prompt_templates/factory.py@@ -943,6 +943,12 @@ def _azure_tool_call_invoke_helper(return function_call_params+def _azure_image_url_helper(content: ChatCompletionImageObject):+ if isinstance(content["image_url"], str):+ content["image_url"] = {"url": content["image_url"]}+ return++def convert_to_azure_openai_messages(messages: List[AllMessageValues],) -> List[AllMessageValues]:@@ -951,6 +957,11 @@ def convert_to_azure_openai_messages(function_call = m.get("function_call", None)if function_call is not None:m["function_call"] = _azure_tool_call_invoke_helper(function_call)++ if m["role"] == "user" and isinstance(m.get("content"), list):+ for content in m.get("content", []):+ if isinstance(content, dict) and content.get("type") == "image_url":+ _azure_image_url_helper(content) # type: ignorereturn messagesdiff --git a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.pyindex 56ea91aef24..0253f00c7ed 100644--- a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py+++ b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py@@ -83,6 +83,48 @@ async def test_anthropic_bedrock_thinking_blocks_with_none_content():)+def test_convert_to_azure_openai_messages():+ """Test coverting image_url to azure_openai spec"""++ from typing import List+ from litellm.types.llms.openai import AllMessageValues+ from litellm.litellm_core_utils.prompt_templates.factory import convert_to_azure_openai_messages++ input: List[AllMessageValues] = [+ {+ "role": "user",+ "content": [+ {+ "type": "text",+ "text": "What is in this image?"+ },+ {+ "type": "image_url",+ "image_url": "www.mock.com"+ }+ ]+ }+ ]++ expected_content = [+ {+ "type": "text",+ "text": "What is in this image?"+ },+ {+ "type": "image_url",+ "image_url": {"url": "www.mock.com"}+ }+ ]++ output = convert_to_azure_openai_messages(input)++ content = output[0].get('content')+ assert content == expected_content++++def test_bedrock_validate_format_image_or_video():"""Test the _validate_format method for images, videos, and documents"""