TypeScript

Official TypeScript SDK for the VideoGen API.

Install

$npm install @videogen/sdk

Create a client

1import { VideoGen } from "@videogen/sdk";
2
3const vg = new VideoGen({ apiKey: "sk_videogen_live_..." });

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:

1import { VideoGen } from "@videogen/sdk";
2
3const vg = new VideoGen({ apiKey: "sk_videogen_live_..." });
4
5const run = await vg.workflows.scriptToVideoAndWait({
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
24console.log(run.status, run.projectId);

Use projectId for export, remix, 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:

OptionTypeDefaultDescription
pollIntervalMsnumber1500Milliseconds between polls.
timeoutMsnumber3600000Maximum wait time before throwing.
signalAbortSignal(none)Cancel polling early.

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:

1import { VideoGen, createPublicPreview } from "@videogen/sdk";
2
3const vg = new VideoGen({ apiKey: "sk_videogen_live_..." });
4
5const execution = await vg.tools.generateImageAndWait({
6 prompt: "A sunset over a calm ocean, cinematic lighting",
7});
8
9console.log(execution.status); // "succeeded"
10const fileId = execution.results?.[0]?.fileId;
11const preview = await createPublicPreview({ client: vg, fileId });

For start-then-poll yourself, call generateImage then pollExecutedTool({ client: vg, toolExecutionId }). Poll helpers accept the same options as above (pollIntervalMs, timeoutMs, signal).

Upload a file

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

Download a file

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

Verify a webhook

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