BerriAI/litellm · error · ValueError
Invalid data URL format
Error message
Invalid data URL format: {data_url[:50]}... What it means
Raised by AmazonNovaEmbeddingConfig._parse_data_url when a media value passed for Nova multimodal embedding does not start with 'data:'. Nova accepts images/video/audio only as RFC 2397 data URLs (data:image/jpeg;base64,...); a raw base64 blob, a file path, or an https URL fails this check immediately.
Solutions
- Prefix the value: 'data:image/jpeg;base64,' + base64_str
- Use a helper that builds the URL with the correct MIME type for your media (image/png, video/mp4, audio/mpeg, ...)
- If you only have a public URL, download the bytes and re-encode as a data URL first
Example fix
# before
import base64
b64 = base64.b64encode(open('cat.jpg','rb').read()).decode()
media = b64 # '/9j/4AAQ...' -> ValueError
# after
media = f'data:image/jpeg;base64,{b64}' Defensive patterns
Strategy: validation
Validate before calling
import base64, mimetypes
def to_data_url(path_or_b64: str, mime: str | None = None) -> str:
if path_or_b64.startswith('data:'):
return path_or_b64
if len(path_or_b64) < 260 or '/' in path_or_b64[:1]: # smells like a path
with open(path_or_b64, 'rb') as f:
b64 = base64.b64encode(f.read()).decode()
mime = mime or mimetypes.guess_type(path_or_b64)[0] or 'application/octet-stream'
else:
b64, mime = path_or_b64, mime or 'image/jpeg'
return f'data:{mime};base64,{b64}' Type guard
from typing import TypeGuard
def is_data_url(v: object) -> TypeGuard[str]:
return isinstance(v, str) and v.startswith('data:') and ',' in v Try / catch
try:
resp = litellm.embedding(model='bedrock/amazon.nova-embed-v1', input=[to_data_url(raw)])
except ValueError as e:
if 'Invalid data URL format' in str(e):
raise InputFormatError('media must be data:<mime>;base64,<payload>') from e
raise Prevention
- Always build data URLs with one helper; never concatenate ad hoc
- Store MIME type alongside bytes in your pipeline
- Reject http(s) URLs early with a 'download then re-encode' hint
When it happens
Trigger: Passing '/tmp/img.jpg' or 'https://cdn.example.com/img.jpg' as the media value; passing bare base64 ('/9j/4AAQ...') without the data: prefix; passing a Python bytes object stringified by accident.
Common situations: Reading a file and sending b64encode(...).decode() directly, forgetting the 'data:<mime>;base64,' header; migrating code from APIs that accept plain URLs; letting a frontend send just the base64 payload.
Related errors
- Invalid data URL format (missing comma)
- output_s3_uri is required for async invoke requests
- Missing boto3 to call bedrock. Run 'pip install boto3'.
- No embedding data found in response
- Timeout error occurred.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/916419ef39dab534.
Report an issue: GitHub.
Appendix: 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 77b7c6c40c)