Gemini Video Generation
Migrate GeminiTools to Veo 3.1 on Vertex AI and save the returned MP4 correctly.
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 the corrections below. See Vertex AI release notes.
"""Example: Using the GeminiTools Toolkit for Video Generation
An Agent using the Gemini video generation tool.
Video generation only works with Vertex AI.
Make sure you have set the GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION environment variables.
Example prompts to try:
- "Generate a 5-second video of a kitten playing a piano"
- "Create a short looping animation of a neon city skyline at dusk"
Run `uv pip install google-genai agno` to install the necessary dependencies.
"""
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.models.gemini import GeminiTools
from agno.utils.media import save_base64_data
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=OpenAIChat(id="gpt-5.6-luna"),
tools=[GeminiTools(vertexai=True)], # Video Generation only works on VertexAI mode
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
agent.print_response(
"create a video of a cat driving at top speed",
)
response = agent.get_last_run_output()
if response and response.videos:
for video in response.videos:
if video.content:
save_base64_data(
base64_data=str(video.content),
output_path=f"tmp/cat_driving_{video.id}.mp4",
)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno google-genai openaiExport environment variables
export GOOGLE_CLOUD_LOCATION="your_google_cloud_location_here"
export GOOGLE_CLOUD_PROJECT="your_google_cloud_project_here"
export OPENAI_API_KEY="your_openai_api_key_here"Authenticate with Google Cloud
Sign in with Application Default Credentials:
gcloud auth application-default loginEnable Vertex AI access
Enable the Vertex AI API and billing in your project, grant the signed-in identity access to generate video, and choose a region supported by the Veo 3.1 model.
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.
Capture the run result
Replace agent.print_response(...) and response = agent.get_last_run_output() with response = agent.run("Create a short video of a cat driving"). The saved example has no database or enabled session cache for the last-run lookup.
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.
Run the example
Save the code above as gemini_video_generation.py, then run:
python gemini_video_generation.pyThe toolkit exposes only a prompt, sets enhance_prompt=True, and polls until the operation finishes without a toolkit timeout. It does not expose duration or other Veo generation settings; the five-second source prompt is not a duration guarantee. Validate the selected model and SDK configuration in your project before relying on the generated result.
Full source: cookbook/91_tools/models/gemini_video_generation.py