- JavaScript ships both a React API (provider, components, hooks) and an imperative API
(the
Reactorclass). Use React for browser apps, imperative for vanilla JS or fine-grained control. The browser obtains a short-lived JWT token from your server. - Python is an async library for scripts, servers, and computer-vision pipelines. It receives frames as NumPy arrays and authenticates with your API key directly, server-side.
- C++ is a C++17 library for native applications — engines, capture pipelines, desktop clients.
Calls return
std::future, frames arrive as BGRA on the library’s delivery thread, and it ships as a prebuilt archive per platform. See the C++ reference. - Swift is a Swift 6 package for macOS and iOS apps. Calls are
async throws, frames arrive as BGRADataon the library’s delivery thread, and it ships as a SwiftPM package — add the dependency and link. See the Swift reference. - Java is a Java 22+ library for JVM applications. Calls return
CompletableFuture, and video frames arrive as borrowed BGRA pixels. See the Java reference. - Android is a Kotlin library for Android apps. Calls are
suspendfunctions, state is aStateFlow, and video frames arrive as borrowed BGRA pixels. See the Android reference.
Keep API keys on your server. Browser and distributed desktop or mobile apps obtain a short-lived
JWT from your backend; trusted server applications can use an API key to obtain one. See
Authentication.
Two layers: base SDK and typed SDKs
Reactor SDKs are built in two layers:- The base
Reactorclass is the generic, model-agnostic entry point. It speaks raw JSON over the wire: you callsendCommand(name, payload)and listen for genericmessageevents. It works against any model. This page teaches the base layer, so the examples work no matter which model you connect to. - Typed SDKs (for example,
HeliosModel) extend the base class and expose strongly-named methods (setPrompt(),sendImage(), …) that mirror a model’s schema. They add ergonomics, not capabilities, and every method is still asendCommand()under the hood.
Reactor class when you’re experimenting with a model that has no typed SDK yet,
developing locally against an in-progress model, writing a one-off script, or want a single SDK that
can talk to several models. For everything else the typed SDK is the recommended path. See
Typed model SDKs for the full story and the name-to-name mapping.
For the commands and events a specific model accepts, see the
Model API Reference.
Connecting
- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Connect
Disconnect
A model name is always
owner/name, for example reactor/helios. The Reactor API refuses a name
without the owner, such as helios: session creation fails as if the model does not exist.Receiving model output
The browser SDK delivers the model’s video as a media track you render in a<video> element.
Python delivers decoded frames as NumPy arrays for processing; C++, Swift, Java, and Android deliver
them as raw BGRA pixels.
- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Listen for the
trackReceived event and attach the stream to a video element.Track listener
Sending commands
Commands control what the model does. The available commands depend on the model. See the Model API Reference. Wait for the connection to reachready
before sending commands; the model is not available until the connection is fully established.
- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Send command
Replies and refusals
A command can answer with a reply message, which the awaited call returns. A model can also refuse a command, for example when its queue is full. A refusal fails that one call with a stablecode the
model names in its schema, and a message written for your user. Only the client that sent the
command receives it. Read the refusal off the call:
- JavaScript
- React
- Python
Read a refusal
sendCommand() never rejects. A refused call resolves undefined, and the SDK emits the failure
on the error event, with operation: "sendCommand", before the call resolves. Its code is the
model’s code, and its message reads command '<name>' failed (<code>): <reason>. A command whose
schema declares a reply resolves undefined only when it fails. A command with no reply resolves
undefined on success too, so for it only the error event tells you it was refused.The error event is not tied to one call. When you send the same command twice at once, match the
command name in the message.command_error message when they refuse a command. That message
reaches every client in the session, including clients that did not send the command, and models
are retiring it. Read the refusal off the call instead. A model release that refuses only with that
message answers the call as if it succeeded. For a command whose schema declares a reply, treat an
empty answer as a refusal: undefined in JavaScript, None in Python.
File uploads
Upload files and pass them to commands. See File Uploads for the full guide.- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
File upload
uploadFile() returns a FileRef (JavaScript ·
Python · C++ ·
Swift · Java) containing the upload ID, filename, MIME type, and size.
Pass multiple FileRef values in a single command and mix them with scalar arguments like
transition.
Receiving messages
Models can send structured messages back to your app, such as the current frame number, generation state, or custom events.- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Message handler
Sending video input
For models that accept a video input (e.g. video-to-video models), publish a track to the input declared by the model. Publishing is explicit: the model receives nothing until you publish, and connecting on its own never starts sending. Publish once the connection isready, and call
unpublishTrack() to stop.
- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Get a media stream and publish it once connected:To stop publishing:
Publish track
Unpublish
The track name (
"webcam") must match the attribute name declared on the model. The model
declares which tracks it accepts in its capabilities, which are fetched automatically during
connection.Stepped generation
In a stepped session, the model runs one step each time you callstep(), and the step’s frames come back as arrays instead of a live stream. Ask for the mode when
you create the client; it stays fixed for the session. The C++, Swift, Java, and Android SDKs have
the same step(), with the result types listed in
Step results in each SDK.
- JavaScript
- Python
Create the client with
generation: "stepped", publish the input tracks you feed, and push frames
into them. A pushed frame goes to the model at once, over the data channel, and the next step()
reads it from the input track.Run steps
step({ state, commands, media })appliesstate(each key as the model’sset_<key>command), thencommandsin order, then the frames inmedia, as separate calls. Frames you pushed before the step are already on the input tracks. The runtime checks the whole request first: a request that fails a check is refused and changes nothing. A handler that fails rejects withStepCommandFailedError, and the calls before it stay applied. Every option is optional:step()runs a step on the model’s current state.mediamaps an input track name to this step’s own frames, each one a framepushFrame()takes or anEncodedFrame. A bad track or frame anywhere inmediafails the step before any of it is applied.- It resolves with
{ step, tracks, elapsed, files, error, data }. Each entry intrackshastrack,kind,rate, andframes.elapsedis the seconds the step’s generation took.fileslists the extra files the model kept, each aStepFilewithname,contentType, andsize; download them as Reading a step’s files shows.erroris set when the step ran and the model reported a failure. That step still resolves.datais aUint8Arrayof what the model returned with the step besides its media, and is absent when it returned none. A dict the model returned arrives encoded as JSON. - Each frame has
encoding,dtype,shape,data, and optionalmetadata.encodingsays how the frame travelled, anddatais decoded whatever it says.datais a typed array: aUint8Arrayof RGB(height, width, 3)for video, anInt16Arrayof planar(channels, samples)for audio.stepFrameToImageData(frame)turns a video frame into anImageDatafor a canvas. publishTrack(name)resolves with aPublishedTrack,{ name, pushFrame(frame, options?), pushEncodedFrame(frame) }.track.pushFrame(...)is the same asreactor.pushFrame(name, ...), which still works.pushFrame(frame, { metadata?, captureTimeUs? })takes aVideoFrame, anImageData, or raw pixels as{ data, width, height, format? }, whereformatis"rgba"(the default),"rgb", or"bgra". For an audio track, pass{ samples, sampleRate, channels? }with interleavedInt16ArrayPCM at the sample rate the model’s track declares. Pushes keep their order with commands and steps, andstep()waits for every push you started before it. A model on a runtime older than 3.11.8 gets pushed frames with the nextstep()instead, from a buffer that holds one data-channel message’s worth of frames and drops the oldest past that.pushEncodedFrame(frame)pushes one encoded access unit,{ codec, data, width, height, keyframe? }, wherecodecis"h264","vp8","vp9", or"av1"anddatais aUint8Array, anArrayBuffer, or a WebCodecsEncodedVideoChunk.keyframedefaults to the chunk’stype. Give the frames in decode order, starting with a keyframe. See Encoded input frames.- Video step frames travel encoded when the browser and the model share a codec. The SDK encodes
your pushes and decodes the results with WebCodecs, so you still push and receive RGB.
setCodecPreference(codecs, { track? })chooses the codecs, most preferred first, or turns encoding off with[]. It applies on the next connection or reconnect.getStepFrameEncodings()returns what each track negotiated. See Encoded step frames. - A stepped session sends no live media, so
publishTrack()needs noMediaStreamTrack. If you pass one (a webcam, for example), the SDK ignores it and logs a console warning. To feed webcam frames, draw them to a canvas and push them. In a streamed session theMediaStreamTrackis still required. - A file goes in the way it does for a command:
uploadFile()it, then put theFileRefin a command’sdataor in thestatevalue of a field that takes an upload. - A step can take a long time.
stepTimeoutMson theReactoroptions sets how longstep()waits for a result, generation included. The default is 300000 (five minutes). maxMessageSizeon theReactoroptions sets the largest data-channel message, from 256 KiB to 1 GiB. The default is 64 MiB. Raise it for a model that returns larger steps.
Step errors
The step errors carry
entry, the part of the request at fault, such as state.prompt or
commands[1]. StepCommandFailedError also carries command_code, the code the failing handler
raised. step_refused, step_command_failed, step_not_ready, step_session_ended, and
step_result_too_large are lowercase codes, because the model’s runtime reports them. None of the
step errors except StepSessionEndedError ends the session. A step that did not run has no number
and does not count as a step of the session. A step that ran but that the model reported as failed
is not an error: it resolves with error set on its result.
clearStepInputs() (clear_step_inputs() in Python) drops every pushed frame the SDK still holds,
for a step that should start from fresh input. Frames the SDK already sent are on the model’s input
tracks and stay there.
Error handling
Handle connection and runtime errors from the SDK. A refused command also reaches the JavaScripterror event, with operation: "sendCommand". Handle it beside the call that sent it, as
Replies and refusals shows, not as a connection error.
- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Error handler
ReactorError (JavaScript ·
Python · C++ ·
Swift) for all error codes and fields. Java uses
ReactorException.
Reconnection
If a connection drops unexpectedly, the session stays alive on the GPU for 30 seconds. Reconnect within that window to resume without losing server-side state. For more information, see Sessions.- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Reconnect
- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Auto-reconnect
Sharing a session
Multiple clients can connect to one session at the same time. Create a session on one client (or your backend), read its id (getSessionId() in JavaScript, reactor.session_id in Python,
session_id() in C++, reactor.sessionID in Swift, reactor.sessionId() in Java), then adopt it from another client by passing
the session id to connect(). The creator owns the session lifecycle; clients that adopt it leave it
running when they disconnect.
- JavaScript
- React
- Python
- C++
- Swift
- Java
- Android
Adopt a session
Test a local model with Python
To verify a model’s video and commands without a browser, follow Local testing. That guide includes a complete brightness model and the Python client script that tests it.Full API reference
Typed model SDKs
HeliosModel, LingbotModel, and their React layers over the base SDK.JavaScript: Reactor class
The base class for connecting to any model and sending raw commands.
React components & hooks
ReactorProvider, ReactorView, WebcamStream, useReactor, and more.Python: Reactor class
The base Python class, decorators, and types for server-side use.
Python: Track
The object form of a named media track — publish, push frames, receive, pause/resume.
C++: Reactor class
The base C++ class — connecting, commands, uploads, recordings, events.
C++: Track
The object form of a named media track — publish, push frames, receive, pause/resume.
Swift: Reactor class
The base Swift class — connecting, commands, uploads, recordings, events.
Swift: Track
The object form of a named media track — publish, push frames, receive, pause/resume.
Java: Reactor class
The base Java class — connecting, commands, uploads, recordings, and events.
Java: Track
Publish media, push frames, receive output, and pause or resume a named track.
Android: Reactor class
The base Android class — connecting, commands, uploads, recordings, and stepped generation.
Android: Track
Publish media, push frames, receive output, and pause or resume a named track.