{"record":{"id":"dd4b46b2061fe62c","repo":"BerriAI/litellm","slug":"unsupported-image-type-for-vertex-ai-gemini-image","errorCode":null,"errorMessage":"Unsupported image type for Vertex AI Gemini image edit.","messagePattern":"Unsupported image type for Vertex AI Gemini image edit\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/image_edit/vertex_gemini_transformation.py","lineNumber":272,"sourceCode":"\n        return inline_parts\n\n    def _read_all_bytes(self, image: FileTypes) -> bytes:\n        if isinstance(image, bytes):\n            return image\n        if isinstance(image, BytesIO):\n            current_pos = image.tell()\n            image.seek(0)\n            data = image.read()\n            image.seek(current_pos)\n            return data\n        if isinstance(image, BufferedReader):\n            current_pos = image.tell()\n            image.seek(0)\n            data = image.read()\n            image.seek(current_pos)\n            return data\n        raise ValueError(\"Unsupported image type for Vertex AI Gemini image edit.\")\n","sourceCodeStart":254,"sourceCodeEnd":273,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_edit/vertex_gemini_transformation.py#L254-L273","documentation":"The Gemini image-edit byte reader (_read_all_bytes in vertex_gemini_transformation.py:257) accepts only three shapes: raw bytes, io.BytesIO, and io.BufferedReader (a file opened in binary mode). Everything else — str (path or base64), pathlib.Path, the OpenAI-style FileTypes tuple ('cat.png', b'...'), PIL images, text-mode file handles — falls through to this ValueError. Unlike the Imagen variant, it does not unwrap tuples, dicts, or nested lists.","triggerScenarios":"image=open('cat.png', 'r') (TextIOWrapper, not BufferedReader); image='cat.png' or a base64 string; image=Path('cat.png'); image=('cat.png', b'...') tuple form; passing a list wrapped in a tuple so the whole tuple reaches _read_all_bytes.","commonSituations":"Reusing code built for requests/httpx multipart files= tuples; passing base64 data-URI strings received from a JSON API; opening files without 'b' mode on Windows or after refactoring; passing pathlib.Path objects from modern scripts.","solutions":["Open the file in binary mode: open('cat.png', 'rb') yields a BufferedReader, which is accepted","Pass raw bytes or io.BytesIO(bytes) for in-memory images","Convert pathlib.Path via Path('cat.png').read_bytes()","base64-decode strings first: base64.b64decode(data_uri.split(',')[1])"],"exampleFix":"# before\nresp = litellm.image_edit(\n    model='vertex_ai/gemini-2.5-flash-image',\n    prompt='add a hat',\n    image='cat.png',  # str path -> raises\n)\n\n# after\nwith open('cat.png', 'rb') as f:  # BufferedReader\n    resp = litellm.image_edit(\n        model='vertex_ai/gemini-2.5-flash-image',\n        prompt='add a hat',\n        image=f,\n    )","handlingStrategy":"type-guard","validationCode":"from io import BytesIO, BufferedReader\n\ndef is_gemini_edit_compatible(img) -> bool:\n    return isinstance(img, (bytes, BytesIO, BufferedReader))\n\nassert is_gemini_edit_compatible(image), 'provide bytes, BytesIO, or a file opened in rb mode'","typeGuard":"from io import BytesIO, BufferedReader\nfrom typing import Any\n\ndef is_readable_image(img: Any) -> bool:\n    \"\"\"Narrow to types the Vertex Gemini image-edit reader accepts.\"\"\"\n    return isinstance(img, (bytes, BytesIO, BufferedReader))","tryCatchPattern":"try:\n    resp = litellm.image_edit(model='vertex_ai/gemini-2.5-flash-image', prompt=p, image=image)\nexcept ValueError as e:\n    if 'Unsupported image type' in str(e):\n        raise ValueError('Convert image to bytes/BytesIO/binary file before editing') from e\n    raise","preventionTips":["Always open files with mode 'rb' before passing to image edit","Convert Path objects with .read_bytes() at the boundary","Base64-decode strings before sending; the Gemini handler does not decode them"],"tags":["vertex-ai","gemini","image-edit","input-validation","file-handling","unsupported-type"],"backgroundTag":"unsupported-input-type","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}