BerriAI/litellm · error · ValueError
Invalid MIME type: {mime_type}
Error message
Invalid MIME type: {mime_type} What it means
Raised when the resolved MIME type (from the filename, file object name, or document['mime_type'] override) is not a valid MIME string, so it cannot be embedded in the base64 data URI for the OCR request.
Source
Thrown at litellm/ocr/main.py:549
file_name = getattr(file_input, "name", None)
if file_name:
mime_type = get_mime_type(file_name)
file_bytes = file_input.read()
if isinstance(file_bytes, str):
file_bytes = file_bytes.encode("utf-8")
else:
raise ValueError(
f"Unsupported file input type: {type(file_input)}. Expected pathlib.Path, bytes, or a file-like object."
)
if not file_bytes:
raise ValueError("File is empty or could not be read")
if "mime_type" in document:
mime_type = document["mime_type"]
if not _MIME_PATTERN.match(mime_type):
raise ValueError(f"Invalid MIME type: {mime_type}")
base64_data: Final = base64.b64encode(file_bytes).decode("utf-8")
data_uri: Final = f"data:{mime_type};base64,{base64_data}"
if mime_type.startswith("image/"):
verbose_logger.debug(
"OCR file input: Converted file to image_url data URI (mime=%s, size=%s bytes, name=%s)",
mime_type,
len(file_bytes),
file_name,
)
return {"type": "image_url", "image_url": data_uri}
verbose_logger.debug(
"OCR file input: Converted file to document_url data URI (mime=%s, size=%s bytes, name=%s)",
mime_type,
len(file_bytes),
file_name,View on GitHub (pinned to 77b7c6c40c)
Solutions
- Provide a supported MIME type (e.g. application/pdf, image/png).
- Check the file extension matches its actual content.
Example fix
mime_type='application/pdf'
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/ocr/main.py:549 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/1cba2a836fe135b0.
Report an issue: GitHub.