{"record":{"id":"84f71e402af376d8","repo":"BerriAI/litellm","slug":"gemini-image-conversion-failed-please-run-pip-ins","errorCode":null,"errorMessage":"gemini image conversion failed please run `pip install Pillow`","messagePattern":"gemini image conversion failed please run `pip install Pillow`","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/factory.py","lineNumber":3241,"sourceCode":"                    if isinstance(element, dict):\n                        if element[\"type\"] == \"text\":\n                            prompt += element[\"text\"]\n                        elif element[\"type\"] == \"image_url\":\n                            image_url = element[\"image_url\"][\"url\"]\n                            images.append(image_url)\n        # processing images passed to gemini\n        processed_images: Final = []\n        for img in images:\n            if \"https:/\" in img:\n                # Case 1: Image from URL\n                image = _load_image_from_url(img)\n                processed_images.append(image)\n\n            else:\n                try:\n                    from PIL import Image\n                except Exception:\n                    raise Exception(\"gemini image conversion failed please run `pip install Pillow`\")\n\n                if \"base64\" in img:\n                    # Case 2: Base64 image data\n                    import base64\n                    import io\n\n                    # Extract the base64 image data\n                    base64_data = img.split(\"base64,\")[1]\n\n                    # Decode the base64 image data\n                    image_data = base64.b64decode(base64_data)\n\n                    # Load the image from the decoded data\n                    image = Image.open(io.BytesIO(image_data))\n                else:\n                    # Case 3: Image filepath (e.g. temp.jpeg) given\n                    image = Image.open(img)\n                processed_images.append(image)","sourceCodeStart":3223,"sourceCodeEnd":3259,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/prompt_templates/factory.py#L3223-L3259","documentation":"Gemini vision conversion, base64 branch: litellm tried to import PIL to decode the base64 image data and the import failed, raising this dependency error. It is the Gemini-path twin of the generic Pillow error - the environment lacks the optional Pillow package.","triggerScenarios":"Sending base64 image data (img contains 'base64') to a Gemini vision model in an environment without Pillow installed; the URL branch uses _load_image_from_url and fails with the sibling error instead.","commonSituations":"Minimal deployments (slim Docker, serverless) without Pillow; upgrading environments and dropping the dependency; CI differing from local.","solutions":["pip install Pillow in the runtime environment","Pin Pillow in requirements to keep it present across rebuilds","If you cannot install it, pass image URLs supported without local decoding"],"exampleFix":"# before: PIL import fails on the base64 branch\n# after\npip install Pillow","handlingStrategy":"validation","validationCode":"def pillow_available() -> bool:\n    try:\n        import PIL  # noqa: F401\n        return True\n    except ImportError:\n        return False\n\n# fail fast at startup when sending base64 images to gemini vision models","typeGuard":null,"tryCatchPattern":"try:\n    litellm.completion(model=\"gemini/gemini-...\", messages=messages)\nexcept Exception as e:\n    if \"gemini image conversion failed\" in str(e) and \"Pillow\" in str(e):\n        raise RuntimeError(\"Install Pillow to send base64 images to Gemini\") from e\n    raise","preventionTips":["Install Pillow whenever base64 images go to Gemini vision models","Add a dependency check to your deployment health probe","Prefer https URLs for Gemini images when you cannot install Pillow"],"tags":["dependency","pillow","image","gemini"],"backgroundTag":"missing-dependency","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}