Video REST

quickstartsrestgemini-cookbookgemini-apigemini
Copyright 2025 Google LLC.
[ ]

Gemini API: Video prompting with REST

This notebook provides quick code examples that show you how to prompt the Gemini API using a video file with curl. In this case, you'll use a short clip of Big Buck Bunny.

You can run this in Google Colab, or you can copy/paste the curl commands into your terminal.

Set up the environment

To run this notebook, your API key must be stored it in a Colab Secret named GOOGLE_API_KEY. If you are running in a different environment, you can store your key in an environment variable. See Authentication to learn more.

Authentication Overview

Important: The File API uses API keys for authentication and access. Uploaded files are associated with the API key's cloud project. Unlike other Gemini APIs that use API keys, your API key also grants access data you've uploaded to the File API, so take extra care in keeping your API key secure. For best practices on securing API keys, refer to the API console support center.

[ ]

Install jq to help with processing of JSON API responses.

[ ]

Use a video file with the Gemini API

The Gemini API accepts video file formats through the File API. The File API accepts files under 2GB in size and can store up to 20GB of files per project. Files last for 2 days and cannot be downloaded from the API. For this example, you will use the short film "Big Buck Bunny".

"Big Buck Bunny" is (C) Copyright 2008, Blender Foundation / www.bigbuckbunny.org and licensed under the Creative Commons Attribution 3.0 License.

Note: In Colab, you can also upload your own files to use.

[ ]

With the video file now available locally, generate some metadata that you will use in subsequent steps.

[8]
./BigBuckBunny_320x180.mp4 video/mp4 64657027

Start the upload task

Media uploads in the File API are resumable, so the first step is to define an upload task. This initial request gives you a reference you can use for subsequent upload operations, and allows you to query the status of the upload before sending data, in case of network issues during the data transfer.

The API returns the upload URL in the x-goog-upload-url header, so take note of that in the response headers - you will send the payload data to this URL.

No payload data (video bytes) are sent in this initial request.

[15]
HTTP/2 200 

Upload video data

Now that you have created the upload task, you can upload the file data by sending bytes to the returned upload URL.

[16]
{
  "file": {
    "name": "files/4if4o2bqvugf",
    "displayName": "Big Buck Bunny",
    "mimeType": "video/mp4",
    "sizeBytes": "64657027",
    "createTime": "2024-08-26T08:24:56.068012Z",
    "updateTime": "2024-08-26T08:24:56.068012Z",
    "expirationTime": "2024-08-28T08:24:56.049455995Z",
    "sha256Hash": "Zjc4ZjM5NjAzZTY3NzQ5MDdmMmZhYWZhYmYyNmE2NjdmNGE2ZmMzMTc2OWVjMzA0YThhOGY3YzYyZDI4MDUwOA==",
    "uri": "https://generativelanguage.googleapis.com/v1beta/files/4if4o2bqvugf",
    "state": "PROCESSING"
  }
}

Get file info

After uploading the file, you can verify the API has successfully received the files by querying the files.get endpoint.

files.get lets you see the file uploaded to the File API that are associated with the Cloud project your API key belongs to. Only the name (and by extension, the uri) are unique.

[19]
{
  "name": "files/4if4o2bqvugf",
  "displayName": "Big Buck Bunny",
  "mimeType": "video/mp4",
  "sizeBytes": "64657027",
  "createTime": "2024-08-26T08:24:56.068012Z",
  "updateTime": "2024-08-26T08:25:03.977029Z",
  "expirationTime": "2024-08-28T08:24:56.049455995Z",
  "sha256Hash": "Zjc4ZjM5NjAzZTY3NzQ5MDdmMmZhYWZhYmYyNmE2NjdmNGE2ZmMzMTc2OWVjMzA0YThhOGY3YzYyZDI4MDUwOA==",
  "uri": "https://generativelanguage.googleapis.com/v1beta/files/4if4o2bqvugf",
  "state": "ACTIVE",
  "videoMetadata": {
    "videoDuration": "596s",
    "videoThumbnailBytes": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAC0AUADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipq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2OOeDmiVVV8KxbKqTlduMjpjJz9eKVm24QjLqTuYH5TnGMdRxz09eaaGVvvIox02/LnPbvk+g471kZDQ7DOcH0wMY/nU73AA+UlVHRee/XnH9KrnDckFl/hJI59eCOP8APcECsEIIBBO4k8NjHTjAzn9MUGim+i8r3bt2vpf9WOZmZSrEnIwCe1RRYB3FS2CNoGOWHOM9sgdcGlVjEMj5uenTt+PpUrMz/vGOSxYEdGG3A5HbOensaCLt63d1+V119X5gCpZ1Vdocll5zsI6EcDOM+1IR8yrlTlcgqc4UdF9wOcHjPPAxUTPjBRmD85YfL9MryDx7/wBMACAEh8txgbWDHBDEqw3bWGMZweCeDQVdWto/mlpdO3be+nTUGYr0DDIYHcuOuOnJ6dfZtp7UiDc6k4GAQzfXpx+B4zTZlJ2k8DnB656Z47Y4+uabl19Fz6jOfzxQTpp+K27dd3ffTboPf5cIfvLkn/gWP8KE4YEckEYX16557flzTDySfXBP17nPvxx2qfGc9eGYDH95cYb8Mnj9aA63XRJ+lrL8HodDRRRXQeuFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUrLsvuQrLsvuQUUUUWXZfcgsuy+5BRRRRZdl9yCy7L7kFc5MxE0gB9Ow96KK0ppa6Lp0XmZ1IxdrxT33S8hLYB4xuAOAuM9s5/wFWI+/wCH9aKKKiWmi69F5GXLH+WP3L/IePvpwD1HI9cVdZRlhzwWP6LRRWFTp8/0MFvL1/RFCT/WL9W/9CWmnp/21X+YoorQ6Rh++34fzagnCNwDyvUZ9aKKAIV/i/3T/SkkVVBwAMg5x7CiigCSZQrYA6EjJ5J6Yye+M8VEfuN+H8moooAliRX3ZzxjGD65/wAKfH3/AOuY/rRRQB//2Q=="
  }
}

Wait for processing

Once the file is uploaded, the file service will perform some pre-processing to prepare the video for use in the LLM. For simple media types this is typically a negligible amount of time, but for video content you may need a short wait.

You can use the state field to query if the video is ready for use. If you use it in a prompt prematurely you will see an error like The File ... is not in an ACTIVE state and usage is not allowed.

[ ]
Processing video...
Processing video...
Processing video...
Video is now ACTIVE.

Prompt with the video

Now that the video is uploaded and processed, you can reference it in a prompt.

When assembling your contents, the video can be referenced using a file_data part, like this:

{
  "file_data": {
    "mime_type": "video/mp4",
    "file_uri": "https://uri/from/previous/steps"
  }
}

Try it yourself with this request.

[ ]
MODEL_ID
[ ]
{
  "parts": [
    {
      "text": "This is a 3D animated short film about a big bunny that gets tired of his usual diet of grass. He wants to try something different like fruit and learns the value of what he has. The film's title is Big Buck Bunny. "
    }
  ],
  "role": "model"
}

Further reading

The File API lets you upload a variety of multimodal MIME types, including images, audio, and video formats. The File API handles inputs that can be used to generate content with the content generation endpoint.

  • Read the File API reference.

  • Learn more about prompting with media files in the docs, including the supported formats and maximum length.