Fix Vertex AI Gemini default mimeType when emitting fileData for HTTPS image URLs#206
Open
Jessica Alder (jessicaalder-lgtm) wants to merge 1 commit intomainfrom
Open
Fix Vertex AI Gemini default mimeType when emitting fileData for HTTPS image URLs#206Jessica Alder (jessicaalder-lgtm) wants to merge 1 commit intomainfrom
Jessica Alder (jessicaalder-lgtm) wants to merge 1 commit intomainfrom
Conversation
Alex Z (CLowbrow)
added a commit
that referenced
this pull request
Apr 29, 2026
Vetex was having issues without mime types shamelessly copying #206 --------- Co-authored-by: Alex Z <alex.zelenskiy@braintrustdata.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Customers using Vertex AI Gemini models in the playground (and any caller flowing through gateway → lingua → Vertex) get a 400 from Vertex when sending file/image content parts whose URL is an HTTPS link rather than a base64 data URL:
The same payload against the standalone Gemini provider succeeds. Seems like server-side tolerance difference (v1beta is permissive; Vertex v1 is strict), not a routing difference. Any chat-completions API call to a Vertex Gemini model where the input contains a File message image_url content part with an HTTPS URL.
Root cause
crates/lingua/src/providers/google/convert.rs:380-413converts a UniversalUserContentPart::Imageto a GooglePart.Three branches:
data:…;base64,…data URLinline_datahttp(s)://…URLfile_datamedia_type(Option<String>, may beNone) ✗inline_datamedia_type.unwrap_or(DEFAULT_MIME_TYPE)✓The HTTPS branch was the only one missing a fallback. When the OpenAI chat-completions input converter at
crates/lingua/src/providers/openai/convert.rs:3134-3141sees an HTTPS URL, it setsmedia_type: None. ThatNoneflowed untouched into the Google emit, producingfileData: { fileUri: "...", mimeType: null }. Vertex rejects.The existing
multimodalRequestpayload-test snapshot had this buggy output captured (fileDatawith nomimeType), so it never caught the issue.Fix
Fallback chain at the Google output boundary:
URL inference uses a new
util/media::mime_type_from_urlhelper:response-content-typequery param on S3 presigned URLs (handled by existingparse_file_metadata_from_url).Noneif neither matches; caller appliesDEFAULT_MIME_TYPEas last resort.Fixing at the Google output boundary (rather than the OpenAI input boundary) protects all upstream sources. The Universal
UserContentPart::Image.media_typeisOption<String>by design, so any producer (Anthropic input, direct construction) can legally produceNone.Tests
convert.rs::testsforImage { image: <HTTPS URL>, media_type: None }— fails before the fix, passes after.media_typeprecedence, URL-without-extension fallback toDEFAULT_MIME_TYPE, and a regression guard for the unaffected data-URL branch.mime_type_from_url(S3 presigned content-type override, extension matching including uppercase, unknown/missing extensions, data URLs, invalid URLs).multimodalRequestUrlImagepayload case inpayloads/cases/advanced.ts— exercises the previously-uncovered HTTPS-URL converter branch.multimodalRequest > request 1snapshot, which had captured the buggy pre-fix output (nomimeTypeonfileData).Downstream
This is the lingua side of the fix. After this merges, the gateway needs the lingua submodule pointer bumped in the
braintrustrepo (one-line change inlinguasubmodule SHA on a follow-up braintrust PR), then deployed.