{"record":{"id":"f24da5f45988998d","repo":"BerriAI/litellm","slug":"image-url-not-in-expected-format-example-expected-f24da5","errorCode":null,"errorMessage":"Image url not in expected format. Example Expected input - \"image_url\": \"data:image/jpeg;base64,{base64_image}\". Supported formats - ['image/jpeg', 'image/png', 'image/gif', 'image/webp']. Error: {e}","messagePattern":"Image url not in expected format\\. Example Expected input - \"image_url\": \"data:image/jpeg;base64,(.+?)\"\\. Supported formats - \\['image/jpeg', 'image/png', 'image/gif', 'image/webp'\\]\\. Error: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/factory.py","lineNumber":858,"sourceCode":"        if openai_image_url.startswith(\"http\"):\n            openai_image_url = convert_url_to_base64(url=openai_image_url)\n        # Extract the media type and base64 data\n        media_type, base64_data = openai_image_url.split(\"data:\")[1].split(\";base64,\")\n\n        if format:\n            media_type = format\n        else:\n            media_type = media_type.replace(\"\\\\/\", \"/\")\n\n        return GenericImageParsingChunk(\n            type=\"base64\",\n            media_type=media_type,\n            data=base64_data,\n        )\n    except litellm.ImageFetchError:\n        raise\n    except Exception as e:\n        raise Exception(\n            f\"\"\"Image url not in expected format. Example Expected input - \"image_url\": \"data:image/jpeg;base64,{{base64_image}}\". Supported formats - ['image/jpeg', 'image/png', 'image/gif', 'image/webp']. Error: {e}\"\"\"\n        )\n\n\ndef create_anthropic_image_param(\n    image_url_input: str | dict,\n    format: str | None = None,\n    is_bedrock_invoke: bool = False,\n) -> AnthropicMessagesImageParam:\n    \"\"\"\n    Create an AnthropicMessagesImageParam from an image URL input.\n\n    Supports both URL references (for HTTP/HTTPS URLs) and base64 encoding.\n    \"\"\"\n    # Extract URL and format from input\n    if isinstance(image_url_input, str):\n        image_url = image_url_input\n    else:","sourceCodeStart":840,"sourceCodeEnd":876,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/prompt_templates/factory.py#L840-L876","documentation":"While parsing an image into a base64 chunk (media_type + data) for Anthropic-style params, something failed and the generic except wraps it. The supported set is explicit in the message: image/jpeg, image/png, image/gif, image/webp. ImageFetchError is re-raised untouched, so this wrapper covers parse/format problems, not fetch failures.","triggerScenarios":"A data URI whose mime is outside the supported set (image/heic, image/avif, image/svg+xml); malformed or truncated base64 payloads; escaped slashes (\\/) the parser could not normalize; unexpected string shapes hitting the parser.","commonSituations":"iPhone HEIC photos; next-gen formats like AVIF/JPEG-XL; hand-assembled data URIs with typos in the mime or base64.","solutions":["Convert the image to a supported format (PNG/JPEG/GIF/WEBP) before sending","Use a data URI with one of the supported mimes: data:image/png;base64,...","Pass a hosted image URL instead of inline base64 where the provider supports it"],"exampleFix":"# before: HEIC not supported\n{\"type\": \"image_url\", \"image_url\": {\"url\": \"data:image/heic;base64,...\"}}\n\n# after: convert to PNG first\nfrom PIL import Image\nimport base64, io\nbuf = io.BytesIO()\nImage.open(\"photo.heic\").convert(\"RGB\").save(buf, format=\"PNG\")\nb64 = base64.b64encode(buf.getvalue()).decode()\n{\"type\": \"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{b64}\"}}","handlingStrategy":"validation","validationCode":"import re\n\nSUPPORTED_IMAGE_MIMES = {\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"}\nDATA_URI_RE = re.compile(r\"^data:([a-zA-Z0-9./+-]+);base64,(.+)$\")\n\ndef data_uri_is_supported(u: str) -> bool:\n    m = DATA_URI_RE.match(u)\n    return bool(m) and m.group(1).lower() in SUPPORTED_IMAGE_MIMES\n\n# before the call, convert unsupported images:\n# if not data_uri_is_supported(url): re-encode with PIL to PNG","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=model, messages=messages)\nexcept litellm.ImageFetchError:\n    raise\nexcept Exception as e:\n    if \"Image url not in expected format\" in str(e) and \"Supported formats\" in str(e):\n        messages = reencode_images_to_png(messages)\n    else:\n        raise","preventionTips":["Normalize user uploads to PNG/JPEG before building data URIs","Whitelist mimes at the API boundary: jpeg/png/gif/webp only","Transcode HEIC/AVIF server-side with Pillow/Pillow-Heif on ingest"],"tags":["image","base64","format","multimodal","anthropic"],"backgroundTag":"unsupported-image-format","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}