{"record":{"id":"2ae7c3b4442840c5","repo":"BerriAI/litellm","slug":"error-parsing-file-upload-response-e","errorCode":null,"errorMessage":"Error parsing file upload response: {e}","messagePattern":"Error parsing file upload response: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/files/transformation.py","lineNumber":192,"sourceCode":"                id=response_object[\"uri\"],  # Gemini uses URI as identifier\n                bytes=int(response_object[\"sizeBytes\"]),  # Gemini doesn't return file size\n                created_at=int(\n                    time.mktime(\n                        time.strptime(\n                            response_object[\"createTime\"].replace(\"Z\", \"+00:00\"),\n                            \"%Y-%m-%dT%H:%M:%S.%f%z\",\n                        )\n                    )\n                ),\n                filename=response_object[\"displayName\"],\n                object=\"file\",\n                purpose=\"user_data\",  # Default to assistants as that's the main use case\n                status=\"uploaded\",\n                status_details=None,\n            )\n        except Exception as e:\n            verbose_logger.exception(\"Error parsing file upload response: %s\", e)\n            raise ValueError(f\"Error parsing file upload response: {e}\")\n\n    def transform_retrieve_file_request(\n        self,\n        file_id: str,\n        optional_params: dict,\n        litellm_params: dict,\n    ) -> tuple[str, dict]:\n        \"\"\"\n        Get the URL to retrieve a file from Google AI Studio.\n\n        Endpoint:\n        GET https://generativelanguage.googleapis.com/v1beta/{name=files/*}\n\n        The URL should look like:\n        https://generativelanguage.googleapis.com/v1beta/files/{file_id}?key=API_KEY\n\n        We expect file_id to be just the file identifier (e.g., files/abc123 or abc123)\n        as returned by the upload response. (If it's a full URL, extract the file name.)","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/gemini/files/transformation.py#L174-L210","documentation":"Thrown by GoogleAIStudioFilesHandler.transform_create_file_response after a Gemini Files API upload request completes. The handler does raw_response.json(), builds GeminiCreateFilesResponseObject from response_json['file'], then reads uri, sizeBytes, createTime (parsed via time.strptime with '%Y-%m-%dT%H:%M:%S.%f%z') and displayName to build an OpenAIFileObject. Any failure in that chain (non-JSON body, missing key, Pydantic validation error, unparseable timestamp) is caught, logged with a full traceback via verbose_logger.exception, and re-raised wrapped in this ValueError.","triggerScenarios":"litellm.create_file(..., custom_llm_provider='gemini') where the upload endpoint returns an error payload instead of a 'file' object; a file object missing uri/sizeBytes/createTime/displayName; a createTime that does not match the strict '%Y-%m-%dT%H:%M:%S.%f%z' format (e.g. no fractional seconds or an unexpected timezone suffix); or HTML/plain-text from a proxy configured via api_base/GEMINI_API_BASE.","commonSituations":"Custom GEMINI_API_BASE pointing at a gateway that returns HTML error pages; free-tier quota or API-not-enabled errors returned after the upload handshake; Gemini Files API schema drift on newer litellm versions; large-file uploads that were cut off server-side, producing a truncated body.","solutions":["Enable verbose logging (litellm.set_verbose=True or LITELLM_LOG=DEBUG) and read the verbose_logger.exception traceback plus the wrapped '{e}' to see exactly which field/step failed","Inspect the raw response body: the logged exception shows whether the JSON lacks file.uri/sizeBytes/createTime/displayName or whether .json() itself failed","If a proxy/gateway is set via api_base or GEMINI_API_BASE, bypass it or confirm it forwards Gemini's JSON responses unmodified","Upgrade litellm to the latest patch release to pick up any parser fixes for Gemini Files API changes","As a workaround, upload files with the google-genai SDK and pass the resulting file URI into the Gemini chat request"],"exampleFix":"# before\nfile_obj = litellm.create_file(file=open('doc.pdf', 'rb'), custom_llm_provider='gemini')\n# ValueError: Error parsing file upload response: 'uri'\n\n# after - surface the real cause and verify the payload shape first\nimport litellm\nlitellm.set_verbose = True  # traceback shows the underlying KeyError/validation error\ntry:\n    file_obj = litellm.create_file(\n        file=open('doc.pdf', 'rb'),\n        custom_llm_provider='gemini',\n        api_key=GEMINI_KEY,\n    )\nexcept ValueError as e:\n    raise RuntimeError(f'Gemini upload failed, inspect verbose log: {e}') from e","handlingStrategy":"try-catch","validationCode":"import litellm\nfrom litellm.llms.gemini.common_utils import GeminiModelInfo\n\nif not (litellm.params.api_key if hasattr(litellm, 'params') else None) and not GeminiModelInfo.get_api_key():\n    raise RuntimeError('Set GEMINI_API_KEY/GOOGLE_API_KEY before uploading files')","typeGuard":null,"tryCatchPattern":"try:\n    f = litellm.create_file(file=fp, custom_llm_provider='gemini', api_key=KEY)\nexcept ValueError as e:\n    if 'Error parsing file upload response' in str(e):\n        # {e} suffix carries the underlying KeyError/ValidationError/json error\n        log.exception('gemini upload parse failed: %s', e)\n        raise\n    raise","preventionTips":["Keep litellm updated so Gemini Files response-shape fixes land automatically","Point api_base only at proxies proven to pass Google JSON through untouched","Run with LITELLM_LOG=DEBUG during file-flow integration so wrapped parse errors show their true cause","Persist the create_file response id immediately; do not re-derive it by re-parsing"],"tags":["gemini","files-api","response-parsing","upload"],"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"}