BerriAI/litellm · error · ValueError
URL does not point to a valid image
Error message
URL does not point to a valid image (content-type: {content_type}) What it means
Inside _load_image_from_url: the URL was fetched successfully but the response's content-type header is missing or does not contain 'image', so litellm refuses to hand the bytes to PIL. This guards against parsing HTML error pages or XML auth errors as images.
Solutions
- Verify with curl -I <url> that the response content-type is image/*
- Fix URL signing/auth so the image bytes are returned directly
- Re-host the image somewhere serving correct image/* headers
- Download the image yourself and pass base64 data instead of the URL
Example fix
# before: URL serves text/html
image = _load_image_from_url("https://example.com/pic?token=expired")
# after: fetch bytes yourself and pass base64 / data URI
import base64, httpx
data = httpx.get("https://example.com/pic", headers={"Authorization": "Bearer ..."}).content
b64 = base64.b64encode(data).decode() Defensive patterns
Strategy: validation
Validate before calling
import httpx
def url_serves_image(url: str, timeout: float = 10.0) -> bool:
try:
r = httpx.get(url, follow_redirects=True, timeout=timeout, headers={"Range": "bytes=0-0"})
ct = r.headers.get("content-type", "")
return "image" in ct
except httpx.HTTPError:
return False
# guard each image URL before the LLM call; re-encode or reject failures Try / catch
try:
litellm.completion(model=model, messages=messages)
except ValueError as e:
if "URL does not point to a valid image" in str(e):
# fetch bytes yourself with proper auth and inline as base64
messages = inline_image_bytes(messages)
else:
raise Prevention
- curl -I image URLs in integration tests to confirm image/* content-types
- Keep signed URLs fresh; refresh before they expire
- Pass base64 data for images behind auth walls instead of relying on litellm's fetch
When it happens
Trigger: An image URL whose server responds 200 with text/html (SPA/redirect page), application/xml (S3 error), or no content-type at all; signed URLs past expiry; endpoints that proxy images through HTML wrappers.
Common situations: Expired presigned S3/CDN links; auth walls in front of image hosts; misconfigured static servers omitting content-type headers.
Related errors
- Unable to determine content type from URL
- Unsupported image format
- Amazon Nova Canvas requires a text prompt. Pass a non-empty…
- audience must be provided unless…
- BFL error
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/a032222eab9d3e3c.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/prompt_templates/factory.py:3190
def _load_image_from_url(image_url):
try:
from PIL import Image
except Exception:
raise Exception("image conversion failed please run `pip install Pillow`")
from io import BytesIO
try:
# Send a GET request to the image URL
client: Final = HTTPHandler(concurrent_limit=1)
response: Final[httpx.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
content_type: Final = response.headers.get("content-type")
if not content_type or "image" not in content_type:
raise ValueError(f"URL does not point to a valid image (content-type: {content_type})")
# Load the image from the response content
return Image.open(BytesIO(response.content))
except Exception as e:
raise e
def _gemini_vision_convert_messages(messages: list):
"""
Converts given messages for GPT-4 Vision to Gemini format.
Args:
messages (list): The messages to convert. Each message can be a dictionary with a "content" key. The content can be a string or a list of elements. If it is a string, it will be concatenated to the prompt. If it is a list, each element will be processed based on its type:
- If the element is a dictionary with a "type" key equal to "text", its "text" value will be concatenated to the prompt.
- If the element is a dictionary with a "type" key equal to "image_url", its "image_url" value will be added to the list of images.
Returns:View on GitHub (pinned to 77b7c6c40c)