Open History to see the last commit
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:426
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 threadId,
57})
58
59console.log('Job started:', jobId)
60
61// The submission only OPENS the run; the poll that sees a terminal state is
62// what completes it. The `jobId` is the whole correlation — pass the same
63// `middleware` and `threadId` when you use them.
64const status = await getVideoJobStatus({
65 adapter: openaiVideo('sora-2'),
66 jobId,
67 threadId,
68})
69```
70
71**Stream the full video generation lifecycle**
72
73```ts
74import { generateVideo, toServerSentEventsResponse } from '@tanstack/ai'
75import { openaiVideo } from '@tanstack/ai-openai'
76
77const stream = generateVideo({
78 adapter: openaiVideo('sora-2'),
79 prompt: 'A cat chasing a dog in a sunny park',
80 threadId,
81 stream: true,
82 pollingInterval: 3000,
83})
84
85return toServerSentEventsResponse(stream)
86```