TypeScript
Install
Create a client
The client reads from the VIDEOGEN_API_KEY environment variable when no apiKey is provided.
Generate a video from a script
Workflows turn a script into a finished video asynchronously. Prefer scriptToVideoAndWait when you can block:
Use projectId for export, video edits, and other API calls. projectUrl (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).
For start-then-poll yourself, call scriptToVideo then pollWorkflowRun({ client: vg, workflowRunId }).
Responses are plain JSON objects (camelCase keys as returned by the API).
Options
pollWorkflowRun and *AndWait accept optional polling options:
Edit a generated video
Choose the video’s editableVideoId from the completed workflow’s outputs. Edits always target that video explicitly:
startVideoEditsAndWait combines the start and poll calls with the same request. Both wait paths follow only the returned edit ids, including when saveAsNewProject: true creates a copy. Use listVideoEdits({ projectId, editableVideoId, limit, cursor }) to browse a video’s edit history. Poll helpers accept signal, pollIntervalMs, timeoutMs, and throwOnFailure.
For immediate timeline changes, use the video editing API to inspect the selected video and submit typed editVideo commands with its revision and a new mutation id.
Run a standalone tool
All tool endpoints are asynchronous. Prefer generateImageAndWait (and the other tool *AndWait methods). Use createPublicPreview when you need a shareable preview URL:
For start-then-poll yourself, call generateImage then pollExecutedTool({ client: vg, toolExecutionId }). Poll helpers accept the same options as above (pollIntervalMs, timeoutMs, signal).