Embedding videos

Make generated files publicly accessible and embed video or audio with the VideoGen player.

VideoGen files are private by default. To share or embed them, call enable public preview on the file. That always returns a permanent public URL (staticPublicPreviewSource) for any file type — images, audio, video, PDFs, and more.

For video and audio embeds, the same call also registers a public playback ID (publicPlaybackId) once streaming is ready. Pass that ID to @videogen/player or @videogen/player-react for a branded player with adaptive streaming.

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 works for any file type — not just video and audio.

1const file = await client.files.enablePublicPreview({ fileId });
2
3console.log(file.staticPublicPreviewSource?.url); // permanent public URL (any type)
4console.log(file.publicPlaybackId); // "vg_play_..." (video/audio embeds, when ready)

The response includes:

FieldDescription
isPublicPreviewEnabledtrue — public access is enabled.
staticPublicPreviewSourcePermanent direct URL for the file (expiresAt is null). Use for images, downloads, <img src>, <audio src>, or any file type.
publicPlaybackIdEncoded playback ID (e.g. vg_play_...) for video and audio embeds. Pass this to @videogen/player. May be omitted until streaming is ready.
publicHlsUrlPublic HLS streaming URL for video/audio (if you need raw HLS access). Prefer publicPlaybackId for embeds.

Which URL should I use?

  • Embedded video or audio playerpublicPlaybackId with @videogen/player (adaptive streaming, branded controls).
  • Direct permanent link (image in a blog post, PDF download, <video src> fallback, etc.) → staticPublicPreviewSource.url.

For video and audio, the endpoint starts a streaming upload if one does not exist yet and polls briefly for the embed playback id. If streaming is still processing, use pollPublicPreview / poll_public_preview from the SDK (or poll GET /v1/files/{fileId}) until staticPublicPreviewSource and publicPlaybackId are ready.

To disable public preview later, call POST /v1/files/{fileId}/disable-public-preview. This removes the public URL copy and revokes embed streaming access.

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/..."