Skip to content

fix: omit mimeType from fileData for YouTube and extensionless URLs#442

Merged
mikehostetler merged 3 commits into
agentjido:mainfrom
Nickcom4:fix/433-google-youtube-mimetype
Feb 20, 2026
Merged

fix: omit mimeType from fileData for YouTube and extensionless URLs#442
mikehostetler merged 3 commits into
agentjido:mainfrom
Nickcom4:fix/433-google-youtube-mimetype

Conversation

@Nickcom4
Copy link
Copy Markdown
Contributor

Summary

  • Extracts build_file_data/2 helper in the Google provider that conditionally includes mimeType
  • When MIME type is nil or "application/octet-stream" (unrecognizable extension), mimeType is omitted entirely from the fileData map
  • This lets Gemini infer the content type from the URI, which is required for YouTube URLs per the Video Understanding docs
  • Also preserves media_type from ContentPart.image_url/1 through the OpenAI encoding layer in defaults.ex

Root cause

infer_mime_type_from_url/1 falls back to "application/octet-stream" for URLs without a recognizable file extension (e.g., youtube.com/watch?v=...). This was unconditionally added to fileData, causing Gemini to reject the request with:

Google API error: Unsupported MIME type: application/octet-stream (400 INVALID_ARGUMENT)

Files changed

File Change
lib/req_llm/providers/google.ex Extract build_file_data/2, conditionally omit mimeType
lib/req_llm/provider/defaults.ex Preserve media_type in encode_openai_content_part for :image_url
test/providers/google_test.exs Update existing test, add 2 new tests (extensionless + YouTube URLs)

Test plan

  • mix test passes (2164 tests, 0 failures)
  • Google provider tests pass (68 tests, 0 failures)
  • mix compile --warnings-as-errors passes
  • New test: extensionless URLs omit mimeType
  • New test: YouTube URLs omit mimeType
  • Existing test: known extensions (.mp4, .jpg, etc.) still produce mimeType

Closes #433

Google's convert_content_part/1 unconditionally added mimeType to
all fileData parts. For YouTube URLs (no file extension), this
resulted in "application/octet-stream" which Gemini rejects with
a 400 error.

Extract build_file_data/2 helper that omits mimeType when the
inferred type is nil or octet-stream, letting Gemini infer it.
Also preserve media_type through OpenAI content part encoding
so explicit types aren't dropped.

Closes agentjido#433
@mikehostetler mikehostetler added the needs_work Changes requested before merge label Feb 20, 2026
@mikehostetler mikehostetler removed the needs_work Changes requested before merge label Feb 20, 2026
@mikehostetler mikehostetler merged commit bae7b32 into agentjido:main Feb 20, 2026
6 checks passed
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.

[Bug]: Google provider adds mimeType to fileData for YouTube URLs, causing Gemini 400 error

2 participants