Chat with an agent over a socket, with your organization's credentials

wss://api.hilus.ai/Platform/chat/stream

Chat with an agent over a socket, with your organization's credentials.

Three kinds of caller use it: your server, with an API key in a header (keep the key out of browsers); the dashboard's signed-in browser, with its session cookie from an allowed origin; and a browser host off a Hilus origin that holds a person's access key (the Chrome extension), with a one-minute token from stream-token as ?token=, never the key itself. Within five seconds of connecting, send a resume frame: with a conversation_id to continue that conversation (history is replayed first), or without one to start a new conversation. The server answers conversation_started, then any history and history_complete. Each message frame gets a message_ack, then the reply streams as text_delta frames, tool call frames and attachments, ending with turn_end. stop cancels the reply in progress; voice_start switches to voice.

A resume frame with mock starts a test chat, mocked exactly as a mocked send is. branch picks the configuration to test (a draft change, for example), and ephemeral keeps the conversation in memory for the life of the socket, so nothing is written. Otherwise the test conversation is stored on the branch, or on the agent's lab/sim-<agent_id> branch, and never on main. In a test chat every turn_end is followed by turn_inspect: the model request id the lab uses to diagnose or replay the reply, the turn's tool calls and its latency. A test chat always starts a new conversation. Voice works in a test chat as in any chat, with the agent's tools mocked; an ephemeral test chat stores no call, and while voice is on, message frames are refused. A test chat has no file uploads. A refused resume frame (branch or ephemeral without mock, or a stored test chat on main) gets one error frame and the socket closes.

The socket is for members, servers and the organization's registered computers only: a chat's share slug, or a visitor's or sandbox's session token, gets one error frame and nothing else. Visitors use the visitor chat socket. A registered computer connects with the one-minute token the connector gateway's chat token route gives it after key proof; it always comes in through the organization's browser extension (the socket's agent_id is not used), never opens a test chat or voice, resumes only its own conversations, and is checked again before every message: once revoked, its next message gets one error frame and the socket ends.

Side effects: an ordinary chat runs the agent's tools for real, which can reach people and systems outside Hilus, and stores the conversation. A test chat never runs irreversible tools; read-only tools still read real data.

A token minted with an entry comes in through that entry point of your organization instead: its routing picks the agent, and a refusal is one error frame before anything runs.

Args: agent_id: Agent to chat with. Not used when the token names an entry point. conversation_id: Conversation to continue; a resume frame can name it instead.

Query parameters

Heartbeat: the server pings every 25.0s; answer each with {"type": "pong"}. Idle timeout: 900.0s without a client frame closes with 4002.

Close codes

Code Meaning
1000 Normal close; also sent when the client stops answering heartbeat pings.
1003 No WebSocket route at this path.
1008 Policy violation: credential not accepted for this route, missing scope or role, or invalid connection parameters (the reason names them).
1011 Server error while handling the connection.
1012 Server restarting; reconnect.
1013 Rate or concurrency limit reached; retry later.
4001 Session expired or missing; re-authenticate (reload) and reconnect.
4002 Closed for inactivity (no real client frame within the idle timeout); reconnect at once only to resume a conversation the server has stored, otherwise when the user acts again.
4003 Credential of the wrong kind for this route; do not retry with the same credential.

Example

// Mint a short-lived session token on your server; never put an API key in a browser or a URL.
const socket = new WebSocket("wss://api.hilus.ai/Platform/chat/stream?token=" + HILUS_SESSION_TOKEN);