Skip to content

fix: 修复 gemini 文件类型不支持 image/jpg - #2578

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
xyfacai:fix/gemini-mimetype
Jan 4, 2026
Merged

fix: 修复 gemini 文件类型不支持 image/jpg#2578
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
xyfacai:fix/gemini-mimetype

Conversation

@xyfacai

@xyfacai xyfacai commented Jan 4, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Extended image format support to recognize JPG files alongside JPEG, improving compatibility with legacy image naming conventions.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 4, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The 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

Cohort / File(s) Summary
MIME Type Allowlist Update
relay/channel/gemini/relay-gemini.go
Added "image/jpg": true entry to geminiSupportedMimeTypes map to recognize legacy JPG naming alongside existing JPEG support

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A JPG arrives at the gate,
Once turned away—now it's first-rate!
Legacy formats, both old and new,
Gemini's welcome grows broader too! 📸

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for the image/jpg MIME type to the Gemini relay, which was previously unsupported.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1519e97 and 5ed4583.

📒 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 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.

@Calcium-Ion
Calcium-Ion merged commit 177553a into QuantumNous:main Jan 4, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
fix: 修复 gemini 文件类型不支持 image/jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants