500 error when trying send video from YouTube URL

I’m trying to create a bot that analyzes the content of a YouTube video link. From this documentation it seemed to me that Gemini 2.0 could do this. But this code returns error 500

async def process_youtube_link(file_uri: str, video_prompt: str) -> str:
    
    try:
        video_part = types.Part.from_uri(
            file_uri=file_uri,
            mime_type="video/mp4",  
        )

        response = client.models.generate_content(
            model='gemini-2.0-flash-exp',
            contents=[
                video_part,
                video_prompt,  
            ]
        )

        if not response or not hasattr(response, "text"):
            return "Error"

        return response.text.strip()

    except Exception as e:
        return "Error"

What am I doing wrong?

Hey @sylar113, Welcome to the forum.

The reason you’re getting 500 error is because you’re initializing the client using a Gemini API key, like this: client = genai.Client(api_key=GOOGLE_API_KEY).

To process YouTube URLs directly, you need to initialize the client using your GCP project ID, like this: client = genai.Client(vertexai=True, project=PROJECT_ID, location=LOCATION).

Below is the Colab gist I tried, please have a look.

Notebook

Thanks!