BerriAI/litellm · error · ValueError

Unsupported image input: plain string values are not accepte

Error message

Unsupported image input: plain string values are not accepted for Vertex AI Imagen image edit. Provide image bytes or a file-like object.

What it means

Imagen edit deliberately refuses bare strings as image input: a str could be a filesystem path, a URL, or base64, and guessing wrong silently corrupts the edit. Strings are only accepted inside dicts under the 'data', 'bytes', or 'content' keys, where they are explicitly base64-decoded (decode failure falls through). Note that a dict {'path': ...} recurses into its string value and lands on this same error.

Source

Thrown at litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py:336

            current_pos: Final = image.tell()
            image.seek(0)
            data = image.read()
            image.seek(current_pos)
            return data
        if isinstance(image, (BufferedReader, BufferedRandom)):
            stream_pos: int | None = None
            try:
                stream_pos = image.tell()
            except Exception:
                stream_pos = None
            if stream_pos is not None:
                image.seek(0)
            data = image.read()
            if stream_pos is not None:
                image.seek(stream_pos)
            return data
        if isinstance(image, str):
            raise ValueError(
                "Unsupported image input: plain string values are not accepted for "
                "Vertex AI Imagen image edit. Provide image bytes or a file-like object."
            )
        if isinstance(image, Path):
            raise ValueError(
                "Unsupported image input: filesystem paths are not accepted for "
                "Vertex AI Imagen image edit. Provide image bytes or a file-like object."
            )
        if hasattr(image, "read"):
            data = image.read()
            if isinstance(data, str):
                data = data.encode("utf-8")
            return data
        raise ValueError(f"Unsupported image type for Vertex AI Imagen image edit. Got type={type(image)}")

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. base64-decode first: base64.b64decode(s.split(',')[-1]) and pass the resulting bytes
  2. Or wrap the base64 string in a dict: image={'data': '<base64>'} — this form IS accepted and decoded internally
  3. For files, open in binary mode and pass the file object or its bytes

Example fix

# before
import base64
resp = litellm.image_edit(
    model='vertex_ai/imagen-3.0-capability-001',
    prompt='edit',
    image='iVBORw0KGgoAAAANSU...',  # bare base64 str -> raises
)

# after
img_bytes = base64.b64decode('iVBORw0KGgoAAAANSU...')
resp = litellm.image_edit(
    model='vertex_ai/imagen-3.0-capability-001',
    prompt='edit',
    image=img_bytes,
)
Defensive patterns

Strategy: type-guard

Validate before calling

import base64

def normalize_image(img):
    if isinstance(img, str):
        return base64.b64decode(img.split(',')[-1])  # str -> bytes
    return img

image = normalize_image(image)

Type guard

def is_imagen_edit_compatible(img) -> bool:
    import base64
    from io import BytesIO, BufferedReader
    from pathlib import Path
    if isinstance(img, (str, Path)):
        return False  # explicitly rejected
    return isinstance(img, (bytes, bytearray, BytesIO, BufferedReader)) or hasattr(img, 'read')

Try / catch

try:
    resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=image)
except ValueError as e:
    if 'plain string values are not accepted' in str(e):
        img = base64.b64decode(image.split(',')[-1])
        resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=img)
    else:
        raise

Prevention

When it happens

Trigger: image='iVBORw0KGgo...' (base64 string); image={'path': '/tmp/x.png'} (the inner path str reaches the str branch); forwarding a data-URI 'data:image/png;base64,...' straight from a JSON request.

Common situations: Receiving base64 from a web frontend and passing it through unchanged; code ported from the Gemini handler expectations; configuration files referencing images by path string.

Related errors


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