generateLiveVideo() opens a live video session. The server mints the session. The browser plays it and can change the prompt while it plays.
Warning
Live generation is experimental. The API can change. Live models bill for each second that a session holds a GPU.
This streams a live video from Reactor Helios. It takes about 10 minutes.
npm i @tanstack/ai @tanstack/ai-reactor @reactor-team/js-sdkpnpm add @tanstack/ai @tanstack/ai-reactor @reactor-team/js-sdkyarn add @tanstack/ai @tanstack/ai-reactor @reactor-team/js-sdkbun add @tanstack/ai @tanstack/ai-reactor @reactor-team/js-sdkREACTOR_API_KEY=your-reactor-keyimport { generateLiveVideo } from '@tanstack/ai'
import { reactorVideo } from '@tanstack/ai-reactor'
export async function POST() {
const live = await generateLiveVideo({
adapter: reactorVideo('helios'),
prompt: 'A chef tosses noodles in a steel wok, flames leaping',
threadId: 'thread-1',
})
return Response.json({
token: live.token,
model: live.model,
prompt: live.prompt,
})
}import { Reactor } from '@reactor-team/js-sdk'
const live = await fetch('/api/live', { method: 'POST' }).then((r) => r.json())
const token = typeof live.token === 'string' ? live.token : ''
const model = typeof live.model === 'string' ? live.model : ''
const prompt = typeof live.prompt === 'string' ? live.prompt : ''
const reactor = new Reactor({ modelName: model })
const video = document.querySelector('video')
reactor.on('trackReceived', (name, _track, stream) => {
if (name !== 'main_video') return
if (!video) return
video.muted = true
const attach = () => {
video.srcObject = null
video.srcObject = stream
void video.play().catch((error: unknown) => {
if (error instanceof DOMException && error.name === 'AbortError') return
})
}
attach()
for (const track of stream.getTracks()) {
track.addEventListener('unmute', attach)
}
})
await reactor.connect(token)
await reactor.sendCommand('set_sr_scale', { sr_scale: '2x' })
await reactor.sendCommand('set_prompt', { prompt })
await reactor.sendCommand('start', {})The video element now plays the live stream. To steer it, send a new set_prompt. The shot changes at the next chunk.
A full app is in examples/ts-react-media. Open the Live tab.
The work splits in two:
The server half is the same for every live adapter. The browser half is different for each provider. There is no client hook, and there is no file at the end. For the shared model of other media types, see Generations.
Set the key with REACTOR_API_KEY or FAL_KEY, or pass apiKey in the adapter config. Do not put the key in the JSON body.
| Adapter | Id | What it does |
|---|---|---|
| reactorVideo() | helios | Interactive live video |
| reactorVideo() | fast-h3 | Fast live clips on a live track |
| reactorVideo() | longlive-v2 | Live clips, one shot at a time |
| reactorVideo() | ltx2 | LTX live video |
| falLiveVideo() | minimax/h3-max/director | Steerable live stream over fal WMA |
Each Reactor model takes its own start commands:
See the Reactor adapter for every id.
For a navigable world (Orbis, LingBot), use World Generation. For a video file that finishes, use Video Generation.
The server half uses falLiveVideo():
import { generateLiveVideo } from '@tanstack/ai'
import { falLiveVideo } from '@tanstack/ai-fal'
const live = await generateLiveVideo({
adapter: falLiveVideo('minimax/h3-max/director'),
prompt: 'Live shopping stream: a host holds up a gold watch to camera',
threadId: 'thread-1',
})
// live.model is 'fal-ai/minimax-h3-max-director'. Send it to the browser.The browser opens the stream with @fal-ai/client@alpha. Follow these rules:
The example proxy is src/routes/api.fal.proxy.ts in examples/ts-react-media. It attaches the key. It forwards only to wma.fal.run (/ice, /session, /session/heartbeat) and to the Director /ice.
import { createFalClient } from '@fal-ai/client'
import { wma } from '@fal-ai/client/realtime'
const fal = createFalClient({ proxyUrl: '/api/fal/proxy' })
const video = document.querySelector('video')
const session = fal.realtime.open(wma(live.model), {
receive: ['video', 'audio'],
onError: (error) => {
console.error(error)
},
onMedia: (stream) => {
if (!video) return
video.muted = true
video.srcObject = stream
void video.play().catch((error: unknown) => {
if (error instanceof DOMException && error.name === 'AbortError') return
})
},
})
session.send({
type: 'configure',
prompt: live.prompt,
prompt_version: 1,
protocol_version: 1,
})
await session.readyTo steer, send { type: 'prompt', prompt, prompt_version }. Increase prompt_version each time. To stop, send { type: 'stop' } and close the session.
Director bills a minimum of 60 seconds. The resolution is 480p or 768p. See the fal adapter.
Helios can start from an image. Pass a File from <input type="file">. Do not send base64. The SDK uploads the file:
const picker = document.querySelector('input[type="file"]')
if (!(picker instanceof HTMLInputElement)) {
throw new Error('Pick a seed image')
}
const file = picker.files?.[0]
if (file === undefined) {
throw new Error('Pick a seed image')
}
const image = await reactor.uploadFile(file)
await reactor.sendCommand('set_conditioning', { prompt, image })
await reactor.sendCommand('start', {})generateLiveVideo() returns these fields:
| Field | Description |
|---|---|
| id | The id of this generation |
| model | The id the browser connects to. Reactor: a slug such as reactor/helios. fal: the WMA app id. |
| token | A short-lived session token. Reactor uses it to connect. fal does not. |
| expiresAt | The token expiry, in milliseconds since epoch |
| prompt | The prompt that the browser sends when it starts the session |
| status | 'ready' or 'waiting' |
| sessionId | The provider session id, when the adapter creates one |
| usage | Usage and billing, when the adapter reports it |