TypeScript

Official TypeScript SDK for the VideoGen API.

Install

npm install @videogen/sdk

Create a client

import { VideoGen } from "@videogen/sdk";
const 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:

import { VideoGen } from "@videogen/sdk";
const vg = new VideoGen({ apiKey: "sk_videogen_live_..." });
const run = await vg.workflows.scriptToVideoAndWait({
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.",
visualStyle: {
type: "AI_IMAGE",
aiStyle: "loose watercolor illustration with visible brushstrokes and soft color bleeds",
},
quality: "HIGH",
remixActions: [
{ type: "ENABLE_CAPTIONS" },
{
type: "CONVERT_IMAGES_TO_VIDEOS",
motionPrompt: "slow cinematic push-in",
muteOutputVideos: true,
quality: "HIGH",
},
],
});
console.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:

import { VideoGen, createPublicPreview } from "@videogen/sdk";
const vg = new VideoGen({ apiKey: "sk_videogen_live_..." });
const execution = await vg.tools.generateImageAndWait({
prompt: "A sunset over a calm ocean, cinematic lighting",
});
console.log(execution.status); // "succeeded"
const fileId = execution.results?.[0]?.fileId;
const 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

import { VideoGen, uploadFile } from "@videogen/sdk";
import { readFileSync } from "node:fs";
const vg = new VideoGen({ apiKey: "sk_videogen_live_..." });
const file = await uploadFile({
client: vg,
data: readFileSync("input.mp4"),
displayName: "input.mp4",
type: "VIDEO",
});
console.log(file.fileId); // "vg_file_..."

Download a file

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

Verify a webhook

import { verifyWebhookSignature } from "@videogen/sdk";
const event = verifyWebhookSignature({
rawBody,
headers,
secret: signingSecret,
});
if (event.event === "tool_execution.succeeded") {
console.log(event.results);
}