{"record":{"id":"c1aa8adb09af2b0c","repo":"BerriAI/litellm","slug":"unsupported-image-input-filesystem-paths-are-not","errorCode":null,"errorMessage":"Unsupported image input: filesystem paths are not accepted for Vertex AI Imagen image edit. Provide image bytes or a file-like object.","messagePattern":"Unsupported image input: filesystem paths are not accepted for Vertex AI Imagen image edit\\. Provide image bytes or a file-like object\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py","lineNumber":341,"sourceCode":"        if isinstance(image, (BufferedReader, BufferedRandom)):\n            stream_pos: int | None = None\n            try:\n                stream_pos = image.tell()\n            except Exception:\n                stream_pos = None\n            if stream_pos is not None:\n                image.seek(0)\n            data = image.read()\n            if stream_pos is not None:\n                image.seek(stream_pos)\n            return data\n        if isinstance(image, str):\n            raise ValueError(\n                \"Unsupported image input: plain string values are not accepted for \"\n                \"Vertex AI Imagen image edit. Provide image bytes or a file-like object.\"\n            )\n        if isinstance(image, Path):\n            raise ValueError(\n                \"Unsupported image input: filesystem paths are not accepted for \"\n                \"Vertex AI Imagen image edit. Provide image bytes or a file-like object.\"\n            )\n        if hasattr(image, \"read\"):\n            data = image.read()\n            if isinstance(data, str):\n                data = data.encode(\"utf-8\")\n            return data\n        raise ValueError(f\"Unsupported image type for Vertex AI Imagen image edit. Got type={type(image)}\")\n","sourceCodeStart":323,"sourceCodeEnd":351,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py#L323-L351","documentation":"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.","triggerScenarios":"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.","commonSituations":"Refactoring legacy os.path code to pathlib and forgetting the litellm call site; Path objects flowing in from FastAPI/CLI argument parsers.","solutions":["Convert to bytes: image=Path('cat.png').read_bytes()","Or open in binary mode: with Path('cat.png').open('rb') as f: ...","Normalize paths to bytes at your request boundary so Path never reaches litellm"],"exampleFix":"# before\nfrom pathlib import Path\nresp = litellm.image_edit(\n    model='vertex_ai/imagen-3.0-capability-001',\n    prompt='edit',\n    image=Path('cat.png'),  # raises\n)\n\n# after\nfrom pathlib import Path\nresp = litellm.image_edit(\n    model='vertex_ai/imagen-3.0-capability-001',\n    prompt='edit',\n    image=Path('cat.png').read_bytes(),\n)","handlingStrategy":"type-guard","validationCode":"from pathlib import Path\n\nif isinstance(image, Path):\n    image = image.read_bytes()  # normalize before the call","typeGuard":"from pathlib import Path\nfrom typing import Any\n\ndef is_path(obj: Any) -> bool:\n    \"\"\"True when obj is a filesystem path that must be read to bytes first.\"\"\"\n    return isinstance(obj, Path)","tryCatchPattern":"try:\n    resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=image)\nexcept ValueError as e:\n    if 'filesystem paths are not accepted' in str(e):\n        resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=Path(image).read_bytes())\n    else:\n        raise","preventionTips":["Convert Path to bytes at your request boundary: Path(...).read_bytes()","Keep a single normalize_image() helper applied to all incoming image fields","Remember litellm never performs implicit filesystem I/O for image edit inputs"],"tags":["vertex-ai","imagen","image-edit","input-validation","pathlib","unsupported-type"],"backgroundTag":"unsupported-input-type","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}