fix: 修复 gemini 文件类型不支持 image/jpg - #2578
Conversation
WalkthroughThe change adds "image/jpg" as a supported MIME type to the Gemini relay's whitelist, mapping it to the same compatibility level as "image/jpeg" to support legacy naming conventions without modifying any other logic or behavior. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
relay/channel/gemini/relay-gemini.go
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-08T17:12:43.157Z
Learnt from: RedwindA
Repo: QuantumNous/new-api PR: 1537
File: relay/gemini_handler.go:330-342
Timestamp: 2025-08-08T17:12:43.157Z
Learning: In the new-api repository, the `GeminiEmbeddingHandler` function in `relay/gemini_handler.go` is designed specifically for native Gemini embedding requests and therefore does not require the `ConvertGeminiRequest` step that is used in the chat handler. The embedding requests are already in the native Gemini format and don't need conversion.
Applied to files:
relay/channel/gemini/relay-gemini.go
| "audio/wav": true, | ||
| "image/png": true, | ||
| "image/jpeg": true, | ||
| "image/jpg": true, // support old image/jpeg |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Google Gemini API supported image MIME types image/jpg image/jpeg
💡 Result:
Google's Gemini API accepts the MIME type image/jpeg (use this for .jpg and .jpeg files). The docs list supported image MIME types as image/png, image/jpeg, image/webp (and in some pages also image/heic / image/heif). Use image/jpeg rather than image/jpg. [1][2]
Sources:
- Google Gemini API image understanding docs (supported MIME types list). [1]
- Vertex AI / Gemini image-understanding docs (supported MIME types and examples using mime_type='image/jpeg'). [2]
Remove "image/jpg" — Gemini API does not support this MIME type.
Verification against Google Gemini API documentation shows that the official API only supports image/jpeg, image/png, image/webp, image/heic, and image/heif. The documentation explicitly recommends using image/jpeg rather than image/jpg, and image/jpg is not listed as a supported MIME type.
Adding "image/jpg": true to the whitelist will not provide backwards compatibility since the Gemini API will reject requests with this MIME type. Either remove this entry or update the code to convert image/jpg to image/jpeg before sending to the API.
🤖 Prompt for AI Agents
In relay/channel/gemini/relay-gemini.go around line 35, remove the unsupported
"image/jpg" whitelist entry or normalize incoming images with MIME type
"image/jpg" to "image/jpeg" before sending to Gemini; update the MIME whitelist
to only include Gemini-supported types (image/jpeg, image/png, image/webp,
image/heic, image/heif) and, if you choose normalization, add a small pre-send
step that rewrites any "image/jpg" content-type to "image/jpeg" so requests are
accepted by the Gemini API.
fix: 修复 gemini 文件类型不支持 image/jpg
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.