{"record":{"id":"4721ce5d1216df81","repo":"BerriAI/litellm","slug":"error-unsupported-image-format-format-img-type","errorCode":null,"errorMessage":"Error: Unsupported image format. Format={_img_type}. Supported types = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']","messagePattern":"Error: Unsupported image format\\. Format=(.+?)\\. Supported types = \\['image/jpeg', 'image/png', 'image/gif', 'image/webp'\\]","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/image_handling.py","lineNumber":63,"sourceCode":"            raise litellm.ImageFetchError(\n                f\"Error: Image size ({size_mb:.2f}MB) exceeds maximum allowed size ({MAX_IMAGE_URL_DOWNLOAD_SIZE_MB}MB). url={url}\"\n            )\n        image_bytes.extend(chunk)\n\n    base64_image: Final = base64.b64encode(image_bytes).decode(\"utf-8\")\n\n    image_type: Final = response.headers.get(\"Content-Type\")\n    if image_type is None:\n        img_type = url.split(\".\")[-1].lower()\n        _img_type: Final = {\n            \"jpg\": \"image/jpeg\",\n            \"jpeg\": \"image/jpeg\",\n            \"png\": \"image/png\",\n            \"gif\": \"image/gif\",\n            \"webp\": \"image/webp\",\n        }.get(img_type)\n        if _img_type is None:\n            raise Exception(\n                f\"Error: Unsupported image format. Format={_img_type}. Supported types = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']\"\n            )\n        img_type = _img_type\n    else:\n        img_type = image_type\n\n    result: Final = f\"data:{img_type};base64,{base64_image}\"\n    in_memory_cache.set_cache(url, result)\n    return result\n\n\nasync def async_convert_url_to_base64(url: str) -> str:\n    if url.startswith(\"data:\") and \";base64,\" in url:\n        return url\n\n    # If MAX_IMAGE_URL_DOWNLOAD_SIZE_MB is 0, block all image downloads\n    if MAX_IMAGE_URL_DOWNLOAD_SIZE_MB == 0:\n        raise litellm.ImageFetchError(","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/prompt_templates/image_handling.py#L45-L81","documentation":"Image download validation guard: after fetching an image URL, the resolved image type (from Content-Type header or URL extension) is not one of the supported types (jpeg/png/gif/webp), so the image cannot be forwarded to the provider. Fires on unsupported or mislabeled image URLs.","triggerScenarios":"Thrown at litellm/litellm_core_utils/prompt_templates/image_handling.py:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Convert the image to jpeg, png, gif, or webp before sending.","Check the image's actual format; the detected format is unsupported."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}