Connecting
Open a WebSocket connection to:- An
Authorization: Bearer <API_KEY>header on the connection request - An
api_keyquery parameter, for examplewss://run.vast.ai/ws/workers/?api_key=<API_KEY>. Browsers cannot set headers on WebSocket connections, so use this form from browser code.
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:
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 aworkers array:
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 anerror 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
websockets library, version 14 or later.