BerriAI/litellm · error · ValueError

Error parsing file upload response: {e}

Error message

Error parsing file upload response: {e}

What it means

After the Gemini resumable upload completes, litellm parses the final response JSON (name, displayName, createTime timestamps) into an OpenAI-style file object inside a try/except. Any failure while parsing — missing keys, unexpected timestamp formats, or a non-JSON body — is logged via verbose_logger.exception and re-raised as ValueError('Error parsing file upload response: ...') with the parsing exception appended.

Source

Thrown at litellm/llms/gemini/files/transformation.py:192

                id=response_object["uri"],  # Gemini uses URI as identifier
                bytes=int(response_object["sizeBytes"]),  # Gemini doesn't return file size
                created_at=int(
                    time.mktime(
                        time.strptime(
                            response_object["createTime"].replace("Z", "+00:00"),
                            "%Y-%m-%dT%H:%M:%S.%f%z",
                        )
                    )
                ),
                filename=response_object["displayName"],
                object="file",
                purpose="user_data",  # Default to assistants as that's the main use case
                status="uploaded",
                status_details=None,
            )
        except Exception as e:
            verbose_logger.exception("Error parsing file upload response: %s", e)
            raise ValueError(f"Error parsing file upload response: {e}")

    def transform_retrieve_file_request(
        self,
        file_id: str,
        optional_params: dict,
        litellm_params: dict,
    ) -> tuple[str, dict]:
        """
        Get the URL to retrieve a file from Google AI Studio.

        Endpoint:
        GET https://generativelanguage.googleapis.com/v1beta/{name=files/*}

        The URL should look like:
        https://generativelanguage.googleapis.com/v1beta/files/{file_id}?key=API_KEY

        We expect file_id to be just the file identifier (e.g., files/abc123 or abc123)
        as returned by the upload response. (If it's a full URL, extract the file name.)

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Enable verbose logging (litellm.verbose = True or set LITELLM_LOG=DEBUG) — the logged exception names the exact parse failure and field.
  2. Retry the upload: truncated/proxied responses are frequently one-off; resumable upload will start a new session.
  3. Upgrade litellm to the latest release so the Files response parser matches Google's current schema.

Example fix

# before
file_obj = litellm.create_file(model="gemini/", file=f)
# parse failure crashes the app

# after
import litellm
try:
    file_obj = litellm.create_file(model="gemini/", file=f)
except ValueError as e:
    if "Error parsing file upload response" in str(e):
        file_obj = litellm.create_file(model="gemini/", file=f)  # retry once
    else:
        raise
Defensive patterns

Strategy: retry

Try / catch

def upload_gemini_file(f, attempts: int = 2):
    for i in range(attempts):
        try:
            return litellm.create_file(model="gemini/", file=f, purpose="user_data")
        except ValueError as e:
            if "Error parsing file upload response" in str(e):
                f.seek(0)  # reset handle for a clean retry
                continue
            raise
    raise RuntimeError("Gemini file upload failed to parse response after retries")

Prevention

When it happens

Trigger: The upload endpoint returns a 2xx whose body is not the expected File object JSON (e.g. an HTML page from an intercepting proxy, a truncated body), or Google changes a field format such as createTime so datetime.strptime fails.

Common situations: Corporate proxies or gateways that replace response bodies; partial reads on dropped connections; schema drift between litellm's parser version and the live Files API.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/2ae7c3b4442840c5. Report an issue: GitHub.