@fal.realtime("/realtime") decorator, which uses fal’s binary msgpack protocol for efficient serialization. Callers connect using the realtime() method in the fal client SDKs. For one-way progressive output from a single request (like showing diffusion steps), use Streaming Endpoints instead — they use SSE and are simpler when you don’t need bidirectional communication.
How Realtime Works
Under afal.App, the @fal.realtime() decorator makes your endpoint compatible with fal’s real-time clients. It uses fal’s binary msgpack protocol for efficient serialization and eliminates connection establishing overhead for repeated requests.
Important: The
fal_client.realtime() method connects to the /realtime path on your app by default. Use @fal.realtime("/realtime") so that clients connect without extra configuration. If your endpoint uses a different path, pass that path to the client with the path option. See Custom WebSocket Path.@fal.endpoint can
be initialized with is_websocket=True flag and the underlying function will receive the raw WebSocket connection and
can choose to use it however it wants.
Server-Side Implementation
Here’s an example of a fal app with both a regular HTTP endpoint and a WebSocket endpoint:Buffering and dropped inputs
A realtime client can send inputs faster than the app processes them. Examples are webcam frames and slider updates. Use thebuffering parameter to control the input buffer:
- A unary endpoint receives one input and returns one output, like
generate_rtabove. It keeps at mostbufferingunprocessed inputs for each connection. When the input buffer is full, a new input replaces the oldest input. The app always works on recent inputs. Withoutbuffering, the app keeps every input and processes the inputs in order. - All realtime endpoints use an outgoing queue that holds twice the
bufferingvalue, or 2 when you do not set it. When this queue is full, the app sends outputs directly. These outputs can arrive out of order.
buffering when the app must process every input.
Two related parameters control the session:
max_batch_sizepasses up to this number of inputs from the input buffer to a unary function in one call.session_timeoutends the session when the client sends no message for this number of seconds.
Client-Side Connection
Connecting to @fal.realtime() Endpoints
For endpoints decorated with @fal.realtime(), use fal_client.realtime() or fal_client.realtime_async(). These methods handle serialization automatically using fal’s binary protocol:
Connecting to Raw WebSocket Endpoints
For endpoints usingis_websocket=True, use fal_client.ws_connect() or fal_client.ws_connect_async() for direct WebSocket access:
- For
@fal.realtime()endpoints: Usefal_client.realtime()- serialization is handled automatically. - For raw
is_websocket=Trueendpoints: Usefal_client.ws_connect()with thepathparameter to specify the endpoint path.
WebRTC Transport
For applications that need direct video/audio streaming (webcam feeds, live game rendering), you can use WebRTC as the transport layer on top of fal’s WebSocket infrastructure. WebRTC provides lower latency for media streams compared to sending frames over msgpack. The low-level pattern uses a bidirectional@fal.realtime("/realtime") endpoint for WebRTC signaling. The endpoint receives an async iterator of signaling messages (offer, answer, and ICE candidates) and yields its replies. The media then flows between the browser and your runner over WebRTC. If no direct path is available, the media goes through a TURN relay.
Real-time World Model
Deploy a keyboard-controlled world model with WebRTC video streaming
Real-time Video Style Transfer
Restyle a live webcam stream with a text prompt
Real-time Voice Chat
Talk to a full-duplex speech model over WebRTC audio
Next Steps
Streaming Endpoints
Stream progressive results (image previews, video updates) using SSE
Real-time Client Docs
Client library documentation for realtime connections