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.

Run a tool and poll for the result

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

Options

pollExecutedTool accepts an optional third argument:

OptionTypeDefaultDescription
pollIntervalMsnumber1500Milliseconds between polls.
timeoutMsnumber3600000Maximum wait time before throwing.
signalAbortSignal—Cancel polling early.

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}