oobabooga/textgen · error · ValueError

Invalid base64 image data: {e}

Error message

Invalid base64 image data: {e}

What it means

Error "Invalid base64 image data: {e}" thrown in oobabooga/textgen.

Source

Thrown at modules/image_utils.py:46

    buffered = io.BytesIO()
    # Save image to an in-memory bytes buffer in PNG format
    image.save(buffered, format="PNG")
    # Encode the bytes to a base64 string
    return base64.b64encode(buffered.getvalue()).decode('utf-8')


def decode_base64_image(base64_string: str) -> Image.Image:
    """Decodes a base64 string to a PIL Image."""
    try:
        if base64_string.startswith('data:image/'):
            base64_string = base64_string.split(',', 1)[1]

        image_data = base64.b64decode(base64_string)
        image = Image.open(io.BytesIO(image_data))
        return image
    except Exception as e:
        logger.error(f"Failed to decode base64 image: {e}")
        raise ValueError(f"Invalid base64 image data: {e}")


def process_message_content(content: Any) -> Tuple[str, List[Image.Image]]:
    """
    Processes message content that may contain text and images.
    Returns: A tuple of (text_content, list_of_pil_images).
    """
    if isinstance(content, str):
        return content, []

    if isinstance(content, list):
        text_parts = []
        images = []
        for item in content:
            if not isinstance(item, dict):
                continue

            item_type = item.get('type', '')

View on GitHub (pinned to ed888c71f2)

Solutions

  1. Verify the image string is valid base64, including correct padding and no data-URI prefix unless expected.
  2. Re-encode the image with base64.b64encode before sending it.

When it happens

Trigger: Raised in modules/image_utils.py when decoding base64 image data supplied to the API (e.g. in a multimodal chat message image_url) fails. Triggers when the payload is not valid base64, has data-URI prefix issues, wrong padding, or contains non-image bytes.

Common situations: See trigger scenarios.


AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15). Data as JSON: /api/errors/be6a5e72b93c673e. Report an issue: GitHub.