{"record":{"id":"6038de132966aceb","repo":"BerriAI/litellm","slug":"unsupported-image-input-plain-string-values-are-n","errorCode":null,"errorMessage":"Unsupported image input: plain string values are not accepted for Vertex AI Imagen image edit. Provide image bytes or a file-like object.","messagePattern":"Unsupported image input: plain string values 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":336,"sourceCode":"            current_pos: Final = image.tell()\n            image.seek(0)\n            data = image.read()\n            image.seek(current_pos)\n            return data\n        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":318,"sourceCodeEnd":351,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vertex_ai/image_edit/vertex_imagen_transformation.py#L318-L351","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["base64-decode first: base64.b64decode(s.split(',')[-1]) and pass the resulting bytes","Or wrap the base64 string in a dict: image={'data': '<base64>'} — this form IS accepted and decoded internally","For files, open in binary mode and pass the file object or its bytes"],"exampleFix":"# before\nimport base64\nresp = litellm.image_edit(\n    model='vertex_ai/imagen-3.0-capability-001',\n    prompt='edit',\n    image='iVBORw0KGgoAAAANSU...',  # bare base64 str -> raises\n)\n\n# after\nimg_bytes = base64.b64decode('iVBORw0KGgoAAAANSU...')\nresp = litellm.image_edit(\n    model='vertex_ai/imagen-3.0-capability-001',\n    prompt='edit',\n    image=img_bytes,\n)","handlingStrategy":"type-guard","validationCode":"import base64\n\ndef normalize_image(img):\n    if isinstance(img, str):\n        return base64.b64decode(img.split(',')[-1])  # str -> bytes\n    return img\n\nimage = normalize_image(image)","typeGuard":"def is_imagen_edit_compatible(img) -> bool:\n    import base64\n    from io import BytesIO, BufferedReader\n    from pathlib import Path\n    if isinstance(img, (str, Path)):\n        return False  # explicitly rejected\n    return isinstance(img, (bytes, bytearray, BytesIO, BufferedReader)) or hasattr(img, 'read')","tryCatchPattern":"try:\n    resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=image)\nexcept ValueError as e:\n    if 'plain string values are not accepted' in str(e):\n        img = base64.b64decode(image.split(',')[-1])\n        resp = litellm.image_edit(model='vertex_ai/imagen-...', prompt=p, image=img)\n    else:\n        raise","preventionTips":["Decode base64 strings to bytes before calling litellm","If you must pass base64 text, wrap it as {'data': '<base64>'} which the handler decodes","Avoid {'path': ...} dicts — the inner string is still rejected"],"tags":["vertex-ai","imagen","image-edit","input-validation","base64","unsupported-type"],"backgroundTag":"unsupported-input-type","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}