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

reactor.md

182 lines6.6 KB

1---
2title: Reactor
3id: reactor-adapter
4description: "Generate live worlds and video with Reactor models in TanStack AI via the @tanstack/ai-reactor adapter."
5keywords:
6 - tanstack ai
7 - reactor
8 - world generation
9 - live generation
10 - orbis
11 - helios
12 - generateWorld
13 - generateLiveVideo
14 - adapter
15---
16​
17Reactor hosts live world and video models. You describe a scene. Then you open a session and stream video. You can steer the stream with a new prompt.
18​
19Use `reactorWorld()` with `generateWorld()` for navigable worlds. Use `reactorVideo()` with `generateLiveVideo()` for live video models. Both mint a session token. Neither supports `chat()`.
20​
21## Installation
22​
23<!-- ::start:tabs variant="package-manager" mode="install" -->
24​
25react: @tanstack/ai-reactor
26vue: @tanstack/ai-reactor
27solid: @tanstack/ai-reactor
28svelte: @tanstack/ai-reactor
29preact: @tanstack/ai-reactor
30angular: @tanstack/ai-reactor
31vanilla: @tanstack/ai-reactor
32octane: @tanstack/ai-reactor
33​
34<!-- ::end:tabs -->
35​
36Peer dependency: `@tanstack/ai`. The browser also needs `@reactor-team/js-sdk` to connect and play the stream. See [World Generation](../media/world-generation) and [Live Generation](../media/live-generation).
37​
38A full working app is in [`examples/ts-react-media`](https://github.com/TanStack/ai/tree/main/examples/ts-react-media). Open the World or Live tab.
39​
40## API key
41​
42Create a key in the [Reactor dashboard](https://www.reactor.inc/dashboard). Keys start with `rk_`.
43​
44The example app uses [Bring Your Own Key](../advanced/byok). The browser pastes the key. The relay reads `x-byok-reactor`, then `REACTOR_API_KEY`.
45​
46```ts
47import { generateWorld } from '@tanstack/ai'
48import { byokMissing, getByokKey } from '@tanstack/ai/byok/server'
49import { reactorWorld } from '@tanstack/ai-reactor'
50import { reactorByok } from '@tanstack/ai-reactor/byok'
51​
52export async function POST(request: Request) {
53 const apiKey = getByokKey(request, reactorByok)
54 if (!apiKey) return byokMissing(reactorByok)
55​
56 const world = await generateWorld({
57 adapter: reactorWorld('visko-orbis-stable', { apiKey }),
58 prompt: 'A neon cyberpunk city at night, slow aerial drift',
59 })
60​
61 return Response.json({
62 token: world.token,
63 model: world.model,
64 prompt: world.prompt,
65 expiresAt: world.expiresAt,
66 })
68```
69​
70The adapter mints a **session-scoped** token for that model only. Hand `world.token`, `world.model`, and `world.prompt` to the browser. Do not put the API key in the JSON body.
71​
72## Models
73​
74Pass a string literal so TypeScript can narrow options.
75​
76```ts
77import { reactorWorld } from '@tanstack/ai-reactor'
78​
79const adapter = reactorWorld('visko-orbis-stable')
80```
81​
82| Id | Connect slug |
83| --- | --- |
84| `visko-orbis-stable` | `reactor/visko-orbis-stable` |
85| `visko-orbis-dynamic` | `reactor/visko-orbis-dynamic` |
86| `happy-oyster-adventure` | `reactor/happy-oyster-adventure` |
87| `happy-oyster-director` | `reactor/happy-oyster-director` |
88| `lingbot-world-2` | `reactor/lingbot-world-2` |
89| `lingbot` | `reactor/lingbot` |
90| `helios` | `reactor/helios` |
91​
92`world.model` is the connect slug. Pass it to `new Reactor({ modelName })`.
93​
94## Live video
95​
96Reactor video is a live stream, not a finished file. `generateLiveVideo()` returns a token. The browser connects, sets the prompt, and plays the track.
97​
98```ts
99import { generateLiveVideo } from '@tanstack/ai'
100import { reactorVideo } from '@tanstack/ai-reactor'
101​
102const apiKey = process.env.REACTOR_API_KEY ?? ''
103const live = await generateLiveVideo({
104 adapter: reactorVideo('helios', { apiKey }),
105 prompt: 'A neon cyberpunk city at night, slow aerial drift',
106})
107```
108​
109Hand `live.token`, `live.model`, and `live.prompt` to the browser. Connect as shown in [Live Generation](../media/live-generation).
110​
111| Id | Connect slug |
112| --- | --- |
113| `helios` | `reactor/helios` |
114| `fast-h3` | `reactor/fast-h3` |
115| `longlive-v2` | `reactor/longlive-v2` |
116| `ltx2` | `reactor/ltx2` |
117​
118`helios` also works with `reactorWorld()`. Pick `generateLiveVideo()` when you want a video session. Pick `generateWorld()` when you want a navigable world.
119​
120Pass a text prompt to `generateWorld()` / `generateLiveVideo()`. Those calls mint a token. They do not send resolution or a seed image.
121​
122After `connect`, send browser commands. LingBot starts from a seed image. Pass a `File` from `<input type="file">`. The SDK uploads it and returns a `FileRef`. Do not send base64. `start` also needs `set_prompt`. Write the prompt to describe what the image shows.
123​
124```ts
125import { Reactor } from '@reactor-team/js-sdk'
126​
127const reactor = new Reactor({ modelName: 'reactor/lingbot' })
128const picker = document.querySelector('input[type="file"]')
129if (!(picker instanceof HTMLInputElement)) {
130 throw new Error('Pick a seed image')
132const file = picker.files?.[0]
133if (file === undefined) {
134 throw new Error('Pick a seed image')
136const image = await reactor.uploadFile(file)
137await reactor.sendCommand('set_image', { image })
138await reactor.sendCommand('set_prompt', {
139 prompt: 'A narrow stone alley at night, wet cobbles, one lit shop window.',
140})
141await reactor.sendCommand('start', {})
142```
143​
144Helios can take the same `File` with `set_conditioning` so prompt and image land together.
145​
146Orbis takes an optional seed image. Send `set_image` before `set_prompt` and `start`. Use a 16:9 image, because Orbis resizes other shapes without a crop. A new image during a run has no effect until `reset`.
147​
148## Browser session options
149​
150Orbis reads these on the next `start`. Keep them in client state. Send them with `sendCommand` after `connect`. They are not token-mint fields.
151​
152```ts
153import { Reactor } from '@reactor-team/js-sdk'
154​
155const reactor = new Reactor({ modelName: 'reactor/visko-orbis-stable' })
156await reactor.sendCommand('set_resolution', { resolution: '2k' })
157await reactor.sendCommand('set_seed', { seed: 42 })
158await reactor.sendCommand('set_audio_enabled', { audio_enabled: true })
159```
160​
161| Option | Command | Meaning |
162| --- | --- | --- |
163| `resolution` | `set_resolution` | `1080p`, `2k`, or `4k` delivery tier |
164| `seed` | `set_seed` | RNG seed for the next run |
165| `audioEnabled` | `set_audio_enabled` | When `false`, skip audio compute |
166| `audioPrompt` | `set_audio_prompt` | Sound description, or `""` for picture-driven audio |
167​
168## Custom endpoint
169​
170```ts
171import { reactorWorld } from '@tanstack/ai-reactor'
172​
173const apiKey = process.env.REACTOR_API_KEY ?? ''
174const adapter = reactorWorld('visko-orbis-stable', {
175 apiKey,
176 baseUrl: 'https://api.reactor.inc',
177})
178```
179​
180## What you have now
181​
182A server call that mints a scoped Reactor token for one world or video model. Next: connect in the browser as shown in [World Generation](../media/world-generation) or [Live Generation](../media/live-generation).