{"record":{"id":"16f1308fb1fb0236","repo":"BerriAI/litellm","slug":"unsupported-image-type-for-vertex-ai-imagen-image-16f130","errorCode":null,"errorMessage":"Unsupported image type for Vertex AI Imagen image edit. Got type={type(image)}","messagePattern":"Unsupported image type for Vertex AI Imagen image edit\\. Got type=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py","lineNumber":350,"sourceCode":"            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":332,"sourceCodeEnd":351,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py#L332-L351","documentation":"This is the catch-all at the end of Imagen edit's _read_all_bytes: the value matched none of the accepted shapes (list/tuple, dict with data/bytes/content/path, bytes, bytearray, BytesIO, BufferedReader/BufferedRandom, str, Path) and has no .read() method. Anything else — ints, PIL Image objects, numpy arrays, torch tensors — lands here with its type printed in the message.","triggerScenarios":"image=Image.open('cat.png') (PIL.Image.Image — no .read); image=np.ndarray from cv2/numpy pipelines; image=123 from a bad variable; a dataclass wrapping bytes without a read method.","commonSituations":"Computer-vision pipelines that keep images as numpy arrays or PIL objects; serialization boundaries passing through objects that lost their bytes; wrong variable passed after refactoring.","solutions":["PIL: buf=io.BytesIO(); img.save(buf, format='PNG'); image=buf.getvalue()","numpy/cv2: image=cv2.imencode('.png', arr)[1].tobytes()","Unwrap custom wrappers to raw bytes before the call","Check the Got type=... portion of the message to find which object leaked through"],"exampleFix":"# before\nfrom PIL import Image\nresp = litellm.image_edit(\n    model='vertex_ai/imagen-3.0-capability-001',\n    prompt='edit',\n    image=Image.open('cat.png'),  # PIL object -> raises\n)\n\n# after\nfrom PIL import Image\nimport io\nbuf = io.BytesIO()\nImage.open('cat.png').save(buf, format='PNG')\nresp = litellm.image_edit(\n    model='vertex_ai/imagen-3.0-capability-001',\n    prompt='edit',\n    image=buf.getvalue(),\n)","handlingStrategy":"type-guard","validationCode":"import io\n\ndef to_bytes(img) -> bytes:\n    if isinstance(img, bytes):\n        return img\n    if hasattr(img, 'read'):  # file-like\n        return img.read()\n    if hasattr(img, 'save'):  # PIL\n        buf = io.BytesIO(); img.save(buf, format='PNG'); return buf.getvalue()\n    if hasattr(img, 'tobytes'):  # numpy\n        return img.tobytes()\n    raise TypeError(f'cannot convert {type(img)} to image bytes')\n\nimage = to_bytes(image)","typeGuard":"def is_supported_image_value(img) -> bool:\n    return (\n        isinstance(img, (bytes, bytearray, list, tuple, dict))\n        or hasattr(img, 'read')\n    )","tryCatchPattern":"try:\n    resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=image)\nexcept ValueError as e:\n    if 'Unsupported image type' in str(e) and 'Got type=' in str(e):\n        image = to_bytes(image)  # your PIL/numpy converter\n        resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=image)\n    else:\n        raise","preventionTips":["Convert PIL/numpy/torch images to PNG bytes before calling litellm","Centralize conversion in one to_bytes() helper used by every upload path","Check the 'Got type=' suffix in the message to identify which unexpected object leaked through"],"tags":["vertex-ai","imagen","image-edit","input-validation","unsupported-type","pillow","numpy"],"backgroundTag":"unsupported-input-type","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}