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.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 Tickets are single-use and expire in
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.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 Calling
end on agent_url when the conversation finishes.end on an already-closed session returns 400 SESSION_ENDED.Advanced topics
Handling guardrail rejections
Handling guardrail rejections
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.Retrying on provider errors
Retrying on provider errors
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.Sandbox mode
Sandbox mode
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.