BerriAI/litellm · error · Exception
Failed to upload file: {response.text}
Error message
Failed to upload file: {response.text} What it means
The final PUT to the resumable upload URL returned a non-200/201 status, so the file content was not (fully) accepted by Gemini. The response body '{response.text}' gives the reason; a fresh upload session is required on retry since resumable URLs are single-use.
Source
Thrown at litellm/rag/ingestion/gemini_ingestion.py:319
"X-Goog-Upload-Command": "upload, finalize",
}
verbose_logger.debug("Uploading file content (%s bytes)", len(file_content))
client: Final = get_async_httpx_client(
llm_provider=httpxSpecialProvider.RAG,
params={"timeout": 300.0}, # Longer timeout for large files
)
response: Final = await client.put(
upload_url,
content=file_content,
headers=headers,
)
if response.status_code not in [200, 201]:
error_msg: Final = f"Failed to upload file: {response.text}"
verbose_logger.error(error_msg)
raise Exception(error_msg)
# Parse response to get file/document ID
try:
response_data: Final = response.json()
# The response should contain the document name or file reference
file_id: Final = response_data.get("name", "") or response_data.get("file", {}).get("name", "")
verbose_logger.debug("Upload complete. File ID: %s", file_id)
return file_id
except Exception as e:
verbose_logger.warning("Could not parse upload response: %s", e)
# Return a placeholder if we can't get the ID
return "uploaded"
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Check the response text for the upload error and retry with a valid file.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/rag/ingestion/gemini_ingestion.py:319 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/9d0dfe2f5073d652.
Report an issue: GitHub.