Skip to main content
The serverless engine can push the status of your workers to you over a WebSocket connection. Each update carries the same worker objects returned by get endpoint workers and get workergroup workers, so you can build dashboards or automation without polling those APIs. The Vast console uses this connection for its live worker view.

Connecting

Open a WebSocket connection to:
Authenticate with your Vast API key in one of two ways:
  • An Authorization: Bearer <API_KEY> header on the connection request
  • An api_key query parameter, for example wss://run.vast.ai/ws/workers/?api_key=<API_KEY>. Browsers cannot set headers on WebSocket connections, so use this form from browser code.
If the key is missing or invalid, the server rejects the connection with HTTP 401 and a JSON body such as {"error_msg": "invalid API key"}.

Subscribing

After the connection opens, send a JSON text message to subscribe to an endpoint or a workergroup:
The server confirms each subscription:
Workergroup topics use the form ag:<id>. A single connection can hold any number of subscriptions. Send the same message with "action": "unsubscribe" to stop receiving updates for that endpoint or workergroup; the server replies with {"status": "unsubscribed", "topic": "..."}. You can only subscribe to endpoints and workergroups owned by the account of the API key you connected with.

Update Messages

For every subscription, the server sends an update about once per second. Endpoint updates contain a workers array:
Workergroup updates also include active_update, which is true while a rolling update of the workergroup’s workers is in progress:
Endpoint updates are only sent while the endpoint is in the active state. A suspended or stopped endpoint stays subscribed but receives no updates until it is active again. For the meaning of each status value, see Worker States.

Errors

If a message cannot be processed, the server replies with a JSON object containing an error field and keeps the connection open:

Connection Limits

  • Messages sent to the server can be at most 4 KB.
  • The server sends WebSocket pings automatically and closes connections that have been silent for 120 seconds. Standard WebSocket clients answer pings on their own, so no application-level keepalive is needed.

Examples

The Python example uses the websockets library, version 14 or later.