feat: add video_url support for multimodal video content#417
Open
rafalzawadzki wants to merge 1 commit intoOpenRouterTeam:mainfrom
Open
feat: add video_url support for multimodal video content#417rafalzawadzki wants to merge 1 commit intoOpenRouterTeam:mainfrom
rafalzawadzki wants to merge 1 commit intoOpenRouterTeam:mainfrom
Conversation
Video files (type: "file" with mediaType: "video/*") were falling through
to the generic file handler, which caused two issues:
1. The AI SDK would download video URLs client-side before sending them,
because video/* was not in supportedUrls. This meant YouTube URLs
(which aren't downloadable files) would fail entirely.
2. Video files were sent as { type: "file", file: { file_data } } instead
of { type: "video_url", video_url: { url } }, which is the format
documented at openrouter.ai/docs/guides/overview/multimodal/videos.
This commit:
- Adds video/* and audio/* to supportedUrls in both chat and completion
models, so the AI SDK passes video/audio URLs through without downloading
- Adds a video-specific handler in convertToOpenRouterChatMessages that
converts video file parts to the video_url format
- Adds ChatCompletionContentPartVideo type
Tested with YouTube URLs through Google AI Studio provider — both
generateText and generateObject work correctly with Gemini 2.5 Flash.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
08afcb6 to
2830319
Compare
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
Adds support for passing video URLs through to OpenRouter's
video_urlformat, enabling multimodal video analysis (e.g., YouTube URLs via Gemini through OpenRouter).Problem
Without this change, the Vercel AI SDK downloads video URLs client-side (converting to base64) because
video/*is not in the provider'ssupportedUrls. This breaks YouTube URL support since OpenRouter proxies to Google AI Studio, which natively handles YouTube URLs viavideo_url— but only if the URL is passed through as-is.Changes
video/*andaudio/*tosupportedUrlsin bothchat/index.tsandcompletion/index.ts— prevents the AI SDK from downloading video/audio URLs client-sidevideo_urlmessage format handler inconvert-to-openrouter-chat-messages.ts— convertstype: "file"withvideo/*mediaType to OpenRouter's{ type: "video_url", video_url: { url } }format (docs)ChatCompletionContentPartVideotype inopenrouter-chat-completions-input.ts