Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

generateVideo.md

83 lines2.3 KB

1---
2id: generateVideo
3title: generateVideo
4---
5​
6```ts
7function generateVideo<TAdapter, TStream>(options): TStream extends true ? AsyncIterable<AGUIEvent, any, any> : Promise<VideoJobResult>;
8```
9​
10Defined in: [packages/ai/src/activities/generateVideo/index.ts:394](https://github.com/TanStack/ai/blob/main/packages/ai/src/activities/generateVideo/index.ts#L394)
11​
12**`Experimental`**
13​
14Generate video - creates a video generation job from a text prompt.
15​
16Uses AI video generation models to create videos based on natural language descriptions.
17Unlike image generation, video generation is asynchronous and requires polling for completion.
18​
19When `stream: true` is passed, handles the full job lifecycle automatically:
20create job → poll for status → stream updates → yield final result.
21​
22 Video generation is an experimental feature and may change.
23​
24## Type Parameters
25​
26### TAdapter
27​
28`TAdapter` *extends* [`VideoAdapter`](../interfaces/VideoAdapter.md)\<`string`, `any`, `any`, `any`, `any`, `any`\>
29​
30### TStream
31​
32`TStream` *extends* `boolean` = `false`
33​
34## Parameters
35​
36### options
37​
38`VideoCreateOptions`\<`TAdapter`, `TStream`\>
39​
40## Returns
41​
42`TStream` *extends* `true` ? `AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md), `any`, `any`\> : `Promise`\<[`VideoJobResult`](../interfaces/VideoJobResult.md)\>
43​
44## Examples
45​
46**Create a video generation job**
47​
48```ts
49import { generateVideo, getVideoJobStatus } from '@tanstack/ai'
50import { openaiVideo } from '@tanstack/ai-openai'
51​
52// Start a video generation job
53const { jobId } = await generateVideo({
54 adapter: openaiVideo('sora-2'),
55 prompt: 'A cat chasing a dog in a sunny park'
56})
57​
58console.log('Job started:', jobId)
59​
60// The submission only OPENS the run; the poll that sees a terminal state is
61// what completes it. The `jobId` is the whole correlation — pass the same
62// `middleware` and `threadId` when you use them.
63const status = await getVideoJobStatus({
64 adapter: openaiVideo('sora-2'),
65 jobId,
66})
67```
68​
69**Stream the full video generation lifecycle**
70​
71```ts
72import { generateVideo, toServerSentEventsResponse } from '@tanstack/ai'
73import { openaiVideo } from '@tanstack/ai-openai'
74​
75const stream = generateVideo({
76 adapter: openaiVideo('sora-2'),
77 prompt: 'A cat chasing a dog in a sunny park',
78 stream: true,
79 pollingInterval: 3000,
80})
81​
82return toServerSentEventsResponse(stream)
83```