litellm - 💡(How to fix) Fix [Bug]: Unable to add an image file_id on Gemini responses API [1 comments, 2 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#24919Fetched 2026-04-08 02:23:43
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1

Code Example

{
     type: "input_image",
     file_id: uploadedFileId,
},

---

elif item.get("type") == "input_image":
                        if item.get("file_id"):
                            content_list.append(
                                LiteLLMCompletionResponsesConfig._transform_input_file_item_to_file_item(
                                    item
                                )
                            )
                        else:
                            content_list.append(
                                dict(
                                    LiteLLMCompletionResponsesConfig._transform_input_image_item_to_image_item(
                                        item
                                    )
                                )
                            )

---
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?

Trying to add an image uploaded to Gemini to responses API request will fail with Invalid image received - As you can see in that message image_url will be empty. I find the problem and its file_id :

{
     type: "input_image",
     file_id: uploadedFileId,
},

input_image expect a image_url in LiteLLM not a file_id but this is valid OpenAI request.

LiteLLM when see an type: "input_image" assumes it will be a URL, but can be a file_id

https://github.com/BerriAI/litellm/blob/33c3f13443eaf990ac8c6e3da78bddbc2b7d0e7a/litellm/responses/litellm_completion_transformation/transformation.py#L1276-L1283

My hack/fix is added a check for the file_id, and in that case create a file instead of an object:

                    elif item.get("type") == "input_image":
                        if item.get("file_id"):
                            content_list.append(
                                LiteLLMCompletionResponsesConfig._transform_input_file_item_to_file_item(
                                    item
                                )
                            )
                        else:
                            content_list.append(
                                dict(
                                    LiteLLMCompletionResponsesConfig._transform_input_image_item_to_image_item(
                                        item
                                    )
                                )
                            )

Again, I'm not on LiteLLM team nor be a Python dev, so maybe it's a bad solution. Anyway it works for me with OpenAI and Gemini models

Steps to Reproduce

  1. Upload an IMAGE to Gemini
  2. Try to ask a gemini model about that file

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.82.6

Twitter / LinkedIn details

No response

extent analysis

TL;DR

Modify the LiteLLM completion transformation to handle file_id for input_image type by creating a file instead of an object when file_id is present.

Guidance

  • Check if the file_id is being passed correctly when uploading an image to Gemini and trying to access it through the LiteLLM API.
  • Verify that the modification to the transformation.py file, as suggested in the issue, resolves the Invalid image received error.
  • Consider testing this fix with different models and image uploads to ensure it works consistently.
  • Review the LiteLLM documentation and code to understand how input_image and file_id are handled, and if there are any other potential issues or edge cases.

Example

elif item.get("type") == "input_image":
    if item.get("file_id"):
        content_list.append(
            LiteLLMCompletionResponsesConfig._transform_input_file_item_to_file_item(
                item
            )
        )
    else:
        content_list.append(
            dict(
                LiteLLMCompletionResponsesConfig._transform_input_image_item_to_image_item(
                    item
                )
            )
        )

Notes

This fix assumes that the issue is specific to the handling of file_id for input_image type in the LiteLLM completion transformation. However, without further testing and review, it's uncertain if this fix will work for all cases or introduce other issues.

Recommendation

Apply the workaround by modifying the transformation.py file as suggested, as it has been reported to work for the user's specific use case with OpenAI and Gemini models.

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

litellm - 💡(How to fix) Fix [Bug]: Unable to add an image file_id on Gemini responses API [1 comments, 2 participants]