Skip to content

fix(vertex_ai/gemini): fix Gemini MIME detection for extensionless GCS URIs (addresses Greptile feedback on #27278) - #27713

Closed
krrish-berri-2 wants to merge 1 commit into
litellm_internal_stagingfrom
cursor/fix-gemini-gcs-mime-greptile-feedback-4a6b
Closed

fix(vertex_ai/gemini): fix Gemini MIME detection for extensionless GCS URIs (addresses Greptile feedback on #27278)#27713
krrish-berri-2 wants to merge 1 commit into
litellm_internal_stagingfrom
cursor/fix-gemini-gcs-mime-greptile-feedback-4a6b

Conversation

@krrish-berri-2

Copy link
Copy Markdown
Contributor

Relevant issues

Addresses Greptile feedback on PR #27278 (Fix Gemini MIME detection for extensionless GCS URIs).

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix
✅ Test

Changes

This PR implements the changes from PR #27278 with all Greptile-identified issues resolved:

Issues Fixed (from Greptile score 3/5)

  1. Event-loop blockingasync_transform_request_body was calling _transform_request_body synchronously, which in turn calls _get_gcs_object_content_type (up to 5s sync httpx.get). Fixed by wrapping with asyncify() to offload to a thread pool worker.

  2. Unmocked test making real HTTP calls — All tests now mock _get_gcs_object_content_type so no real outbound requests are made to storage.googleapis.com.

Core Feature (from PR #27278)

  • GCS metadata lookup: _get_gcs_object_content_type resolves MIME type from GCS Storage JSON API for extensionless gs:// URIs
  • litellm_params propagation: vertex_project/vertex_credentials are threaded from request body through _transform_messages_gemini_convert_messages_with_history_process_gemini_media_get_gcs_object_content_type
  • Security: Anonymous-only requests when no Vertex credentials are supplied (prevents server's default Google credentials from being used as an oracle for private GCS objects on the Google AI Studio path)
  • MIME normalization: _normalize_and_validate_gemini_mime_type normalizes aliases (e.g., image/jpgimage/jpeg) and validates against Gemini's accepted file types
  • Explicit MIME fields: mime_type/content_type accepted as aliases for format in image_url and file content blocks

Tests Added (12 new tests, all mock-only)

  • GCS URI with extension — explicit MIME success path
  • GCS URI without extension — metadata lookup success path
  • GCS URI without extension — clear error when metadata unavailable
  • Metadata MIME alias normalization (image/jpgimage/jpeg)
  • Unsupported MIME type rejection
  • Credential propagation to auth header
  • No-credential path skips auth (security assertion)
  • Event-loop non-blocking verification via concurrent sleep timing
  • Dotted bucket name length validation
  • File block with mime_type field
  • Real extensionless file_id resolution via mocked metadata

Affected files

  • litellm/llms/vertex_ai/gemini/transformation.py
  • litellm/llms/gemini/chat/transformation.py
  • litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py
  • tests/test_litellm/llms/vertex_ai/test_vertex.py
Open in Web Open in Cursor 

…S URIs

Addresses Greptile feedback on PR #27278:

1. Add GCS object metadata lookup via Storage JSON API for extensionless
   gs:// URIs — falls back gracefully when metadata is unavailable
2. Use asyncify() to offload the sync httpx.get call in
   async_transform_request_body so it does not block the event loop
3. Add MIME type normalization and validation via
   _normalize_and_validate_gemini_mime_type
4. Propagate litellm_params (vertex_project/vertex_credentials) through
   _transform_messages → _gemini_convert_messages_with_history so
   private GCS objects can be authenticated
5. Accept mime_type/content_type as aliases for format in image_url and
   file content blocks
6. All new tests use proper mocks — no real outbound HTTP in the test suite

Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.21782% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/vertex_ai/gemini/transformation.py 77.77% 22 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Aug 11, 2026
@github-actions github-actions Bot closed this Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants