Skip to main content
AsyncConnectorClient is the async-native client. Use it when your pipeline uses asyncio โ€” LangChain, LlamaIndex, FastAPI, or any framework where embedding and vector store calls are async. Callbacks are async def coroutines, so you can await any async operation directly inside them.

Constructor

url
string
required
Full URL to GET /stream/{product_id} on the connector.
token
string
default:"\"\""
Unkey API key (uk_live_...). Leave empty to connect without authentication.
session_concurrency
int
default:"4"
Maximum number of concurrent in-flight callback tasks per session. Each sessionโ€™s callbacks run as independent asyncio.Task instances โ€” a slow LLM or vector store call for one session never delays delivery for another. Increase this if a single session can generate bursts of events faster than your callback can process them.

Callbacks

All registration methods return self for chaining.

.on_actions(fn)

fn
async Callable[[ActionsPayload], None]
required
Async coroutine called every time a batch of UI actions arrives. await any async I/O directly โ€” it wonโ€™t block other coroutines.

.on_summary(fn)

fn
async Callable[[SummaryPayload], None]
required
Async coroutine called every time a session summary arrives.

Per-session task isolation

Each incoming payload is dispatched as an independent asyncio.Task keyed by session_id. This means:
  • A slow embedding call for session A never delays delivery for session B.
  • Each session has its own asyncio.Semaphore capped at session_concurrency concurrent tasks.
  • The SSE reader loop is never blocked by your callback logic.
This mirrors the event connectorโ€™s own per-session asyncio.Task architecture.

Lifecycle

await .run()

Connect to the SSE stream and process events. Reconnects with exponential backoff (1 s โ†’ 30 s).
HTTP 401, 403, and 404 are not retried โ€” they raise immediately. Check your url and token.

.run_in_background()

Schedule run() as an asyncio.Task and return immediately.
Returns an asyncio.Task.

.stop()

Signal the client to stop after the current event.

Async context manager


FastAPI integration

Register the client as a background task using FastAPIโ€™s lifespan:

Chained setup