{"record":{"id":"ce331d7b68514f03","repo":"BerriAI/litellm","slug":"unsupported-image-type-expected-either-image-url","errorCode":null,"errorMessage":"Unsupported image type. Expected either image url or base64 encoded string","messagePattern":"Unsupported image type\\. Expected either image url or base64 encoded string","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/factory.py","lineNumber":3582,"sourceCode":"                    name=document_name,\n                )\n            )\n        elif is_video:\n            return BedrockContentBlock(video=BedrockVideoBlock(source=_blob, format=image_format))\n        else:\n            return BedrockContentBlock(image=BedrockImageBlock(source=_blob, format=image_format))\n\n    @classmethod\n    def process_image_sync(cls, image_url: str, format: str | None = None) -> BedrockContentBlock:\n        \"\"\"Synchronous image processing.\"\"\"\n\n        if \"base64\" in image_url:\n            img_bytes, mime_type, image_format = cls._parse_base64_image(image_url)\n        elif \"http://\" in image_url or \"https://\" in image_url:\n            img_bytes, mime_type = BedrockImageProcessor.get_image_details(image_url)\n            image_format = mime_type.split(\"/\")[1]\n        else:\n            raise ValueError(\"Unsupported image type. Expected either image url or base64 encoded string\")\n\n        if format:\n            mime_type = format\n            image_format = mime_type.split(\"/\")[1]\n\n        image_format = cls._validate_format(mime_type, image_format)\n        return cls._create_bedrock_block(img_bytes, mime_type, image_format)\n\n    @classmethod\n    async def process_image_async(cls, image_url: str, format: str | None) -> BedrockContentBlock:\n        \"\"\"Asynchronous image processing.\"\"\"\n\n        if \"base64\" in image_url:\n            img_bytes, mime_type, image_format = cls._parse_base64_image(image_url)\n        elif \"http://\" in image_url or \"https://\" in image_url:\n            img_bytes, mime_type = await BedrockImageProcessor.get_image_details_async(image_url)\n            image_format = mime_type.split(\"/\")[1]\n        else:","sourceCodeStart":3564,"sourceCodeEnd":3600,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/prompt_templates/factory.py#L3564-L3600","documentation":"Thrown by BedrockImageProcessor.process_image_sync when converting an OpenAI-style image_url to a Bedrock image block. The dispatcher only recognizes two shapes: strings containing the literal substring 'base64' (data URIs) and strings containing 'http://' or 'https://'. Anything else (file paths, s3:// URLs, bare base64 without the 'base64' marker, gs:// URLs) falls through to this ValueError.","triggerScenarios":"Calling a Bedrock Converse model with a message content block {\"type\": \"image_url\", \"image_url\": {\"url\": ...}} where url is a local file path, an s3:// URI, a data URI missing the 'base64' label, or a bare base64 blob. Detection is substring-based: 'BASE64' uppercase or 'HTTP://' uppercase will not match.","commonSituations":"Porting Anthropic/OpenAI code that reads images from disk or S3; constructing data URIs manually and omitting ';base64'; using uppercase URL schemes; passing an OSS/HTTPS-variant scheme like 'HTTPS://'.","solutions":["Pass a proper data URI: \"data:image/png;base64,<payload>\" so the substring 'base64' is present.","Or pass a public http(s) URL that Bedrock can fetch.","If the image is local or in S3, fetch and base64-encode it yourself before building the message.","Verify the scheme is lowercase and matches the two supported branches exactly."],"exampleFix":"// before\n{\"type\": \"image_url\", \"image_url\": {\"url\": \"/tmp/cat.png\"}}\n// after\nimport base64, pathlib\nb64 = base64.b64encode(pathlib.Path(\"/tmp/cat.png\").read_bytes()).decode()\n{\"type\": \"image_url\", \"image_url\": {\"url\": f\"data:image/png;base64,{b64}\"}}","handlingStrategy":"validation","validationCode":"def is_bedrock_image_url_ok(url: str) -> bool:\n    return \"base64\" in url or \"http://\" in url or \"https://\" in url\n\nassert is_bedrock_image_url_ok(image_url), \"Bedrock needs a data URI (with 'base64') or an http(s) URL\"","typeGuard":"def is_supported_image_url(url: str) -> bool:\n    return isinstance(url, str) and (\"base64\" in url or url.startswith((\"http://\", \"https://\")))","tryCatchPattern":"try:\n    resp = litellm.completion(model=\"bedrock/...\", messages=msgs)\nexcept ValueError as e:\n    if \"Unsupported image type\" in str(e):\n        image_url = local_image_to_data_uri(path)\n        resp = litellm.completion(model=\"bedrock/...\", messages=msgs)","preventionTips":["Always build image inputs with a helper that returns 'data:<mime>;base64,<payload>' or a verified http(s) URL.","Never pass file paths or s3:// URIs directly to image_url.","Unit-test your message builder against the two accepted shapes before sending to Bedrock."],"tags":["bedrock","image","multimodal","input-validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}