TypeScript

Official TypeScript SDK for the VideoGen API.

Install

$npm install @videogen/sdk

Create a client

1import { VideoGenClient } from "@videogen/sdk";
2
3const client = new VideoGenClient({ token: "YOUR_API_KEY" });

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

Generate a video from a script

Workflows turn a script into a finished video asynchronously. Use pollWorkflowRun to wait for the run:

1import { VideoGenClient, pollWorkflowRun } from "@videogen/sdk";
2
3const client = new VideoGenClient({ token: "YOUR_API_KEY" });
4
5const { workflowRunId, projectUrl } = await client.workflows.scriptToVideo({
6 script:
7 "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.",
8 visualStyle: {
9 type: "AI_IMAGE",
10 aiStyle: "loose watercolor illustration with visible brushstrokes and soft color bleeds",
11 },
12 quality: "HIGH",
13 remixActions: [
14 { type: "ENABLE_CAPTIONS" },
15 {
16 type: "CONVERT_IMAGES_TO_VIDEOS",
17 motionPrompt: "slow cinematic push-in",
18 muteOutputVideos: true,
19 quality: "HIGH",
20 },
21 ],
22});
23
24const run = await pollWorkflowRun(client, workflowRunId);
25console.log(run.status, projectUrl); // "succeeded", project URL

Options

pollWorkflowRun accepts an optional third argument:

OptionTypeDefaultDescription
pollIntervalMsnumber1500Milliseconds between polls.
timeoutMsnumber3600000Maximum wait time before throwing.
signalAbortSignalCancel polling early.

Run a standalone tool

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

1import { VideoGenClient, pollExecutedTool } from "@videogen/sdk";
2
3const client = new VideoGenClient({ token: "YOUR_API_KEY" });
4
5const { toolExecutionId } = await client.tools.generateVideoClip({
6 prompt: "A sunset over a calm ocean, cinematic lighting",
7});
8
9const result = await pollExecutedTool(client, toolExecutionId);
10console.log(result.status); // "succeeded"
11console.log(result.results); // generated files

pollExecutedTool accepts the same options as pollWorkflowRun (pollIntervalMs, timeoutMs, signal).

Upload a file

1import { VideoGenClient, uploadFile } from "@videogen/sdk";
2import { readFileSync } from "node:fs";
3
4const client = new VideoGenClient({ token: "YOUR_API_KEY" });
5
6const file = await uploadFile(client, readFileSync("input.mp4"), {
7 displayName: "input.mp4",
8 type: "VIDEO",
9});
10
11console.log(file.fileId); // "vg_file_..."

Download a file

1import { VideoGenClient, downloadFile } from "@videogen/sdk";
2
3const client = new VideoGenClient({ token: "YOUR_API_KEY" });
4
5// Stream to disk
6await downloadFile(client, "vg_file_...", { outputPath: "output.mp4" });
7
8// Or get the raw Response
9const response = await downloadFile(client, "vg_file_...");
10const bytes = await response.arrayBuffer();

Verify a webhook

1import { verifyWebhookSignature } from "@videogen/sdk";
2
3const event = verifyWebhookSignature(rawBody, headers, signingSecret);
4
5if (event.event === "tool_execution.succeeded") {
6 console.log(event.results);
7}