Implementation:BerriAI Litellm Veo Video Generation Example
| Attribute | Value |
|---|---|
| Sources | cookbook/veo_video_generation.py
|
| Domains | Video Generation, Google Veo, Pass-Through, Cookbook |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
veo_video_generation is a cookbook example demonstrating a complete workflow for generating videos using Google's Veo model through the LiteLLM proxy's Gemini pass-through endpoint, including submission, polling, and download.
Description
This script implements the VeoVideoGenerator class that provides a full video generation pipeline through the LiteLLM proxy:
- generate_video - Initiates video generation by sending a text prompt to the Veo
predictLongRunningendpoint via the LiteLLM proxy's Gemini pass-through (/gemini/v1beta). Returns the operation name for status polling.
- wait_for_completion - Polls the operation status endpoint with exponential backoff (starting at 10 seconds, capping at 30 seconds), checking for completion up to a configurable max wait time (default: 600 seconds). Extracts the video URI from the nested response structure on success.
- download_video - Downloads the generated video file via the LiteLLM proxy, converting Google's file URI (e.g.,
files/abc123) to the proxy's download URL format (files/abc123:download?alt=media). Streams the download with progress reporting.
- generate_and_download - Orchestrates the complete workflow: generate, poll, and download, with auto-generated filenames based on the prompt and timestamp.
The script is configurable via LITELLM_BASE_URL and LITELLM_API_KEY environment variables and includes example prompts for testing.
Usage
Run this script as a standalone example when testing or demonstrating video generation through the LiteLLM proxy with Google's Veo model. Requires a running LiteLLM proxy with Google AI Studio pass-through configured and a Google AI Studio API key with Veo access.
Code Reference
Source Location
cookbook/veo_video_generation.py
Signature
class VeoVideoGenerator:
def __init__(self, base_url: str = "http://localhost:4000/gemini/v1beta", api_key: str = "sk-1234")
def generate_video(self, prompt: str) -> Optional[str]
def wait_for_completion(self, operation_name: str, max_wait_time: int = 600) -> Optional[str]
def download_video(self, video_uri: str, output_filename: str = "generated_video.mp4") -> bool
def generate_and_download(self, prompt: str, output_filename: str = None) -> bool
def main()
Import
# This is a standalone cookbook script, run directly:
# python cookbook/veo_video_generation.py
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
base_url |
str |
Base URL for the LiteLLM proxy with Gemini pass-through. Defaults to "http://localhost:4000/gemini/v1beta".
|
api_key |
str |
API key for LiteLLM proxy authentication. |
prompt |
str |
Text description of the video to generate. |
operation_name |
str |
The operation name returned by generate_video for status polling.
|
max_wait_time |
int |
Maximum polling time in seconds. Defaults to 600.
|
video_uri |
str |
The URI of the generated video for download. |
output_filename |
Optional[str] |
Local filename for the downloaded video. |
Outputs
| Method | Return Type | Description |
|---|---|---|
generate_video |
Optional[str] |
The operation name if generation started, None on failure.
|
wait_for_completion |
Optional[str] |
The video URI if complete, None on timeout or error.
|
download_video |
bool |
True if download succeeded, False otherwise.
|
generate_and_download |
bool |
True if the full workflow succeeded, False otherwise.
|
Usage Examples
import os
# Set environment variables
os.environ["LITELLM_BASE_URL"] = "http://localhost:4000/gemini/v1beta"
os.environ["LITELLM_API_KEY"] = "sk-1234"
# Run from the command line:
# python cookbook/veo_video_generation.py
# Or use programmatically:
from cookbook.veo_video_generation import VeoVideoGenerator
generator = VeoVideoGenerator(
base_url="http://localhost:4000/gemini/v1beta",
api_key="sk-1234",
)
# Generate and download a video
success = generator.generate_and_download(
prompt="A cat playing with a ball of yarn in a sunny garden",
output_filename="cat_video.mp4",
)
# Or step-by-step:
operation = generator.generate_video("Ocean waves at sunset")
if operation:
video_uri = generator.wait_for_completion(operation)
if video_uri:
generator.download_video(video_uri, "ocean.mp4")
Related Pages
- BerriAI_Litellm_Nova_Sonic_Realtime_Example - Another cookbook example using LiteLLM proxy pass-through
- BerriAI_Litellm_Passthrough_Utils - Utilities for pass-through endpoint handling