Embedding videos

Make generated videos publicly streamable and embed them anywhere with the VideoGen player.

VideoGen videos are private by default. To embed a video on your site, you first enable public preview on the file to get a public playback ID, then pass that ID to the VideoGen player package.

1. Generate a video

Use any video tool (e.g. generateVideoClip) and wait for the execution to complete:

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 response = await pollExecutedTool(client, toolExecutionId);
10const fileId = response.results[0].fileId;

2. Enable public preview

Call the enable public preview endpoint on the generated file. This returns the file with a publicPlaybackId that you’ll pass to the player.

1const file = await client.files.enablePublicPreview(fileId);
2
3console.log(file.publicPlaybackId); // "vg_play_..."

The response includes:

FieldDescription
isPublicPreviewEnabledtrue — public streaming is enabled.
publicPlaybackIdEncoded playback ID (e.g. vg_play_...). Pass this to the player.
publicHlsUrlPublic HLS streaming URL (if you need raw HLS access).

To disable public preview later, call POST /v1/files/{fileId}/disable-public-preview.

3. Install the player

Choose the package for your stack:

$npm install @videogen/player-react

4. Embed the video

Pass the publicPlaybackId from step 2 to the player:

1import { VideoGenPlayer } from "@videogen/player-react";
2
3function VideoEmbed() {
4 return <VideoGenPlayer publicPlaybackId="vg_play_..." autoPlay muted />;
5}

The component accepts these props:

PropTypeDescription
publicPlaybackIdstringRequired. The encoded playback ID from the API.
autoPlaybooleanStart playback automatically.
mutedbooleanStart muted.
loopbooleanLoop playback.
posterstringPoster image URL shown before playback.
thumbnailTimenumberTime (seconds) to use as the poster frame.
startTimenumberTime (seconds) to start playback from.
styleCSSPropertiesInline styles for the player container.
classNamestringCSS class for the player container.

Controlling playback (React)

The React component exposes a ref with playback controls:

1import { useRef } from "react";
2import { VideoGenPlayer, VideoGenPlayerHandle } from "@videogen/player-react";
3
4function VideoWithControls() {
5 const playerRef = useRef<VideoGenPlayerHandle>(null);
6
7 return (
8 <>
9 <VideoGenPlayer ref={playerRef} publicPlaybackId="vg_play_..." />
10 <button onClick={() => playerRef.current?.play()}>Play</button>
11 <button onClick={() => playerRef.current?.pause()}>Pause</button>
12 </>
13 );
14}
Method / PropertyTypeDescription
play()Promise<void>Start playback.
pause()voidPause playback.
currentTimenumberCurrent playback position in seconds.
durationnumberTotal duration in seconds.
pausedbooleanWhether playback is paused.
endedbooleanWhether playback has ended.
mutedbooleanWhether audio is muted.

Using the raw HLS URL

If you prefer to use your own player, the publicHlsUrl field from the enable public preview response is a standard HLS stream URL that works with any HLS-compatible player (hls.js, Video.js, native Safari, etc.):

1const file = await client.files.enablePublicPreview(fileId);
2
3// Use with any HLS player
4const hlsUrl = file.publicHlsUrl; // "https://stream.media.videogen.io/..."