From 0eb7d975a17fa62ff73a0b1abd9de608b78b049e Mon Sep 17 00:00:00 2001 From: Xingjian Li <43537913+OlivverX@users.noreply.github.com> Date: Tue, 16 Dec 2025 11:33:40 +0800 Subject: [PATCH] fix: Support signed URLs with query parameters for Vertex AI Gemini (#17976) - Fix _get_image_mime_type_from_url() to parse path without query params - Resolves issues with Tencent Cloud COS and other signed URLs --- .../litellm_core_utils/prompt_templates/common_utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/litellm/litellm_core_utils/prompt_templates/common_utils.py b/litellm/litellm_core_utils/prompt_templates/common_utils.py index d2c91f4a841..ca2a092dbc8 100644 --- a/litellm/litellm_core_utils/prompt_templates/common_utils.py +++ b/litellm/litellm_core_utils/prompt_templates/common_utils.py @@ -689,7 +689,14 @@ def _get_image_mime_type_from_url(url: str) -> Optional[str]: video/mpegps video/flv """ + from urllib.parse import urlparse + url = url.lower() + + # Parse URL to extract path without query parameters + # This handles URLs like: https://example.com/image.jpg?signature=... + parsed = urlparse(url) + path = parsed.path # Map file extensions to mime types mime_types = { @@ -717,7 +724,7 @@ def _get_image_mime_type_from_url(url: str) -> Optional[str]: # Check each extension group against the URL for extensions, mime_type in mime_types.items(): - if any(url.endswith(ext) for ext in extensions): + if any(path.endswith(ext) for ext in extensions): return mime_type return None