litellm - ✅(Solved) Fix [Bug]: Gemini file retrieval fails: Error parsing file retrieve response [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24626Fetched 2026-04-08 01:37:34
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×3closed ×1cross-referenced ×1

Error Message

raise ValueError(f"Error parsing file retrieve response: {str(e)}") This makes it impossible to know when an uploaded file becomes ready (ACTIVE), causing https://litellm/v1beta/models/gemini-2.5-flash:generateContent to fail with the error: The File <file_id> is not in an ACTIVE state and usage is not allowed

Fix Action

Fixed

PR fix notes

PR #24662: feat(gemini): normalize AI Studio file retrieve URL

Description (problem / solution / changelog)

Summary

Fixes #24626 Normalizes Google AI Studio file IDs for transform_retrieve_file_request: raw ids, files/{id}, and full generativelanguage.googleapis.com URLs all produce .../v1beta/files/{id}?key=....

<img width="1182" height="775" alt="image" src="https://github.com/user-attachments/assets/61486438-1b72-4fc0-bb9e-5137feaa9802" />

Changed files

  • litellm/llms/gemini/files/transformation.py (modified, +46/-13)
  • tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py (modified, +52/-19)

Code Example

File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1892, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/files/main.py", line 293, in afile_retrieve
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/files/main.py", line 287, in afile_retrieve
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/custom_httpx/llm_http_handler.py", line 4044, in async_retrieve_file
    return provider_config.transform_retrieve_file_response(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        raw_response=response,
        ^^^^^^^^^^^^^^^^^^^^^^
        logging_obj=logging_obj,
        ^^^^^^^^^^^^^^^^^^^^^^^^
        litellm_params=litellm_params,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/files/transformation.py", line 276, in transform_retrieve_file_response
    raise ValueError(f"Error parsing file retrieve response: {str(e)}")

---
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When using LiteLLM Proxy with Google AI Studio (Gemini), file upload works, but GET https://litellm/v1/files/<file_id> always returns 500:

File "/usr/lib/python3.13/site-packages/litellm/utils.py", line 1892, in wrapper_async
    result = await original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/files/main.py", line 293, in afile_retrieve
    raise e
  File "/usr/lib/python3.13/site-packages/litellm/files/main.py", line 287, in afile_retrieve
    response = await init_response
               ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/site-packages/litellm/llms/custom_httpx/llm_http_handler.py", line 4044, in async_retrieve_file
    return provider_config.transform_retrieve_file_response(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        raw_response=response,
        ^^^^^^^^^^^^^^^^^^^^^^
        logging_obj=logging_obj,
        ^^^^^^^^^^^^^^^^^^^^^^^^
        litellm_params=litellm_params,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3.13/site-packages/litellm/llms/gemini/files/transformation.py", line 276, in transform_retrieve_file_response
    raise ValueError(f"Error parsing file retrieve response: {str(e)}")

This makes it impossible to know when an uploaded file becomes ready (ACTIVE), causing https://litellm/v1beta/models/gemini-2.5-flash:generateContent to fail with the error: The File <file_id> is not in an ACTIVE state and usage is not allowed

Steps to Reproduce

  1. upload file ~100 MG mp4 file to gemini: POST https://litellm/v1/files with custom_llm_provider: gemini
  2. Call GET https://litellm/v1/files/<file_id> with file_id from response of step 1

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.82.3

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

The fix involves modifying the transform_retrieve_file_response function in transformation.py to handle the response from the Gemini API correctly.

  • Modify the transform_retrieve_file_response function to catch and handle any exceptions that occur during response parsing.
  • Add error logging to track any issues that arise during file retrieval.

Example code:

# litellm/llms/gemini/files/transformation.py

import logging

def transform_retrieve_file_response(raw_response, logging_obj, litellm_params):
    try:
        # existing code to parse the response
        # ...
    except Exception as e:
        logging_obj.error(f"Error parsing file retrieve response: {str(e)}")
        # return a default or error response
        return {"error": "Failed to parse response"}

Verification

To verify the fix, follow these steps:

  • Upload a file to Gemini using the LiteLLM Proxy.
  • Call the GET https://litellm/v1/files/<file_id> endpoint to retrieve the file status.
  • Check the response to ensure it no longer returns a 500 error.
  • Verify that the file status is correctly updated to "ACTIVE" after upload.

Extra Tips

  • Ensure that the Gemini API is correctly configured and responding as expected.
  • Review the LiteLLM Proxy logs to identify any other potential issues that may be contributing to the problem.
  • Consider adding additional error handling and logging to the transform_retrieve_file_response function to improve debuggability.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING