generateContent request.
Before you begin
You need:- A LinkModel API key with access to a compatible Gemini model, such as
gemini-3.1-flash-lite. - A local video file. The examples below use
sample.mp4with MIME typevideo/mp4. curlandjq.
https://api.linkmodel.ai/v1. The Gemini-native request uses https://api.linkmodel.ai/v1beta.
1. Calculate file metadata
The upload session requires the exact file size and a hexadecimal MD5 checksum.2. Create a Gemini upload session
md5sum in the session request is hexadecimal. Any Content-MD5 upload header is the Base64 value returned by the server. Do not convert or interchange them. Header names are case-insensitive, so avoid extracting them by an assumed capitalization.3. Upload the video bytes
Send the file directly to the returned pre-signed URL. Use the returned upload headers and values unchanged.200 with an empty or very small body. The pre-signed URL and its headers are credentials for this upload; do not log or share them.
4. Complete the upload
After the direct upload succeeds, notify LinkModel so processing can begin:202 response means processing has started. It does not mean the file is ready for Gemini yet.
5. Wait until the file is active
Poll the file resource until it becomes active or reaches the timeout:gs:// URI unchanged. It is an account-scoped Gemini reference, not a public download URL.
6. Analyze the video with Gemini
Reference the active file URI usingfileData.fileUri and include the matching MIME type:
code, data, and msg business envelope:
7. Delete the file
Delete the uploaded file when you no longer need it:Complete runnable example
The following script runs the complete lifecycle and attempts to delete the remote file even when a later step fails. It usesgemini-3.1-flash-lite and keeps temporary response files outside your project directory.