BerriAI/litellm · error · ValueError

Unsupported image format

Error message

Unsupported image format: {image_format}. Supported formats: {supported_image_and_video_formats}

What it means

Bedrock image processing: the derived image/video format (extension) is not in the supported list for that model (supported_video_formats + supported_image_formats), so litellm raises rather than sending a format Bedrock will reject. Documents take a separate path and do not reach this check.

Solutions

  1. Convert the media to a supported format (JPEG/PNG/GIF/WEBP for images; the model's listed video formats for video)
  2. Rename/serve the file with a standard extension so format detection picks a supported one
  3. Check the error's supported list against your format before filing bugs

Example fix

# before: TIFF sent to Bedrock Anthropic
{"type": "image", "source": {"type": "base64", "media_type": "image/tiff", "data": tiff_b64}}

# after: convert to PNG
from PIL import Image
import base64, io
buf = io.BytesIO()
Image.open("scan.tiff").convert("RGB").save(buf, format="PNG")
png_b64 = base64.b64encode(buf.getvalue()).decode()
{"type": "image", "source": {"type": "base64", "media_type": "image/png", "data": png_b64}}
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED_IMAGE_FORMATS = {"jpeg", "jpg", "png", "gif", "webp"}
SUPPORTED_VIDEO_FORMATS = {"mp4", "mov", "mkv", "webm", "flv", "mpeg", "mpg", "wmv", "3gp"}

def media_format_supported(url_or_mime: str) -> bool:
    ext = url_or_mime.rsplit(".", 1)[-1].lower() if "." in url_or_mime else url_or_mime.split("/")[-1].lower()
    return ext in (SUPPORTED_IMAGE_FORMATS | SUPPORTED_VIDEO_FORMATS)

# convert unsupported media to PNG/MP4 before building the bedrock payload

Try / catch

try:
    litellm.completion(model="bedrock/anthropic.claude-...", messages=messages)
except ValueError as e:
    if "Unsupported image format" in str(e):
        messages = reencode_media_to_png(messages)  # PIL convert, then retry
    else:
        raise

Prevention

When it happens

Trigger: Sending an image or video whose extension is unsupported by the Bedrock model in use - e.g. .tiff, .avif, .svg, or an unusual extension guessed from the mime type when the URL lacks one.

Common situations: iPhone HEIC media; CAD/print formats (TIFF); URLs without extensions where mimetypes.guess_all_extensions picks an exotic suffix; new formats not yet in Bedrock's list.

Related errors


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

Appendix: source

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

        supported_doc_formats: Final = litellm.AmazonConverseConfig().get_supported_document_types()
        supported_video_formats: Final = litellm.AmazonConverseConfig().get_supported_video_types()

        document_types: Final = ["application", "text"]
        is_document: Final = any(mime_type.startswith(doc_type) for doc_type in document_types)

        supported_image_and_video_formats: Final[list[str]] = supported_video_formats + supported_image_formats

        if is_document:
            return BedrockImageProcessor._get_document_format(
                mime_type=mime_type, supported_doc_formats=supported_doc_formats
            )

        else:
            #########################################################
            # Check if image_format is an image or video
            #########################################################
            if image_format not in supported_image_and_video_formats:
                raise ValueError(
                    f"Unsupported image format: {image_format}. Supported formats: {supported_image_and_video_formats}"
                )
            return image_format

    @staticmethod
    def _get_document_format(mime_type: str, supported_doc_formats: list[str]) -> str:
        """
        Get the document format from the mime type

        - Primary method - uses `mimetypes.guess_all_extensions`
        - Fallback method - uses `get_file_extension_from_mime_type`

        Relevant Issue: https://github.com/BerriAI/litellm/issues/12260

        `mimetypes` is not available in docker containers, so we fallback to `get_file_extension_from_mime_type`

        Args:
            mime_type: The mime type of the document

View on GitHub (pinned to 77b7c6c40c)