BerriAI/litellm · error · ValueError

Invalid data URL format (missing comma)

Error message

Invalid data URL format (missing comma): {data_url[:50]}...

What it means

Raised by AmazonNovaEmbeddingConfig._parse_data_url when the value starts with 'data:' but contains no comma. The RFC 2397 format separates metadata ('data:image/jpeg;base64') from the payload with a single comma; without it the parser cannot split media type from base64 data.

Solutions

  1. Ensure the full form data:<mime>;base64,<payload> including the comma
  2. Unquote the value first if it may be percent-encoded: urllib.parse.unquote(data_url)
  3. Guard length: after the comma there should be non-empty base64 payload

Example fix

# before
media = 'data:image/jpeg;base64'  # payload missing

# after
media = 'data:image/jpeg;base64,/9j/4AAQSkZJRg=='
Defensive patterns

Strategy: validation

Validate before calling

def assert_wellformed_data_url(u: str) -> None:
    if not u.startswith('data:'):
        raise ValueError('missing data: prefix')
    if ',' not in u:
        raise ValueError('missing comma between metadata and payload')
    meta, payload = u.split(',', 1)
    if not payload:
        raise ValueError('empty base64 payload after comma')

Type guard

from typing import TypeGuard

def is_valid_data_url(u: object) -> TypeGuard[str]:
    if not isinstance(u, str):
        return False
    return u.startswith('data:') and ',' in u and u.split(',', 1)[1] != ''

Try / catch

try:
    resp = litellm.embedding(model='bedrock/amazon.nova-embed-v1', input=[url])
except ValueError as e:
    if 'missing comma' in str(e):
        raise InputTruncatedError(f'data URL payload missing after header: {url[:50]}') from e
    raise

Prevention

When it happens

Trigger: Sending 'data:image/jpeg;base64' (header with the payload forgotten); truncation/copy-paste that cut the string at the comma; URL-encoding the whole data URL so the comma became %2C; building the string with a missing format placeholder ('data:{};base64,{}' called with one arg).

Common situations: f-string templates with wrong arity; log/secret redaction tools stripping everything after commas; passing encoded URLs from web frameworks that percent-encode automatically.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/9e49c21fcaf7322a. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/bedrock/embed/amazon_nova_transformation.py:71

    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_data

    def _transform_request(
        self,
        input: str,
        inference_params: dict,

View on GitHub (pinned to 77b7c6c40c)