Method Signature
def generate_videos (
self ,
* ,
model : str ,
prompt : Optional[ str ] = None ,
image : Optional[Image] = None ,
video : Optional[Video] = None ,
source : Optional[GenerateVideosSource] = None ,
config : Optional[GenerateVideosConfig] = None ,
) -> GenerateVideosOperation
async def generate_videos (
self ,
* ,
model : str ,
prompt : Optional[ str ] = None ,
image : Optional[Image] = None ,
video : Optional[Video] = None ,
source : Optional[GenerateVideosSource] = None ,
config : Optional[GenerateVideosConfig] = None ,
) -> GenerateVideosOperation
Description
Generates videos based on input (text, image, or video) using Veo models. This is a long-running operation that returns immediately with an operation object that can be polled for completion.
Supported use cases:
Text to video - Generate video from text prompt
Image to video - Animate a static image (with optional text prompt)
Image to video with interpolation - Generate video between two frames
Video extension - Extend an existing video (with optional text prompt)
Parameters
The Veo model to use for generation. Examples:
'veo-2.0-generate-001'
'veo-001'
The input source for video generation (recommended). Text description for the video
Note: Use source instead of the individual prompt, image, video parameters (which are deprecated).
Text prompt for video generation. Deprecated - use source.prompt instead.
Input image for image-to-video. Deprecated - use source.image instead.
Input video for video extension. Deprecated - use source.video instead.
Configuration for video generation. Number of videos to generate (default: 1)
Duration of generated video in seconds. Examples: 5.0, 8.0, 10.0
Aspect ratio of the video. Options:
'16:9' - Landscape (default)
'9:16' - Portrait
'1:1' - Square
Video resolution. Options: Frames per second. Examples: 24, 30 Vertex AI only
Random seed for reproducible generation. Vertex AI only
Text describing what to avoid in the video. Example: 'shaky, blurry, low quality'
Automatically enhance the prompt for better results (default: false)
Policy for generating videos with people. Options:
'DONT_ALLOW'
'ALLOW_ADULT'
End frame for frame interpolation (image-to-video mode). When provided with a start image, generates video interpolating between the two frames.
reference_images
list[VideoGenerationReferenceImage]
Reference images for style or subject consistency.
Mask for selective video generation/editing. Vertex AI only
Generate audio for the video (default: false) Vertex AI only
Google Cloud Storage URI to save generated videos. Example: 'gs://my-bucket/videos/' Vertex AI only
Video compression quality (0-100) Vertex AI only
Pub/Sub topic for completion notifications. Example: 'projects/my-project/topics/video-complete' Vertex AI only
Response
Returns a GenerateVideosOperation object for long-running operation tracking.
The operation name/ID for polling
Whether the operation is complete
Operation metadata including progress information
Error information if the operation failed
The result when operation completes successfully. Show GenerateVideosResponse properties
List of generated videos. Show GeneratedVideo properties
The generated video object with:
.uri - GCS URI or data URI
.video_bytes - Raw video bytes
.mime_type - Video MIME type
Number of videos filtered by Responsible AI systems
rai_media_filtered_reasons
Reasons videos were filtered
Code Examples
Text to Video Generation
import time
from google import genai
from google.genai import types
client = genai.Client( vertexai = True , project = 'my-project' , location = 'us-central1' )
# Start video generation
operation = client.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
prompt = 'A neon hologram of a cat driving at top speed' ,
),
)
print ( f "Operation started: { operation.name } " )
# Poll until complete
while not operation.done:
time.sleep( 10 )
operation = client.operations.get(operation.name)
print ( f "Status: { 'Done' if operation.done else 'In progress...' } " )
# Access the result
if operation.result:
video_uri = operation.result.generated_videos[ 0 ].video.uri
print ( f "Video generated: { video_uri } " )
else :
print ( f "Error: { operation.error } " )
Image to Video with Configuration
from google.genai import types
operation = client.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
image = types.Image.from_file( 'input.jpg' ),
prompt = 'The scene comes to life with gentle movement' ,
),
config = types.GenerateVideosConfig(
duration_seconds = 8.0 ,
aspect_ratio = '16:9' ,
resolution = '1080p' ,
fps = 30 ,
)
)
print ( f "Operation: { operation.name } " )
Frame Interpolation (Image to Video)
operation = client.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
image = types.Image.from_file( 'start_frame.jpg' ),
),
config = types.GenerateVideosConfig(
last_frame = types.Image.from_file( 'end_frame.jpg' ),
duration_seconds = 5.0 ,
)
)
# The model generates smooth transitions between the two frames
Video Extension
operation = client.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
video = types.Video.from_uri( 'gs://my-bucket/input.mp4' , 'video/mp4' ),
prompt = 'Continue the scene with the character walking forward' ,
),
config = types.GenerateVideosConfig(
duration_seconds = 5.0 ,
)
)
With Negative Prompt and Safety Controls
operation = client.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
prompt = 'A person dancing in a vibrant city' ,
),
config = types.GenerateVideosConfig(
negative_prompt = 'shaky camera, blurry, distorted, low quality' ,
person_generation = 'ALLOW_ADULT' ,
duration_seconds = 8.0 ,
enhance_prompt = True ,
)
)
Save to Cloud Storage with Audio
operation = client.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
prompt = 'A waterfall in a lush forest' ,
),
config = types.GenerateVideosConfig(
duration_seconds = 8.0 ,
generate_audio = True ,
output_gcs_uri = 'gs://my-bucket/videos/' ,
compression_quality = 90 ,
)
)
With Pub/Sub Notification
operation = client.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
prompt = 'A futuristic spaceship flying through space' ,
),
config = types.GenerateVideosConfig(
pubsub_topic = 'projects/my-project/topics/video-complete' ,
output_gcs_uri = 'gs://my-bucket/videos/' ,
)
)
print ( f "Operation { operation.name } will notify { config.pubsub_topic } when done" )
Async Usage
import asyncio
from google import genai
from google.genai import types
client = genai.Client( vertexai = True , project = 'my-project' , location = 'us-central1' )
async def generate ():
operation = await client.aio.models.generate_videos(
model = 'veo-2.0-generate-001' ,
source = types.GenerateVideosSource(
prompt = 'A robot exploring an alien planet' ,
),
)
print ( f "Operation started: { operation.name } " )
# Poll until complete
while not operation.done:
await asyncio.sleep( 10 )
operation = await client.aio.operations.get(operation.name)
if operation.result:
print ( f "Video: { operation.result.generated_videos[ 0 ].video.uri } " )
asyncio.run(generate())
Operation Polling
Video generation is a long-running operation. You must poll the operation to check completion:
import time
def wait_for_operation ( client , operation ):
"""Poll operation until complete."""
while not operation.done:
time.sleep( 10 )
operation = client.operations.get(operation.name)
if operation.metadata:
progress = operation.metadata.get( 'progress' , 0 )
print ( f "Progress: { progress } %" )
if operation.error:
raise Exception ( f "Operation failed: { operation.error } " )
return operation.result
# Use it
operation = client.models.generate_videos( ... )
result = wait_for_operation(client, operation)
print ( f "Video: { result.generated_videos[ 0 ].video.uri } " )
Notes
Video generation typically takes 3-10 minutes depending on duration and settings
Use source parameter instead of deprecated prompt, image, video parameters
The operation returns immediately; you must poll for completion
Use Pub/Sub notifications for production systems instead of polling
Some configuration options are only available on Vertex AI
Videos may be filtered by Responsible AI systems
Higher resolution and longer duration increase generation time
The enhance_prompt feature can improve results but may alter your intent