Getting Youtube video summary via Gemini AI API

I would like to use the Gemini AI API to get a summary of a Youtube video. How can I change this prompt to the right format? Placing the youtube URL in the text prompt causes the summarization of a different video than the URL.

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=API_key" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
  "contents": [{
    "parts":[{"text": "Could you give a summary of this youtube video"}, {"file_data":{"mime_type": "video/youtube", "file_uri": "https://www.youtube.com/watch?v=_fuimO6ErKI"}}]
    }]
   }'

Hi,
You cannot provide YouTube URLs directly, and the specified mime_type value is not correct.

Given the size of a video file kindly have a look how to use the File API in order to upload the video to a temporary location which can be used with the Gemini AI.

See here: استكشاف الإمكانات البصرية باستخدام Gemini API  |  Google AI for Developers

Hi,

The Gemini team(s) are keeping themselves busy.
Direct linking of Youtube videos has been announced.

You’ll add the URL as a fileData part to your request:

Request JSON: 
{
  "model": "models/gemini-2.0-flash-exp",
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Describe this video clip."
        },
        {
          "fileData": {
            "fileUri": "https://www.youtube.com/watch?v=1XALhtem2h0",
            "mimeType": ""
          }
        }
      ]
    }
  ]
}

The mimeType is optional.

Cheers.

Now you can use youtube url as fileUri and get video summary
{
“fileData”: {
“mimeType”: “video/*”,
“fileUri”: “Modified by moderator”
}

here is the example code:

#!/bin/bash
set -e -E

GEMINI_API_KEY="$GEMINI_API_KEY"
MODEL_ID="gemini-2.5-pro-exp-03-25"
GENERATE_CONTENT_API="streamGenerateContent"

cat << EOF > request.json
{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "fileData": {
              "mimeType": "video/*",
              "fileUri": "https://youtu.be/_5uSbMMOkCQ"
            }
          },
          {
            "text": "Can you provide full transcript and summary of the video?"
          },
        ]
      },
      {
        "role": "model",
        "parts": [
        ]
      },
      {
        "role": "user",
        "parts": [
          {
            "text": "INSERT_INPUT_HERE"
          },
        ]
      },
    ],
    "generationConfig": {
      "responseMimeType": "text/plain",
    },
}
EOF

curl \
-X POST \
-H "Content-Type: application/json" \
"https://generativelanguage.googleapis.com/v1beta/models/${MODEL_ID}:${GENERATE_CONTENT_API}?key=${GEMINI_API_KEY}" -d '@request.json'

2 Likes