BerriAI/litellm · error · ValueError
Unsupported file input type: {type(file_input)}. Expected pa
Error message
Unsupported file input type: {type(file_input)}. Expected pathlib.Path, bytes, or a file-like object. What it means
Type guard at the end of the OCR file-input chain: the value is neither Path, bytes, nor a readable file-like object, so its bytes cannot be obtained. The received type is listed alongside the accepted shapes.
Source
Thrown at litellm/ocr/main.py:538
file_path: Final = str(file_input)
if not os.path.isfile(file_path):
raise FileNotFoundError(f"File not found: {file_path}")
mime_type = get_mime_type(file_path)
file_name = os.path.basename(file_path)
with open(file_path, "rb") as f:
file_bytes = f.read()
elif isinstance(file_input, bytes):
file_bytes = file_input
elif isinstance(file_input, IOBase) or hasattr(file_input, "read"):
if hasattr(file_input, "name"):
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)",View on GitHub (pinned to 77b7c6c40c)
Solutions
- Convert the input to pathlib.Path, bytes, or a file-like object before passing it.
Example fix
from pathlib import Path; file_input = Path('doc.pdf') Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at litellm/ocr/main.py:538 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/235d223706f687c3.
Report an issue: GitHub.