Skip to main content
The Reactor SDKs are how your app opens a session, sends commands, and receives video and events from any model:
  • JavaScript ships both a React API (provider, components, hooks) and an imperative API (the Reactor class). 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 BGRA Data on 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.
The common examples below offer JavaScript, React, Python, C++, Swift, and Java. Pick a tab and it stays selected down the page. The native SDKs have their own full reference pages (C++ · Swift · Java).
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 Reactor class is the generic, model-agnostic entry point. It speaks raw JSON over the wire: you call sendCommand(name, payload) and listen for generic message events. 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 a sendCommand() under the hood.
The base Reactor class sits at the top; typed model SDKs like HeliosModel and LingbotModel extend it
Reach for the base 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

Connect
Disconnect when done:
Disconnect
See Authentication for how to obtain a token or API key.

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, and Java deliver them as raw BGRA pixels.
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 reach ready before sending commands; the model is not available until the connection is fully established.
Send command

File uploads

Upload files and pass them to commands. See File Uploads for the full guide.
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.
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 is ready, and call unpublishTrack() to stop.
Get a media stream and publish it once connected:
Publish track
To stop publishing:
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.
In Python, a failed publish() does not clean up the session by itself — wrap the connected lifetime, publish included, in try/finally: await reactor.disconnect(), or a failure here can leave an orphaned session behind that the next connect() rejects with ConflictError.

Error handling

Handle connection and runtime errors from the SDK.
Error handler
See 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.
Reconnect
To reconnect automatically when the error is recoverable:
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.
Adopt a session
See Sessions › Multiple connections per session for the full lifecycle and connection-id details.

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.