Skip to main content
Use Veo 3.1 through GeminiTools on Vertex AI and decode the returned base64 content before saving the MP4.
Google discontinued the example’s default veo-2.0-generate-001 endpoint after June 30, 2026 and recommends veo-3.1-generate-001. The source also converts video.content to the string representation of a bytes object, which corrupts the saved MP4. Apply both corrections below. See Vertex AI release notes.
gemini_video_generation.py

Run the Example

1

Set up your virtual environment

2

Install dependencies

3

Export environment variables

4

Authenticate with Google Cloud

Sign in with Application Default Credentials:
5

Use Veo 3.1

Replace GeminiTools(vertexai=True) with GeminiTools(vertexai=True, video_generation_model="veo-3.1-generate-001", enable_generate_image=False) in the saved file.
6

Decode the returned content

Replace base64_data=str(video.content) with base64_data=video.content.decode("utf-8") so save_base64_data() receives the base64 string instead of a bytes representation.
7

Run the example

Save the code above as gemini_video_generation.py, then run:
Full source: cookbook/91_tools/models/gemini_video_generation.py