From 994e35135dc53badf26455e12d04d87981bc3561 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Thu, 23 Apr 2026 11:20:20 -0700 Subject: [PATCH] fix: correct image size limit enforcement and vertex_location None passthrough MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit token_counter.py: the previous size-limit raises were inside except Exception: pass, so they were silently swallowed. The post-read raise was worse — img_data was already assigned the full body before the raise, so the oversized value was used downstream. Restructured to only assign img_data when the body is within bounds. vertex_ai/common_utils.py and llm_passthrough_endpoints.py: the is-not-None guard skipped validation for None, falling through to produce "https://None-aiplatform..." Added explicit None check that raises before the regex guard. --- litellm/litellm_core_utils/token_counter.py | 9 +++++---- litellm/llms/vertex_ai/common_utils.py | 6 +++--- .../pass_through_endpoints/llm_passthrough_endpoints.py | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.py index d893b980789..e6a68de07e9 100644 --- a/litellm/litellm_core_utils/token_counter.py +++ b/litellm/litellm_core_utils/token_counter.py @@ -219,10 +219,11 @@ def get_image_dimensions( max_bytes = int(MAX_IMAGE_URL_DOWNLOAD_SIZE_MB * 1024 * 1024) content_length = response.headers.get("Content-Length") if content_length is not None and int(content_length) > max_bytes: - raise ValueError("Image response exceeds size limit") - img_data = response.read() - if len(img_data) > max_bytes: - raise ValueError("Image response exceeds size limit") + pass # skip download; img_data stays None + else: + body = response.read() + if len(body) <= max_bytes: + img_data = body except Exception: pass if img_data is None: diff --git a/litellm/llms/vertex_ai/common_utils.py b/litellm/llms/vertex_ai/common_utils.py index c13f6a86f83..fb8fd903409 100644 --- a/litellm/llms/vertex_ai/common_utils.py +++ b/litellm/llms/vertex_ai/common_utils.py @@ -232,9 +232,9 @@ def get_vertex_base_url( """ if vertex_location == "global": return "https://aiplatform.googleapis.com" - if vertex_location is not None and not re.match( - r"^[a-z][a-z0-9-]*$", vertex_location - ): + if vertex_location is None: + raise ValueError("vertex_location is required") + if not re.match(r"^[a-z][a-z0-9-]*$", vertex_location): raise ValueError("Invalid vertex_location format") return f"https://{vertex_location}-aiplatform.googleapis.com" diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py index 3cf155739ca..8a86b98fee2 100644 --- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py @@ -1501,9 +1501,9 @@ def get_vertex_base_url(vertex_location: Optional[str]) -> str: """ if vertex_location == "global": return "https://aiplatform.googleapis.com/" - if vertex_location is not None and not re.match( - r"^[a-z][a-z0-9-]*$", vertex_location - ): + if vertex_location is None: + raise ValueError("vertex_location is required") + if not re.match(r"^[a-z][a-z0-9-]*$", vertex_location): raise ValueError("Invalid vertex_location format") return f"https://{vertex_location}-aiplatform.googleapis.com/"