BerriAI/litellm · error · ValueError

Batch upload file handle must be seekable; got a non-seekabl

Error message

Batch upload file handle must be seekable; got a non-seekable stream. Pass bytes, a path, or a seekable handle.

What it means

Batch file iteration guard: the supplied file object has a read() method but no seek(), and the upload reads the handle twice (first-row probe then body), so a non-seekable stream would silently drop data and is rejected loudly.

Source

Thrown at litellm/llms/vertex_ai/files/transformation.py:597

        return

    if isinstance(content, str):
        yield from _iter_stripped_lines(io.StringIO(content))
        return

    if isinstance(content, PathLike):
        with open(str(content), "rb") as handle:
            yield from _iter_stripped_lines(handle)
        return

    if hasattr(content, "read"):
        # The handle is read twice per upload (first-row probe for the GCS
        # object name, then the body stream), so it must rewind to 0. A
        # non-seekable handle would silently resume mid-stream and drop the
        # already-consumed first row, so reject it loudly instead.
        seek: Final = getattr(content, "seek", None)
        if seek is None:
            raise ValueError(
                "Batch upload file handle must be seekable; got a non-seekable "
                "stream. Pass bytes, a path, or a seekable handle."
            )
        try:
            seek(0)
        except (OSError, ValueError) as e:
            raise ValueError(
                "Batch upload file handle must be seekable so it can be re-read "
                "for the GCS object name and the upload body."
            ) from e
        yield from _iter_stripped_lines(content)
        return

    raise ValueError("Unsupported file content type")


def _iter_openai_jsonl_entries(
    openai_file_content: FileTypes,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Pass bytes, a file path, or a seekable file handle for the batch upload.

Example fix

file=open("batch.jsonl","rb")  # seekable handle
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when the batch upload file handle is a non-seekable stream; pass bytes, a path, or a seekable handle.

Common situations: See trigger scenarios.


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