WebSocket messages
The live channel for one generation: progress, previews, finished media and the final status, pushed to the client as they happen.
On this page
The app uses this channel to fill the Generate page while a run is going. Anything that can open a WebSocket can use it. To start a run and get its id, see the API tab of The Generate workspace; to read a finished run, use History over HTTP.
Connect and authenticate#
Open /ws/generation on the same host and port as the app, with ws:// for http and wss:// for https. There are three ways to authenticate:
- A ticket. Call
POST /api/auth/ws-ticketwith the body{"path": "/ws/generation"}, authenticated like any other request; an API key with Can read is enough. The answer carries aticketthat is valid for 30 seconds, for that one socket path and for one connection. Connect to/ws/generation?ticket=<ticket>. - An
Authorizationheader. A client that can set request headers sendsAuthorization: Bearer <API key or login token>when it opens the socket. - The
tokenquery parameter. The login token thatPOST /api/auth/loginreturns still works as?token=<token>, but it is deprecated: use a header or a ticket. An API key is never accepted in the query string.
ws://localhost:26730/ws/generation?ticket=<ticket>
The server checks the credentials before it accepts the connection. If they are missing, invalid or belong to a user that no longer exists, the server accepts the socket only to close it with code 4001 and a reason such as Authentication required, Invalid or expired ticket, Invalid token, User not found, Authentication error or Authentication failed. A socket opened with an API key is also closed with 4001 when the key is revoked, expires or is narrowed so that it no longer permits the socket. The app does not reconnect after a 4001; it treats the session as expired. After any other close it reconnects, doubling its delay from 1 second up to 30 seconds, and subscribes again.
Once connected, the server sends connection_established with a client_id and then a heartbeat every 15 seconds. Every message is one JSON text frame with a type field.
Subscribe to a generation#
Nothing about a generation arrives until you subscribe to it. Send the generation id that POST /api/generations/start returned:
{"type": "subscribe_generation", "generation_id": "<generation id>"}The server answers subscribed, followed at once by a status_update that holds the generation's current status, so a client that subscribes late does not miss what already happened. After that, every message for that generation is pushed to you. You can subscribe to several generations on one socket.
You can subscribe only to your own generations. An administrator can subscribe to any. An id that does not exist and an id that belongs to someone else get the same subscription_error, Generation <id> not found, so the channel cannot be used to find out which ids exist.
The client can also send {"type": "ping"} and gets a pong back. Frames that are not valid JSON, and message types the server does not know, are ignored without a reply. Messages are not replayed: if the socket drops, subscribe again and read the status_update snapshot, or ask GET /api/generations/{generation_id}/status.
What a message looks like#
Messages that carry a generation output share these fields, followed by the fields of their own type:
| Field | Meaning |
|---|---|
type | The message type from the table below. |
generation_id | The generation the message belongs to. |
pipe_id, pipe_name | The pipe that produced the output. Present, and possibly empty, on every output message. |
output_type | The kind of output that was serialized, for example image, video, progress or seed. |
grid_id | Only when the run is one cell of an X/Y compare grid. |
index | Only when the output has an index, for example a numbered artifact. |
nsfw, content_flagged, preview_suppressed | On image, video and gallery outputs. When preview_suppressed is true the message is cut down to the type, ids, flags and file type, with no picture in it. |
The messages that report a run ending (generation_complete, generation_cancelled) and the status_update snapshot instead wrap the generation status in a data object. For a terminal message, take the id from data.id.
What a regular user receives is scoped. A failed run's message is replaced by a short, plain summary and a hint, paths in progress text are reduced to file names, and the admin detail on preview clips and the failing pipe on errors are left out. An administrator receives the full text and those extra fields.
Message types#
Sent by the server. The first group answers the connection, the second reports the run.
| Type | When it is sent | Fields |
|---|---|---|
connection_established | Right after the connection is accepted. | client_id |
heartbeat | Every 15 seconds while connected. | timestamp |
pong | In reply to a client ping. | timestamp |
subscribed | After a successful subscribe_generation. | generation_id |
status_update | Once, straight after subscribed. It is a snapshot, not a change. | data: the generation status (see below) |
subscription_error | When a subscription fails: no generation_id in the request, a generation that does not exist or is not yours, or a server error. | message, and generation_id when one was sent |
| Type | When it is sent | Main fields |
|---|---|---|
queue_update | When the generation's place in the queue changes, and once more when it leaves the queue and starts. | status (pending or running), queue_position (a number while pending, null once running; the place in the queue of the backend that will run the job), queue_depth (jobs waiting on that backend), waiting_reason (plain text when the backend cannot start work right now, otherwise null), tab_id; administrators also get admin_detail with the backend’s id and name |
generation_status | Whenever a pipe reports progress. | status, current_step (a template string such as <<PIPE:generator:bolt>>), message, progress (0 to 1, or null while unknown), current_step_num, total_steps; for a Video Director run also segment_id; for a batch also item_index, item_count, item_progress, prompt_index, prompt_count |
workbench_update | When a pipe emits an image, a video, a sound or a 3D mesh. temporary is true for an intermediate output such as a live preview and false for a saved one. | Image: image (a base64 preview), path, seed, resolution, sampler, cfg, denoise, step. Video: file_type: "video", path, duration, fps, seed, resolution. Audio: file_type: "audio", track_type, duration, sample_rate, channels. Mesh: file_type: "mesh", mesh_format, vertex_count, face_count |
workbench_preview_clip | For video models that can preview their sampling: a looping low-resolution clip of the run so far. It is bounded in count, size and frequency. | image (a WebP sprite sheet as a data URL), frames, columns, frame_width, frame_height, fps, step, total_steps |
gallery_update | When a set of finished pictures, clips, sounds or meshes is ready. A run's results arrive this way. | images (base64 previews) and image_urls_list (one entry per saved picture with original, seed, resolution, prompt, prompt_index, nsfw and more), and the matching lists videos/video_urls_list, audios/audio_urls_list and meshes/mesh_urls_list |
pipe_artifact | When a pipe hands over something that is not a result. Live types only: a text artifact and a model_file artifact (a model saved into the library by the run). Other artifacts, such as seeds, compare images, the rendered prompt and the model list, are recorded in the admin run report and are not pushed. | artifact_type, artifact_data |
timer_update | When a pipe reports how long a stage took. | timer_name, timer_value, timer_unit, formatted_time |
director_shot_update | During a Video Director run, as each shot starts, progresses and finishes. | shot_id, shot_index, shot_count, status, progress, message, output_url and output_path once the shot's clip is saved |
content_blocked | When the content policy withheld some of a run's outputs. | blocked_count, total |
generation_error | When a pipe fails, or when an output cannot be turned into a message. | status: "failed", error_code, message, hint, error_id; administrators also get detail, failed_pipe_id, failed_pipe_name and failed_at_step |
generation_complete | When the run has ended, whether it succeeded or failed. It carries no media: use the earlier gallery_update messages for those. | data: the final generation status |
generation_cancelled | When the run was cancelled. | data: the generation status, with cancel_notice when there is one |
generation_update | For a pipe's parameter record, which the server stores (it links the generation to the models it used) and which has no display payload, and as the fallback type for an output with no registered type. The cloud cost output is declared with the same type but is kept on the server and never sent. The app has no handler for it and ignores it. | Only the common fields |
Plugins can add output types with their own message type. Those arrive in the same shape, with the common fields and the fields the plugin's serializer adds. A client should ignore a type it does not know.
The generation status#
The data object of status_update, generation_complete and generation_cancelled:
| Field | Meaning |
|---|---|
id | The generation id. |
status | pending, running, completed, failed or cancelled. |
preset_id | The preset the run used. |
progress, current_step, current_step_num, total_steps | The last progress the run reported. progress is 0 to 1 or null. |
message | A line of text about the run. For a failed run seen by a regular user it is the plain summary, not the raw error. |
error_code, error_id | The failure category, and the generation id again, set only when the run failed. |
cancel_notice | A note shown when a run was cancelled, if there is one. |
segment_id | The Video Director shot the last progress update belonged to. |
created_at, completed_at | Timestamps as text; completed_at is null until the run ends. |
grid_id | Only for a run that is one cell of a compare grid. |
What to expect in a run#
- You subscribe. You receive
subscribedand thestatus_updatesnapshot. A run that is still waiting also getsqueue_updatemessages as its position changes. - The run starts. A
queue_updatewithstatus: "running"arrives, thengeneration_statusmessages with progress. Previews come asworkbench_updateorworkbench_preview_clip. - The results are ready. One or more
gallery_updatemessages carry the saved outputs. - The run ends.
generation_completearrives for a finished or failed run andgeneration_cancelledfor a cancelled one. A failure is preceded by ageneration_errormessage. No further outputs follow a terminal message.
Other sockets#
PotionUI has separate WebSocket endpoints for other live data: downloads (/ws/downloads), notifications (/ws/notifications), automations (/ws/automations), administration (/ws/admin) and the system monitor (/ws/system). They have their own message types and are not covered here.