BerriAI/litellm · error · Exception

image conversion failed please run `pip install Pillow`

Error message

image conversion failed please run `pip install Pillow`

What it means

litellm tried to import PIL (Pillow) to open an image and the import failed, so it raises this dependency-missing error instead of an opaque ImportError. Nothing about the request is wrong - the runtime simply lacks the optional imaging dependency.

Solutions

  1. pip install Pillow in the environment that runs litellm
  2. Add Pillow to your requirements.txt/pyproject.toml
  3. Rebuild the Docker image with Pillow included

Example fix

# before: Pillow absent -> Exception('image conversion failed please run `pip install Pillow`')

# after
pip install Pillow
Defensive patterns

Strategy: validation

Validate before calling

def pillow_available() -> bool:
    try:
        import PIL  # noqa: F401
        return True
    except ImportError:
        return False

# at startup:
# if using vision features and not pillow_available(): fail fast with a clear message

Try / catch

try:
    litellm.completion(model=model, messages=messages)  # vision path
except Exception as e:
    if "pip install Pillow" in str(e):
        raise RuntimeError("Pillow missing in this environment - add it to the image") from e
    raise

Prevention

When it happens

Trigger: Calling a vision path that uses _load_image_from_url (e.g. Amazon/Gemini image handling) in an environment where Pillow is not installed, e.g. slim Docker images or a minimal pip install of litellm.

Common situations: Slim/production Docker images; litellm installed without extras; virtualenv or multiple-Python mismatches where Pillow exists in one interpreter but the app runs another.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/4aa4946d677d7dfe. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/prompt_templates/factory.py:3178

    for idx, message in enumerate(messages):
        if message["role"] == "user":
            prompt += f"{AmazonTitanConstants.HUMAN_PROMPT.value}{message['content']}"
        elif message["role"] == "system":
            prompt += f"{AmazonTitanConstants.HUMAN_PROMPT.value}<admin>{message['content']}</admin>"
        else:
            prompt += f"{AmazonTitanConstants.AI_PROMPT.value}{message['content']}"
        if idx == 0 and message["role"] == "assistant":  # ensure the prompt always starts with `\n\nHuman: `
            prompt = f"{AmazonTitanConstants.HUMAN_PROMPT.value}" + prompt
    if messages[-1]["role"] != "assistant":
        prompt += f"{AmazonTitanConstants.AI_PROMPT.value}"
    return prompt


def _load_image_from_url(image_url):
    try:
        from PIL import Image
    except Exception:
        raise Exception("image conversion failed please run `pip install Pillow`")
    from io import BytesIO

    try:
        # Send a GET request to the image URL
        client: Final = HTTPHandler(concurrent_limit=1)
        response: Final[httpx.Response] = safe_get(client, image_url)
        response.raise_for_status()  # Raise an exception for HTTP errors

        # Check the response's content type to ensure it is an image
        content_type: Final = response.headers.get("content-type")
        if not content_type or "image" not in content_type:
            raise ValueError(f"URL does not point to a valid image (content-type: {content_type})")

        # Load the image from the response content
        return Image.open(BytesIO(response.content))

    except Exception as e:
        raise e

View on GitHub (pinned to 77b7c6c40c)