{"record":{"id":"758166eacc65f2d6","repo":"BerriAI/litellm","slug":"error-parsing-file-retrieve-response-e","errorCode":null,"errorMessage":"Error parsing file retrieve response: {e}","messagePattern":"Error parsing file retrieve response: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/files/transformation.py","lineNumber":296,"sourceCode":"                id=response_json.get(\"uri\", \"\"),\n                bytes=int(response_json.get(\"sizeBytes\", 0)),\n                created_at=int(\n                    time.mktime(\n                        time.strptime(\n                            response_json[\"createTime\"].replace(\"Z\", \"+00:00\"),\n                            \"%Y-%m-%dT%H:%M:%S.%f%z\",\n                        )\n                    )\n                ),\n                filename=response_json.get(\"displayName\", \"\"),\n                object=\"file\",\n                purpose=\"user_data\",\n                status=status,\n                status_details=(str(response_json.get(\"error\", \"\")) if gemini_state == \"FAILED\" else None),\n            )\n        except Exception as e:\n            verbose_logger.exception(\"Error parsing file retrieve response: %s\", e)\n            raise ValueError(f\"Error parsing file retrieve response: {e}\")\n\n    def transform_delete_file_request(\n        self,\n        file_id: str,\n        optional_params: dict,\n        litellm_params: dict,\n    ) -> tuple[str, dict]:\n        \"\"\"\n        Transform delete file request for Google AI Studio.\n\n        Args:\n            file_id: The file URI (e.g., \"files/abc123\" or full URI)\n            optional_params: Optional parameters\n            litellm_params: LiteLLM parameters containing api_key\n\n        Returns:\n            tuple[str, dict]: (url, params) for the DELETE request\n        \"\"\"","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/gemini/files/transformation.py#L278-L314","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Enable verbose logging and read the wrapped exception detail to identify the missing field or timestamp failure","Confirm the file id comes from the create_file response 'id' (a files/... URI) and was created with the same API key","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","Upgrade litellm in case the Gemini Files response model changed","If files expired (48h TTL), re-upload and persist the new id"],"exampleFix":"# before\nf = litellm.get_file(file_id=stale_id, custom_llm_provider='gemini')\n# ValueError: Error parsing file retrieve response: 'createTime'\n\n# after - poll defensively and re-upload when Gemini's TTL expired the file\ntry:\n    f = litellm.get_file(file_id=stale_id, custom_llm_provider='gemini', api_key=KEY)\nexcept ValueError:\n    f = litellm.create_file(file=open('doc.pdf', 'rb'), custom_llm_provider='gemini', api_key=KEY)\n    persist_file_id(f.id)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    f = litellm.get_file(file_id=fid, custom_llm_provider='gemini', api_key=KEY)\nexcept ValueError as e:\n    if 'Error parsing file retrieve response' in str(e):\n        # likely expired (48h TTL), deleted, or cross-project file id\n        schedule_reupload(fid)\n    else:\n        raise","preventionTips":["Re-check file ids older than ~48h — Gemini expires uploaded files","Always create and retrieve files with the same API key/project","Log the wrapped exception suffix; it names the missing field","Wrap polling loops in try/except that degrades to re-upload instead of crashing"],"tags":["gemini","files-api","response-parsing","retrieve"],"backgroundTag":"api-response-parsing-failed","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}