BerriAI/litellm · error · Exception
Error fetching file {element}: {response.status_code} {respo
Error message
Error fetching file {element}: {response.status_code} {response.text} What it means
Raised while resolving file references for Gemini batch embeddings: GETting a referenced file (e.g. files/... under generativelanguage.googleapis.com) returned non-200, and the status plus body are embedded. Fires when an input element references a file that is missing or inaccessible.
Source
Thrown at litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py:73
Args:
input: GeminiEmbeddingInput that may contain file references
api_key: Gemini API key
sync_handler: HTTP client
Returns:
Dict mapping file name to {mime_type, uri}
"""
input_list: Final = [input] if isinstance(input, str) else input
resolved_files: Final[dict[str, dict[str, str]]] = {}
for element in input_list:
if isinstance(element, str) and _is_file_reference(element):
url = f"https://generativelanguage.googleapis.com/v1beta/{element}"
headers = {"x-goog-api-key": api_key}
response = sync_handler.get(url=url, headers=headers)
if response.status_code != 200:
raise Exception(f"Error fetching file {element}: {response.status_code} {response.text}")
file_data = response.json()
resolved_files[element] = {
"mime_type": file_data.get("mimeType", ""),
"uri": file_data.get("uri", element),
}
return resolved_files
async def _async_resolve_file_references(
self,
input: GeminiEmbeddingInput,
api_key: str,
async_handler: AsyncHTTPHandler,
) -> dict[str, dict[str, str]]:
"""
Async version of _resolve_file_references.
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Inspect the status/text for the file fetch failure.
- Verify the Gemini file reference and API key permissions.
Example fix
# confirm the files/... reference exists via the Gemini files API.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Triggered when fetching a file element for Gemini batch embedding returns a non-success status.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/b7d282ab176d6ee2.
Report an issue: GitHub.