Skip to navigation

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, 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",
autoExport: true,
videoEdits: [
{ type: "ENABLE_CAPTIONS" },
{
type: "CONVERT_IMAGES_TO_VIDEOS",
motionPrompt: "slow cinematic push-in",
muteOutputVideos: true,
quality: "HIGH",
},
],
});
console.log(run.downloadUrl);

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:

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

Edit a generated video

Choose the video’s editableVideoId from the completed workflow’s outputs. Edits always target that video explicitly:

const output = run.outputs[0];
if (output != null) {
const started = await vg.projects.startVideoEdits({
projectId: run.projectId,
editableVideoId: output.editableVideoId,
videoEdits: [{ type: "ENABLE_CAPTIONS" }, { type: "ADD_TRANSITIONS" }],
});
const completed = await vg.pollVideoEdits({
projectId: started.projectId,
videoEditIds: started.videoEditIds,
});
console.log(completed.videoEdits);
}

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:

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);
}