BerriAI/litellm · error · ValueError

Unable to determine content type from URL

Error message

Unable to determine content type from URL: {url}. Response content-type: {current_content_type}

What it means

When an image's MIME type cannot be inferred from the URL, litellm downloads the image, checks the response content-type header, and sniffs magic bytes for png/jpeg/gif/webp/heic. If none of these fallbacks produces a recognized type, it raises this error naming the URL and the content-type actually received.

Solutions

  1. Use a direct image URL with a recognized extension (.png/.jpg/.webp/.gif) served with an image/* content-type
  2. Pass a data URI with the mime explicit: data:image/png;base64,...
  3. Verify the URL with curl -I and fix signing/auth so it returns the image bytes
  4. Convert the image to PNG or JPEG and host it somewhere that returns correct headers

Example fix

# before: URL returns text/html (error page)
messages = [{"role": "user", "content": [{"type": "image_url", "image_url": {"url": "https://cdn.example.com/expired-signed-pic"}}]}]

# after: inline data URI with explicit mime
import base64
data = base64.b64encode(open("pic.png", "rb").read()).decode()
messages = [{"role": "user", "content": [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{data}"}}]}]
Defensive patterns

Strategy: validation

Validate before calling

import httpx

SUPPORTED = ("image/png", "image/jpeg", "image/gif", "image/webp", "image/heic")

def url_has_image_content_type(url: str, timeout: float = 10.0) -> bool:
    try:
        r = httpx.head(url, follow_redirects=True, timeout=timeout)
        ct = r.headers.get("content-type", "")
        return ct.split(";")[0].strip().lower() in SUPPORTED or ct.startswith("image/")
    except httpx.HTTPError:
        return False

# before the call: skip/replace URLs that fail the check
# for block in content:
#     if block.get("type") == "image_url" and not url_has_image_content_type(block["image_url"]["url"]): convert to data URI

Try / catch

try:
    litellm.completion(model=model, messages=messages)
except ValueError as e:
    if "Unable to determine content type from URL" in str(e):
        # re-encode the image as an explicit data URI and retry once
        messages = inline_image_as_data_uri(messages)
    else:
        raise

Prevention

When it happens

Trigger: Passing an image URL whose server returns a non-image content-type (text/html error page, application/xml from S3), a signed URL that has expired and returns an error document, or an image format outside the sniffed set such as SVG, AVIF, or TIFF.

Common situations: Expired or mis-signed S3/CDN URLs returning XML errors; corporate proxies serving HTML interstitials; using SVG or next-gen formats; typos in URLs leading to 404 HTML pages.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/f204737776107278. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/prompt_templates/common_utils.py:1233

        if inferred_type:
            return inferred_type

    # Try to detect from binary content signature (magic bytes)
    if content:
        detected_type: Final = get_image_type(content[:100])
        if detected_type:
            type_to_mime: Final = {
                "png": "image/png",
                "jpeg": "image/jpeg",
                "gif": "image/gif",
                "webp": "image/webp",
                "heic": "image/heic",
            }
            if detected_type in type_to_mime:
                return type_to_mime[detected_type]

    # If all fallbacks failed, raise error
    raise ValueError(f"Unable to determine content type from URL: {url}. Response content-type: {current_content_type}")


def get_tool_call_names(tools: list[ChatCompletionToolParam]) -> list[str]:
    """
    Get tool call names from tools
    """
    tool_call_names: Final[list[str]] = []
    for tool in tools:
        if tool.get("type") == "function":
            tool_call_name = tool.get("function", {}).get("name")
            if tool_call_name:
                tool_call_names.append(tool_call_name)
    return tool_call_names


def is_function_call(optional_params: dict) -> bool:
    """
    Checks if the optional params contain the function call

View on GitHub (pinned to 77b7c6c40c)