Skip to main content
Asynchronous WebSocket client for CortexHub. Provides a persistent WebSocket connection for efficient model inference. Supports both request-response and pub/sub patterns. For synchronous usage, use CortexClient instead.

Constructor

Signature

Properties

bool
Check if WebSocket connection is active.
int
Number of published requests awaiting responses.
str
WebSocket URL this client connects to.

Methods

available_models()

Signature
Return registered model identifiers.

close()

Signature
Close WebSocket connection and cleanup pub/sub resources.

collect()

Signature
Collect all results into a list. Convenience method that collects subscribe() results.
If provided, collect exactly this many results. If None, collect until no pending requests remain.
Returns: List of HubResult objects.

connect()

Signature
Establish WebSocket connection.

help()

Signature
Return documentation for a model.

publish()

Signature
Publish a model inference request (non-blocking). Sends the request and returns immediately. Results arrive via subscribe().
required
Model to run (ModelType enum or string)
Optional ID to track this request. Auto-generated if not provided.
Model-specific parameters (e.g., image_input, prompt)
Returns: The request_id (useful when auto-generated) Raises: RuntimeError: If not connected

run()

Signature
Run model inference via CortexHub (blocking request-response).
required
Model to run (ModelType enum or string)
Model-specific parameters (e.g., image_input, prompt)
Returns: Model output (same format as CortexClient.run) Raises: RuntimeError: If not connected or if pub/sub mode is active CortexHubError: If server returns an error

submit()

Signature
Submit a request and return a Task for its eventual result. This is a convenience wrapper over the pub/sub API that lets you write:
async with CortexHubClient() as hub: … depth_t = hub.submit(ModelType.ZOEDEPTH, image_input=img) … mask_t = hub.submit(ModelType.GSAM2, image_input=img, prompt=“cat”) … depth_res, mask_res = await asyncio.gather(depth_t, mask_t)

subscribe()

Signature
Subscribe to inference results. Yields results as they arrive from published requests.
If provided, stop after receiving this many results. If None, yields indefinitely until no pending requests remain.
Yields: HubResult objects containing request_id, model, data, ok, and error.