BerriAI/litellm · error · ValueError

Error parsing file retrieve response

Error message

Error parsing file retrieve response: {e}

What it means

Thrown by GoogleAIStudioFilesHandler.transform_retrieve_file_response when turning a GET /v1beta/files/{id} response into an OpenAIFileObject fails. The parser json-decodes the body, reads file state (mapped to a status), sizeBytes, createTime (strptime with '%Y-%m-%dT%H:%M:%S.%f%z'), displayName, and the error field for FAILED uploads. Any exception in that chain (missing keys, bad timestamp, non-JSON body) is wrapped into this ValueError after being logged with a traceback.

Solutions

  1. Enable verbose logging and read the wrapped exception detail to identify the missing field or timestamp failure
  2. Confirm the file id comes from the create_file response 'id' (a files/... URI) and was created with the same API key
  3. Check the raw GET response with curl: curl -H "x-goog-api-key: $GEMINI_API_KEY" https://generativelanguage.googleapis.com/v1beta/files/<id> and verify file.uri/sizeBytes/createTime/displayName exist
  4. Upgrade litellm in case the Gemini Files response model changed
  5. If files expired (48h TTL), re-upload and persist the new id

Example fix

# before
f = litellm.get_file(file_id=stale_id, custom_llm_provider='gemini')
# ValueError: Error parsing file retrieve response: 'createTime'

# after - poll defensively and re-upload when Gemini's TTL expired the file
try:
    f = litellm.get_file(file_id=stale_id, custom_llm_provider='gemini', api_key=KEY)
except ValueError:
    f = litellm.create_file(file=open('doc.pdf', 'rb'), custom_llm_provider='gemini', api_key=KEY)
    persist_file_id(f.id)
Defensive patterns

Strategy: try-catch

Try / catch

try:
    f = litellm.get_file(file_id=fid, custom_llm_provider='gemini', api_key=KEY)
except ValueError as e:
    if 'Error parsing file retrieve response' in str(e):
        # likely expired (48h TTL), deleted, or cross-project file id
        schedule_reupload(fid)
    else:
        raise

Prevention

When it happens

Trigger: litellm.get_file on a file id that does not exist (Gemini returns an error JSON with no 'file' fields); a FAILED upload whose response shape differs from expectations; state values outside PROCESSING/ACTIVE/FAILED; createTime not matching the expected timestamp format; a proxy returning HTML.

Common situations: Polling a file id saved from an older session after Gemini's 48-hour file TTL expired it; typo'd or truncated file ids; mixing file ids from a different Google project/API key than the one that created them; Gemini API surface changes after upgrading.

Related errors


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

Appendix: source

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

                id=response_json.get("uri", ""),
                bytes=int(response_json.get("sizeBytes", 0)),
                created_at=int(
                    time.mktime(
                        time.strptime(
                            response_json["createTime"].replace("Z", "+00:00"),
                            "%Y-%m-%dT%H:%M:%S.%f%z",
                        )
                    )
                ),
                filename=response_json.get("displayName", ""),
                object="file",
                purpose="user_data",
                status=status,
                status_details=(str(response_json.get("error", "")) if gemini_state == "FAILED" else None),
            )
        except Exception as e:
            verbose_logger.exception("Error parsing file retrieve response: %s", e)
            raise ValueError(f"Error parsing file retrieve response: {e}")

    def transform_delete_file_request(
        self,
        file_id: str,
        optional_params: dict,
        litellm_params: dict,
    ) -> tuple[str, dict]:
        """
        Transform delete file request for Google AI Studio.

        Args:
            file_id: The file URI (e.g., "files/abc123" or full URI)
            optional_params: Optional parameters
            litellm_params: LiteLLM parameters containing api_key

        Returns:
            tuple[str, dict]: (url, params) for the DELETE request
        """

View on GitHub (pinned to 77b7c6c40c)