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: align image URL fetch with validated client in bedrock and token counter paths
Yuneng Jiang699b820c22d0
diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.pyindex bf950357bac..5a19c224aa4 100644--- a/litellm/litellm_core_utils/prompt_templates/factory.py+++ b/litellm/litellm_core_utils/prompt_templates/factory.py@@ -15,6 +15,7 @@ import litellm.typesimport litellm.types.llmsfrom litellm import verbose_loggerfrom litellm._uuid import uuid+from litellm.litellm_core_utils.url_utils import async_safe_get, safe_getfrom litellm.llms.custom_httpx.http_handler import HTTPHandler, get_async_httpx_clientfrom litellm.types.files import get_file_extension_from_mime_typefrom litellm.types.llms.anthropic import *@@ -3324,7 +3325,7 @@ def _load_image_from_url(image_url):try:# Send a GET request to the image URLclient = HTTPHandler(concurrent_limit=1)- response = client.get(image_url)+ response = safe_get(client, image_url)response.raise_for_status() # Raise an exception for HTTP errors# Check the response's content type to ensure it is an image@@ -3562,7 +3563,7 @@ class BedrockImageProcessor:params={"concurrent_limit": 1},)# Send a GET request to the image URL- response = await client.get(image_url, follow_redirects=True)+ response = await async_safe_get(client, image_url)response.raise_for_status() # Raise an exception for HTTP errorsreturn BedrockImageProcessor._post_call_image_processing(@@ -3577,7 +3578,7 @@ class BedrockImageProcessor:try:client = HTTPHandler(concurrent_limit=1)# Send a GET request to the image URL- response = client.get(image_url, follow_redirects=True)+ response = safe_get(client, image_url)response.raise_for_status() # Raise an exception for HTTP errorsreturn BedrockImageProcessor._post_call_image_processing(diff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.pyindex 01e5dc39a34..d893b980789 100644--- a/litellm/litellm_core_utils/token_counter.py+++ b/litellm/litellm_core_utils/token_counter.py@@ -23,6 +23,7 @@ from litellm.constants import (DEFAULT_IMAGE_HEIGHT,DEFAULT_IMAGE_TOKEN_COUNT,DEFAULT_IMAGE_WIDTH,+ MAX_IMAGE_URL_DOWNLOAD_SIZE_MB,MAX_LONG_SIDE_FOR_IMAGE_HIGH_RES,MAX_SHORT_SIDE_FOR_IMAGE_HIGH_RES,MAX_TILE_HEIGHT,@@ -215,7 +216,13 @@ def get_image_dimensions(try:client = _get_httpx_client()response = safe_get(client, data)+ 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")except Exception:passif img_data is None: