BerriAI/litellm · error · ValueError
Invalid data URL format: {data_url[:50]}...
Error message
Invalid data URL format: {data_url[:50]}... What it means
Raised by the Amazon Nova embedding/multimodal transformation when a supplied media reference is not a data URL: it must start with 'data:' (format data:<mediatype>;base64,<payload>). Only the first 50 characters are echoed in the error.
Source
Thrown at litellm/llms/bedrock/embed/amazon_nova_transformation.py:66
optional_params["embedding_dimension"] = v
elif k in self.get_supported_openai_params():
optional_params[k] = v
return optional_params
def _parse_data_url(self, data_url: str) -> tuple:
"""
Parse a data URL to extract the media type and base64 data.
Args:
data_url: Data URL in format: data:image/jpeg;base64,/9j/4AAQ...
Returns:
tuple: (media_type, base64_data)
media_type: e.g., "image/jpeg", "video/mp4", "audio/mpeg"
base64_data: The base64-encoded data without the prefix
"""
if not data_url.startswith("data:"):
raise ValueError(f"Invalid data URL format: {data_url[:50]}...")
# Split by comma to separate metadata from data
# Format: data:image/jpeg;base64,<base64_data>
if "," not in data_url:
raise ValueError(f"Invalid data URL format (missing comma): {data_url[:50]}...")
metadata, base64_data = data_url.split(",", 1)
# Extract media type from metadata
# Remove 'data:' prefix and ';base64' suffix
metadata = metadata[5:] # Remove 'data:'
if ";" in metadata:
media_type = metadata.split(";")[0]
else:
media_type = metadata
return media_type, base64_dataView on GitHub (pinned to 6c2dcb801b)
Solutions
- Convert the media to a data URL: f"data:{mime};base64,{b64data}"
- For remote files, download the bytes and base64-encode them with the correct MIME type before building the data URL
- Ensure the prefix uses lowercase 'data:' exactly
Example fix
# before
{"image": "https://example.com/cat.jpg"}
# after
import base64, mimetypes
def to_data_url(path):
mime = mimetypes.guess_type(path)[0] or "application/octet-stream"
return f"data:{mime};base64," + base64.b64encode(open(path, 'rb').read()).decode() Defensive patterns
Strategy: type-guard
Validate before calling
def is_data_url(v: str) -> bool:
return isinstance(v, str) and v.startswith("data:") and "," in v Type guard
def to_data_url(raw: str, mime: str = "image/jpeg") -> str:
if raw.startswith("data:"):
return raw
if raw.startswith(("http://", "https://")):
import base64, urllib.request
b = urllib.request.urlopen(raw).read()
return f"data:{mime};base64," + base64.b64encode(b).decode()
raise ValueError("unsupported media reference") Prevention
- Convert all media to data URLs in one boundary function before Nova calls
- Standardize on data:<mime>;base64,<payload> in your storage layer
When it happens
Trigger: Passing an https:// image URL, a local file path, or a raw base64 string without the data: prefix as image/video/audio data to Nova embed calls.
Common situations: Receiving file references from webhooks/frontend uploads that use hosted URLs, or base64 blobs generated upstream whose data-URL prefix was stripped during JSON transport.
Related errors
- Invalid data URL format (missing comma): {data_url[:50]}...
- output_s3_uri is required for async invoke requests
- Unable to determine bedrock embedding provider for model: {m
- Input type '{input_type}' requires async_invoke route. Use m
- Unsupported image format: {image_format}. Supported formats:
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/916419ef39dab534.
Report an issue: GitHub.