Skip to main content

Native Gemini input

The project’s GeminiPart represents inlineData, fileData, videoMetadata, and mediaResolution; the native Gemini adapter preserves these request structures. Actual formats, duration, resolution, and processing remain upstream/model dependent. The example sends MP4 in contents[].parts[].inlineData with mimeType: video/mp4 and plain Base64 data, followed by a text question. This understands an existing video without creating video tasks or artifacts. Video generation uses separate endpoints. Use the gateway root, a bare model ID, and :generateContent. The shared runtime uses the gateway-supported Bearer header; existing Gemini SDK examples use x-goog-api-key. Never send the gateway token to a media URL.

File sources and protocol differences

The current Chat content parser’s video_url branch reads only a string, while other DTO helpers can represent a url object. Raw forwarding and conversion may therefore behave differently. Do not assume OpenRouter’s object shape works through every channel. This example selects native Gemini to avoid the mismatch; no backend code was changed. /v1/files does not implement general file management. The audited routes also contain no Gemini /upload/v1beta/files or /v1beta/files management endpoints. When framework uploads fail, inspect the request path and choose supported inline input. Replacing an SDK Base URL alone does not provide Files or Interactions APIs. Public videos, signed URLs, and YouTube support need separate verification; browser playback does not establish server access.

Example limits

The script reads one regular file up to 5 MiB and checks the leading MP4 ftyp marker. It does not fully validate containers/codecs, transcode, extract frames, perform multipart uploads, or download links. Select a small valid MP4 approved for transmission; deployment body and model limits may be stricter. Confirm acceptable videoMetadata and media-resolution values with the target model; this example does not set them. Output requires no prompt block, exactly one STOP candidate, and final text. Thought text is excluded; tool/media results cannot pass as text. One request without retries. No local video decoder dependency; fixtures do not assess video understanding quality. Source: relaykit/dto/gemini.go, relaykit/dto/openai_request.go, and relay/channel/gemini/adaptor.go. See Gemini API and upstream content reference.

Runnable example

Run from the documentation directory. See the REST runtime; keep http-client.mjs beside the script when copying.
阅读中文