Skip to navigation

Python

Official Python SDK for the VideoGen API.

Install

pip install videogen

Create a client

from videogen import VideoGen
vg = VideoGen(api_key="sk_videogen_live_...")

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

Async client

from videogen import AsyncVideoGen
vg = AsyncVideoGen(api_key="sk_videogen_live_...")

Generate a video from a script

Workflows turn a script into a finished video asynchronously. Prefer script_to_video_and_wait when you can block:

from videogen import VideoGen
vg = VideoGen(api_key="sk_videogen_live_...")
run = vg.workflows.script_to_video_and_wait(
script=(
"Staying hydrated keeps your body and mind running at their best. "
"Drinking enough water boosts your energy, focus, and mood. "
"Keep a water bottle nearby and sip throughout the day."
),
visual_style={
"type": "AI_IMAGE",
"ai_style": "Loose watercolor illustration, visible brushstrokes, soft color bleeds, paper texture, muted palette. A clear uncluttered subject centered in the frame, occupying only the middle half of the image, with generous empty margins on all four sides, no background clutter.",
},
quality="HIGH",
auto_export=True,
video_edits=[
{"type": "ENABLE_CAPTIONS"},
{
"type": "CONVERT_IMAGES_TO_VIDEOS",
"motion_prompt": "slow cinematic push-in",
"mute_output_videos": True,
"quality": "HIGH",
},
],
)
print(run.get("download_url") or run.get("downloadUrl"))

Use project_id for export, video edits, and other API calls. project_url (also on the response) is optional: a link to open the project in the VideoGen editor for manual review (team members and project collaborators only).

Request kwargs use snake_case (and nested dict keys); the client serializes body/query keys to camelCase for the API. Responses are plain dicts with snake_case keys.

For start-then-poll yourself, call script_to_video then poll_workflow_run(vg, workflow_run_id). For the async client, use script_to_video_and_wait on AsyncVideoGen (or async_poll_workflow_run):

from videogen import AsyncVideoGen
vg = AsyncVideoGen(api_key="sk_videogen_live_...")
run = await vg.workflows.script_to_video_and_wait(
script="Staying hydrated keeps your body and mind running at their best.",
visual_style={
"type": "AI_IMAGE",
"ai_style": "Loose watercolor illustration, visible brushstrokes, soft color bleeds, paper texture, muted palette. A clear uncluttered subject centered in the frame, occupying only the middle half of the image, with generous empty margins on all four sides, no background clutter.",
},
quality="HIGH",
auto_export=True,
video_edits=[
{"type": "ENABLE_CAPTIONS"},
{
"type": "CONVERT_IMAGES_TO_VIDEOS",
"motion_prompt": "slow cinematic push-in",
"mute_output_videos": True,
"quality": "HIGH",
},
],
)
print(run.get("download_url") or run.get("downloadUrl"))

Options

OptionTypeDefaultDescription
poll_interval_msint1500Milliseconds between polls.
timeout_msint3600000Maximum wait time before raising.
cancel_eventthreading.Event(none)Cancel sync polling early (PollCancelledError).

For the async client, pass asyncio.Event as cancel_event to *_and_wait methods and async poll helpers (async_poll_workflow_run, async_poll_executed_tool, async_poll_project_export, async_poll_public_preview).

Edit a generated video

Choose the video’s editable_video_id from the completed workflow’s outputs:

outputs = run.get("outputs") or []
if outputs:
started = vg.projects.start_video_edits(
project_id=run["project_id"],
editable_video_id=outputs[0]["editable_video_id"],
video_edits=[{"type": "ENABLE_CAPTIONS"}, {"type": "ADD_TRANSITIONS"}],
)
completed = vg.poll_video_edits(
started["project_id"],
video_edit_ids=started["video_edit_ids"],
)
print(completed["video_edits"])

start_video_edits_and_wait combines the start and poll calls with the same request. The async client exposes the same methods with await. Poll only the returned ids so unrelated edit history does not determine completion; when save_as_new_project=True, use the project id returned by the start. To browse history, call list_video_edits(project_id=..., editable_video_id=..., limit=..., cursor=...).

For immediate timeline changes, use the video editing API to inspect the selected video and submit typed edit_video commands with its revision and a new mutation id.

Run a standalone tool

All tool endpoints are asynchronous. Prefer generate_image_and_wait (and the other tool *_and_wait methods). Use create_public_preview when you need a shareable preview URL:

from videogen import VideoGen, create_public_preview
vg = VideoGen(api_key="sk_videogen_live_...")
execution = vg.tools.generate_image_and_wait(
prompt="A sunset over a calm ocean, cinematic lighting",
)
print(execution["status"]) # "succeeded"
file_id = execution["results"][0]["file_id"]
preview = create_public_preview(vg, file_id)

Upload a file

from videogen import VideoGen, upload_file
vg = VideoGen(api_key="sk_videogen_live_...")
with open("input.mp4", "rb") as f:
file = upload_file(vg, f, display_name="input.mp4", type="VIDEO")
print(file["file_id"]) # "vg_file_..."

Download a file

from videogen import VideoGen, download_file
vg = VideoGen(api_key="sk_videogen_live_...")
download_file(vg, "vg_file_...", output_path="output.mp4")

Verify a webhook

from videogen import verify_webhook_signature
payload = verify_webhook_signature(
raw_body=raw_body,
headers=headers,
secret=signing_secret,
)
if payload["event"] == "tool_execution.succeeded":
print(payload["results"])