{"record":{"id":"f204737776107278","repo":"BerriAI/litellm","slug":"unable-to-determine-content-type-from-url-url","errorCode":null,"errorMessage":"Unable to determine content type from URL: {url}. Response content-type: {current_content_type}","messagePattern":"Unable to determine content type from URL: (.+?)\\. Response content-type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/common_utils.py","lineNumber":1233,"sourceCode":"        if inferred_type:\n            return inferred_type\n\n    # Try to detect from binary content signature (magic bytes)\n    if content:\n        detected_type: Final = get_image_type(content[:100])\n        if detected_type:\n            type_to_mime: Final = {\n                \"png\": \"image/png\",\n                \"jpeg\": \"image/jpeg\",\n                \"gif\": \"image/gif\",\n                \"webp\": \"image/webp\",\n                \"heic\": \"image/heic\",\n            }\n            if detected_type in type_to_mime:\n                return type_to_mime[detected_type]\n\n    # If all fallbacks failed, raise error\n    raise ValueError(f\"Unable to determine content type from URL: {url}. Response content-type: {current_content_type}\")\n\n\ndef get_tool_call_names(tools: list[ChatCompletionToolParam]) -> list[str]:\n    \"\"\"\n    Get tool call names from tools\n    \"\"\"\n    tool_call_names: Final[list[str]] = []\n    for tool in tools:\n        if tool.get(\"type\") == \"function\":\n            tool_call_name = tool.get(\"function\", {}).get(\"name\")\n            if tool_call_name:\n                tool_call_names.append(tool_call_name)\n    return tool_call_names\n\n\ndef is_function_call(optional_params: dict) -> bool:\n    \"\"\"\n    Checks if the optional params contain the function call","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/prompt_templates/common_utils.py#L1215-L1251","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a direct image URL with a recognized extension (.png/.jpg/.webp/.gif) served with an image/* content-type","Pass a data URI with the mime explicit: data:image/png;base64,...","Verify the URL with curl -I and fix signing/auth so it returns the image bytes","Convert the image to PNG or JPEG and host it somewhere that returns correct headers"],"exampleFix":"# before: URL returns text/html (error page)\nmessages = [{\"role\": \"user\", \"content\": [{\"type\": \"image_url\", \"image_url\": {\"url\": \"https://cdn.example.com/expired-signed-pic\"}}]}]\n\n# after: inline data URI with explicit mime\nimport base64\ndata = base64.b64encode(open(\"pic.png\", \"rb\").read()).decode()\nmessages = [{\"role\": \"user\", \"content\": [{\"type\": \"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{data}\"}}]}]","handlingStrategy":"validation","validationCode":"import httpx\n\nSUPPORTED = (\"image/png\", \"image/jpeg\", \"image/gif\", \"image/webp\", \"image/heic\")\n\ndef url_has_image_content_type(url: str, timeout: float = 10.0) -> bool:\n    try:\n        r = httpx.head(url, follow_redirects=True, timeout=timeout)\n        ct = r.headers.get(\"content-type\", \"\")\n        return ct.split(\";\")[0].strip().lower() in SUPPORTED or ct.startswith(\"image/\")\n    except httpx.HTTPError:\n        return False\n\n# before the call: skip/replace URLs that fail the check\n# for block in content:\n#     if block.get(\"type\") == \"image_url\" and not url_has_image_content_type(block[\"image_url\"][\"url\"]): convert to data URI","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=model, messages=messages)\nexcept ValueError as e:\n    if \"Unable to determine content type from URL\" in str(e):\n        # re-encode the image as an explicit data URI and retry once\n        messages = inline_image_as_data_uri(messages)\n    else:\n        raise","preventionTips":["Prefer data:image/<mime>;base64,... URIs when you control the bytes","Use direct image links ending in .png/.jpg/.webp served with correct headers","Monitor signed-URL expiry for S3/CDN image sources","curl -I the URL in a health check for user-supplied image hosts"],"tags":["image","content-type","url","multimodal"],"backgroundTag":"image-content-type-detection-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}