Understanding Reactor
Reactor enables you to build realtime AI applications by connecting your frontend to GPU-powered machines that stream interactive AI experiences. Think of it as a bridge between your web application and powerful AI models running on remote GPUs.Connection Lifecycle
A Reactor connection goes through four states:- disconnected: No active connection
- connecting: Establishing connection to the Reactor coordinator
- waiting: In queue, waiting for a GPU to be assigned
- ready: Connected to GPU machine, can send and receive messages
Status Flow Diagram
Queue System
Reactor provides two modes for handling connections when no GPU machines are available, controlled by thequeueing
flag:
Queueing Enabled (queueing: true)
When queueing is enabled, users are placed in a FIFO (first-in, first-out) queue if no machines are immediately available. During thewaiting
state, Reactor provides queue information:
- position: Your place in line
Queueing Disabled (queueing: false, default)
When queueing is disabled, users are immediately disconnected if no machines are available. This mode is useful for applications where you prefer to fail fast and let users retry later, or when you want to implement your own custom queueing logic. Examples:Using the Imperative API
The imperative API gives you direct control over Reactor connections. Use this in vanilla JavaScript/TypeScript applications or when you need fine-grained control.Basic Setup
Monitoring Connection Status
Track the connection state to update your UI:Showing Queue Information
Display queue position to users while waiting:Sending Messages
Once connected (ready
state), send messages to the GPU:
Receiving Messages
Listen for messages from the GPU:Publishing Video Input
For video-to-video models, you can publish video streams from webcams, screen captures, or any other video source:Cleanup
Always disconnect when done:Using the React API
The React API provides a declarative way to use Reactor with built-in state management, making it ideal for React applications.Setup
Wrap your app withReactorProvider
:
Displaying the Stream
UseReactorView
to show the video:
Accessing State
Use theuseReactor
hook to access state:
Connection Controls
Access connection methods:Sending Messages
Send messages to the GPU:Receiving Messages
UseuseReactorMessage
hook:
Publishing Video Input
For video-to-video models, use theWebcamStream
component to automatically handle webcam capture and publishing:
WebcamStream
component:
- Automatically requests camera access on mount
- Publishes video when Reactor status becomes
"ready"
- Unpublishes video when disconnecting
- Shows permission errors if camera access is denied
- Handles cleanup on unmount
Queue Display
Show queue information:Complete React Example
Here’s a full example combining all the pieces:Error Handling
Proper error handling ensures your application gracefully handles connection issues and provides helpful feedback to users.Listening for Errors
Subscribe to error events:Error Recovery
Handle recoverable errors with retry logic:Common Error Scenarios
Authentication Failed
Connection Errors
Message Send Failures
Next Steps
- Check out the API Reference for detailed method documentation
- Explore the Quickstart guide for a quick setup
- Browse the Models to see what’s available