Python

Official Python SDK for the VideoGen API.

Install

$pip install videogen

Create a client

1from videogen import VideoGenApi
2
3client = VideoGenApi(token="YOUR_API_KEY")

The client reads from the VIDEOGEN_API_KEY environment variable when no token is provided.

Async client

1from videogen import AsyncVideoGenApi
2
3client = AsyncVideoGenApi(token="YOUR_API_KEY")

Run a tool and poll for the result

All tool endpoints are asynchronous. Use poll_executed_tool to wait for the result:

1from videogen import VideoGenApi, poll_executed_tool
2
3client = VideoGenApi(token="YOUR_API_KEY")
4
5response = client.tools.generate_video_clip(
6 prompt="A sunset over a calm ocean, cinematic lighting",
7)
8
9result = poll_executed_tool(client, response.tool_execution_id)
10print(result.status) # "succeeded"
11print(result.results) # generated files

For the async client, use async_poll_executed_tool:

1from videogen import AsyncVideoGenApi, async_poll_executed_tool
2
3client = AsyncVideoGenApi(token="YOUR_API_KEY")
4
5response = await client.tools.generate_video_clip(
6 prompt="A sunset over a calm ocean, cinematic lighting",
7)
8
9result = await async_poll_executed_tool(client, response.tool_execution_id)

Options

OptionTypeDefaultDescription
poll_interval_msint1500Milliseconds between polls.
timeout_msint3600000Maximum wait time before raising.

Upload a file

1from videogen import VideoGenApi, upload_file
2
3client = VideoGenApi(token="YOUR_API_KEY")
4
5with open("input.mp4", "rb") as f:
6 file = upload_file(client, f.read(), display_name="input.mp4", type="VIDEO")
7
8print(file.file_id) # "vg_file_..."

Download a file

1from videogen import VideoGenApi, download_file
2
3client = VideoGenApi(token="YOUR_API_KEY")
4
5download_file(client, "vg_file_...", output_path="output.mp4")

Verify a webhook

1from videogen import verify_webhook_signature
2
3payload = verify_webhook_signature(raw_body, headers, signing_secret)
4
5if payload["event"] == "tool_execution.succeeded":
6 print(payload["results"])