Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.reactor.inc/llms.txt

Use this file to discover all available pages before exploring further.

The Reactor SDKs are how your app opens a session, sends commands, and receives video and events from any model. There are two:
  • 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.
Every code example below offers all three. Pick a tab and it stays selected down the page.
Never ship your API key to the browser. Browser apps exchange it for a JWT on your server; Python runs server-side and uses the key directly. 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
import { Reactor } from "@reactor-team/js-sdk";

const reactor = new Reactor({ modelName: "your-model-name" });
await reactor.connect(token);
Disconnect when done:
Disconnect
await reactor.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.
Listen for the trackReceived event and attach the stream to a video element.
Track listener
const video = document.getElementById("video") as HTMLVideoElement;

reactor.on("trackReceived", (name, track, stream) => {
  video.srcObject = stream;
});

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
reactor.on("statusChanged", async (status) => {
  if (status === "ready") {
    await reactor.sendCommand("set_prompt", { prompt: "a forest at dawn" });
  }
});

File uploads

Upload files and pass them to commands. See File Uploads for the full guide.
File upload
const file = input.files[0];

const ref = await reactor.uploadFile(file);
await reactor.sendCommand("set_image", { image: ref });
uploadFile() returns a FileRef (JavaScript · Python) 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
reactor.on("message", (msg) => {
  if (msg.type === "state") {
    console.log("Frame:", msg.data.current_frame);
  }
});

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.
Get a media stream and publish it once connected:
Publish track
import { Reactor } from "@reactor-team/js-sdk";

const reactor = new Reactor({ modelName: "your-model-name" });

const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const track = stream.getVideoTracks()[0];

reactor.on("statusChanged", async (status) => {
  if (status === "ready") {
    await reactor.publishTrack("webcam", track);
  }
});

await reactor.connect(token);
To stop publishing:
Unpublish
await reactor.unpublishTrack("webcam");
stream.getTracks().forEach((t) => t.stop());
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.

Error handling

Handle connection and runtime errors from the SDK.
Error handler
reactor.on("error", (error) => {
  console.error(`[${error.component}] ${error.code}: ${error.message}`);

  if (error.recoverable) {
    reactor.reconnect();
  }
});
See ReactorError (JavaScript · Python) for all error codes and fields.

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
// Terminate the session
await reactor.disconnect();

// Disconnect but keep the session alive on the server
await reactor.disconnect(true);
await reactor.reconnect();
To reconnect automatically when the error is recoverable:
Auto-reconnect
reactor.on("error", (error) => {
  if (error.recoverable) {
    setTimeout(() => reactor.reconnect(), (error.retryAfter ?? 3) * 1000);
  }
});

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.