BerriAI/litellm · error · ValueError

Unsupported image input: filesystem paths are not accepted f

Error message

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

What it means

pathlib.Path objects are explicitly rejected by the Imagen edit byte reader, with a dedicated message so users know exactly what to change. The policy matches the string ban: the library will not perform filesystem I/O implicitly on your behalf. Read the file first and hand over bytes or a file object.

Source

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

        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. Convert to bytes: image=Path('cat.png').read_bytes()
  2. Or open in binary mode: with Path('cat.png').open('rb') as f: ...
  3. Normalize paths to bytes at your request boundary so Path never reaches litellm

Example fix

# before
from pathlib import Path
resp = litellm.image_edit(
    model='vertex_ai/imagen-3.0-capability-001',
    prompt='edit',
    image=Path('cat.png'),  # raises
)

# after
from pathlib import Path
resp = litellm.image_edit(
    model='vertex_ai/imagen-3.0-capability-001',
    prompt='edit',
    image=Path('cat.png').read_bytes(),
)
Defensive patterns

Strategy: type-guard

Validate before calling

from pathlib import Path

if isinstance(image, Path):
    image = image.read_bytes()  # normalize before the call

Type guard

from pathlib import Path
from typing import Any

def is_path(obj: Any) -> bool:
    """True when obj is a filesystem path that must be read to bytes first."""
    return isinstance(obj, Path)

Try / catch

try:
    resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=image)
except ValueError as e:
    if 'filesystem paths are not accepted' in str(e):
        resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=Path(image).read_bytes())
    else:
        raise

Prevention

When it happens

Trigger: image=Path('uploads/cat.png'); image={'path': Path('/tmp/x.png')} (recurses into the Path and hits this branch); modern scripts that default to pathlib for all file handling.

Common situations: Refactoring legacy os.path code to pathlib and forgetting the litellm call site; Path objects flowing in from FastAPI/CLI argument parsers.

Related errors


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