Skip to main content

How it works

There is no REST endpoint for sending a message and getting a reply — text conversation turns run exclusively over a WebSocket (see WebSocket streaming). HTTP is used for three things around that connection: opening the session, minting a short-lived ticket so a browser can authenticate the WebSocket upgrade, and closing the session.
agent_url is the base URL for every real-time call — the WebSocket upgrade, and end. In most deployments it is the same public API host behind a reverse proxy; always use the value returned rather than assuming it matches the host you called to open the session.
The ws-ticket step is only needed for browser clients — browsers cannot set an Authorization header on a WebSocket handshake. Non-browser clients (native apps, servers, embedded devices) can skip it and send Authorization: Bearer directly on the WS upgrade.

Step-by-step integration

1

Open a session

Call POST /v1/sessions with mode: "text". Store the returned session_id and agent_url.
2

Mint a WebSocket ticket (browser clients only)

Browsers cannot set an Authorization header on a WebSocket upgrade. POST here first and pass the returned ticket as ?ticket= on the WS URL instead. Non-browser clients skip this step and use the Bearer header directly on the upgrade request.
Tickets are single-use and expire in expires_in seconds (default 30) if unused. See WebSocket streaming for the full connection and message protocol — that page covers sending/receiving turns, error frames, and reconnection.
3

End the session

Always call end on agent_url when the conversation finishes.
Calling end on an already-closed session returns 400 SESSION_ENDED.

Advanced topics

If the user’s input triggers a guardrail rule, the WebSocket sends {"type":"error","code":"TURN_ERROR","message":"INPUT_REJECTED: ..."} instead of a response frame. Display a neutral message to the user and do not retry automatically — see WebSocket streaming for the full error frame format.
A PROVIDER_ERROR-prefixed message means the LLM is temporarily unavailable. Close and reopen a new WebSocket connection with exponential back-off: wait 1 s, then 2 s, then 4 s. Cap at 3 retries. If still failing, surface a generic error.
Sessions opened with an hk_test_ credential echo the user’s message back verbatim over the WebSocket — no LLM call is made and no usage is billed. Useful for testing your integration end-to-end before going live. See Sandbox mode.