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

Methods

available_models()

Return registered model identifiers.

close()

Close WebSocket connection and cleanup pub/sub resources.

collect()

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()

Establish WebSocket connection.

help()

Return documentation for a model.

publish()

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()

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()

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()

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.