Realtime overview
Show a run's status, progress, and streamed output in your app while the task works.
Realtime lets your app show a run while it works. A page can show the run's status, a progress bar, and text as the task writes it. You do not need to poll.
Realtime covers two kinds of data:
- Run updates: the run's status, metadata, and final output. You get a new value each time one of them changes.
- Streams: data the task writes while it runs, such as AI tokens or log lines. You get each part as soon as it is saved.
| Run updates | Streams | |
|---|---|---|
| What you get | Status, metadata, and final output | Each part the task appends |
| When it updates | When the run changes | Each time the task appends a part |
| Good for | Status badges, progress bars, results | AI answers, live logs, long reports |
| Task code | Nothing extra. Call context.updateMeta() to report progress. | Declare streams on the task and call context.stream(name).append(). |
| React hook | useRun | useRunStream |
| Plain client | client.subscribe() | client.readStream() |
Most pages use both: useRun for the status and useRunStream for the live text.
How it works
worker ── saves status, metadata, and parts ──> storage
│
browser ── opens a connection ──> your server ── reads ──┘
<── sends each change ── (realtime.handle)- Your task runs on a worker. It saves status, metadata, and stream parts to storage, as usual.
- You mount one handler,
realtime.handle, in your own server. Runlane does not host it for you. - The browser opens a long-lived HTTP connection to that handler. This uses server-sent events (SSE): one response that keeps sending events.
- On every connection, the handler checks that this user may read this run. It then sends a snapshot of the run, followed by each change.
- If the connection drops, the client reconnects and continues where it stopped. It does not repeat or skip parts.
The worker and the handler can run in different processes. They only share storage.
What you install
| Import from | Runs in | Gives you |
|---|---|---|
@runlane/realtime | Your server | createRunlaneRealtime(): the HTTP handler and token minting |
@runlane/realtime/client | Browser or Node.js | createRunlaneClient(): reads runs and streams |
@runlane/react | React 19 apps | RunlaneProvider, useRun, and useRunStream |
@runlane/realtime/client is part of the @runlane/realtime package. React apps install @runlane/realtime and @runlane/react.
Next steps
Set up realtime
Mount the handler and show a live run in a Next.js app.
Authorize readers
Decide who can read each run, with session cookies or signed tokens.
React hooks
Follow run updates and streams from React components.
JavaScript client
Read runs from Vue, Svelte, plain JavaScript, or Node.js.
The run object
See every field the browser receives, and what is never sent.
Frontend types
Type outputs and stream parts without bundling backend code.
Common questions
Do I need WebSockets or polling?
No. The handler uses server-sent events over normal HTTP. The client reconnects for you.
Who decides who can see a run?
You do. Every connection runs your authorize check, or checks a token that your server signed. Runlane has no built-in user model. See authorize readers.
Is the task's input sent to the browser?
No. The browser gets a short list of safe fields. Payloads, tags, and error stack traces are never sent. See the run object.
What happens when a task retries?
A retry starts a new attempt, and the task may write a new answer. By default, useRunStream clears the text when a new attempt starts. You never see two answers joined together. See retries and attempts.
Does closing the page cancel the run?
No. Unmounting a component or calling stop() only closes the connection. The run keeps going. To cancel it, call runlane.runs.cancel(runId) on your server. See cancel runs.
Where do I write the stream from the task?
In the task's run function. See stream run output for appends, batches, and piping a model's output.