BerriAI/litellm · error · ValueError
Unsupported image type. Expected either image url or base64
Error message
Unsupported image type. Expected either image url or base64 encoded string
What it means
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.
Source
Thrown at litellm/litellm_core_utils/prompt_templates/factory.py:3582
name=document_name,
)
)
elif is_video:
return BedrockContentBlock(video=BedrockVideoBlock(source=_blob, format=image_format))
else:
return BedrockContentBlock(image=BedrockImageBlock(source=_blob, format=image_format))
@classmethod
def process_image_sync(cls, image_url: str, format: str | None = None) -> BedrockContentBlock:
"""Synchronous image processing."""
if "base64" in image_url:
img_bytes, mime_type, image_format = cls._parse_base64_image(image_url)
elif "http://" in image_url or "https://" in image_url:
img_bytes, mime_type = BedrockImageProcessor.get_image_details(image_url)
image_format = mime_type.split("/")[1]
else:
raise ValueError("Unsupported image type. Expected either image url or base64 encoded string")
if format:
mime_type = format
image_format = mime_type.split("/")[1]
image_format = cls._validate_format(mime_type, image_format)
return cls._create_bedrock_block(img_bytes, mime_type, image_format)
@classmethod
async def process_image_async(cls, image_url: str, format: str | None) -> BedrockContentBlock:
"""Asynchronous image processing."""
if "base64" in image_url:
img_bytes, mime_type, image_format = cls._parse_base64_image(image_url)
elif "http://" in image_url or "https://" in image_url:
img_bytes, mime_type = await BedrockImageProcessor.get_image_details_async(image_url)
image_format = mime_type.split("/")[1]
else:View on GitHub (pinned to 6c2dcb801b)
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.
Example fix
// before
{"type": "image_url", "image_url": {"url": "/tmp/cat.png"}}
// after
import base64, pathlib
b64 = base64.b64encode(pathlib.Path("/tmp/cat.png").read_bytes()).decode()
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}} Defensive patterns
Strategy: validation
Validate before calling
def is_bedrock_image_url_ok(url: str) -> bool:
return "base64" in url or "http://" in url or "https://" in url
assert is_bedrock_image_url_ok(image_url), "Bedrock needs a data URI (with 'base64') or an http(s) URL" Type guard
def is_supported_image_url(url: str) -> bool:
return isinstance(url, str) and ("base64" in url or url.startswith(("http://", "https://"))) Try / catch
try:
resp = litellm.completion(model="bedrock/...", messages=msgs)
except ValueError as e:
if "Unsupported image type" in str(e):
image_url = local_image_to_data_uri(path)
resp = litellm.completion(model="bedrock/...", messages=msgs) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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://'.
Related errors
- Unsupported content type: {type(content_block)}
- Bedrock Converse only supports base64-encoded document sourc
- Error: Unsupported image format. Format={_img_type}. Support
- Content type `{item_type}` is not supported by OCI
- model is required
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/ce331d7b68514f03.
Report an issue: GitHub.