-
-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Description
Before submitting
☑️ I checked Known Issues
☑️ I searched existing issues
Configuration
- Model:
gemini-2.5-flash - Provider:
Gemini - Interface: API (Docker / n8n)
Bug description
I encountered two issues when using the API with standard OpenAI-compatible image payloads (e.g., from n8n).
1. g4f/tools/media.py Crash
When the API receives image_url as a dictionary {"url": "..."}, media.py crashes with AttributeError. It currently seems to expect a string.
2. Gemini Provider Image Attachment
Even after fixing media.py, Gemini uploads the image successfully but responds with "I cannot see the image."
It seems the f.req payload structure in Gemini.py is outdated compared to the current browser behavior.
Logs
File "/app/g4f/tools/media.py", line 69, in merge_media
path: str = urlparse(part.get("image_url")).path
AttributeError: 'dict' object has no attribute 'decode'
Observations & Local Fixes
I managed to get it working locally with the following changes. I hope this helps in updating the codebase.
For media.py:
I modified merge_media to check if part.get("image_url") is a dict and extract the "url" value.
For Gemini.py (build_request):
I inspected the browser traffic and noticed the payload structure for images has changed.
Updating the structure to the following format solved the issue for me:
# Current implementation in g4f:
# image_list = [[[image_url, 1], image_name]]
# What worked for me (Browser structure):
image_list.append([
[
image_url,
1,
None,
"image/jpeg" # Note: MIME type seems required now (needs to be dynamic)
],
image_name,
None, None, None, None, None, None, # 7 nulls
[0] # [0] suffix
])After applying this structure, Gemini correctly recognized the uploaded image.