PotionUI Docs v0.3.0
ReferenceWritten for v0.3.0

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-ticket with the body {"path": "/ws/generation"}, authenticated like any other request; an API key with Can read is enough. The answer carries a ticket that is valid for 30 seconds, for that one socket path and for one connection. Connect to /ws/generation?ticket=<ticket>.
  • An Authorization header. A client that can set request headers sends Authorization: Bearer <API key or login token> when it opens the socket.
  • The token query parameter. The login token that POST /api/auth/login returns 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/ws/generation?ticket=<ticket>
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:

Client sends
{"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:

FieldMeaning
typeThe message type from the table below.
generation_idThe generation the message belongs to.
pipe_id, pipe_nameThe pipe that produced the output. Present, and possibly empty, on every output message.
output_typeThe kind of output that was serialized, for example image, video, progress or seed.
grid_idOnly when the run is one cell of an X/Y compare grid.
indexOnly when the output has an index, for example a numbered artifact.
nsfw, content_flagged, preview_suppressedOn 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.

Administrators see more

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.

TypeWhen it is sentFields
connection_establishedRight after the connection is accepted.client_id
heartbeatEvery 15 seconds while connected.timestamp
pongIn reply to a client ping.timestamp
subscribedAfter a successful subscribe_generation.generation_id
status_updateOnce, straight after subscribed. It is a snapshot, not a change.data: the generation status (see below)
subscription_errorWhen 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
TypeWhen it is sentMain fields
queue_updateWhen 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_statusWhenever 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_updateWhen 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_clipFor 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_updateWhen 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_artifactWhen 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_updateWhen a pipe reports how long a stage took.timer_name, timer_value, timer_unit, formatted_time
director_shot_updateDuring 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_blockedWhen the content policy withheld some of a run's outputs.blocked_count, total
generation_errorWhen 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_completeWhen 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_cancelledWhen the run was cancelled.data: the generation status, with cancel_notice when there is one
generation_updateFor 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:

FieldMeaning
idThe generation id.
statuspending, running, completed, failed or cancelled.
preset_idThe preset the run used.
progress, current_step, current_step_num, total_stepsThe last progress the run reported. progress is 0 to 1 or null.
messageA 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_idThe failure category, and the generation id again, set only when the run failed.
cancel_noticeA note shown when a run was cancelled, if there is one.
segment_idThe Video Director shot the last progress update belonged to.
created_at, completed_atTimestamps as text; completed_at is null until the run ends.
grid_idOnly for a run that is one cell of a compare grid.

What to expect in a run#

  1. You subscribe. You receive subscribed and the status_update snapshot. A run that is still waiting also gets queue_update messages as its position changes.
  2. The run starts. A queue_update with status: "running" arrives, then generation_status messages with progress. Previews come as workbench_update or workbench_preview_clip.
  3. The results are ready. One or more gallery_update messages carry the saved outputs.
  4. The run ends. generation_complete arrives for a finished or failed run and generation_cancelled for a cancelled one. A failure is preceded by a generation_error message. 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.

Source: websocket_handler.py