Talk to an agent from a browser: a live call over one socket
wss://api.hilus.ai/Platform/calls/webrtc/stream
Talk to an agent from a browser: a live call over one socket.
Opening the socket creates a Call (provider webrtc, status
in-progress) and sends event / session_started. Send a
config frame naming the agent to start the voice session; the
server answers event / agent_connected (or an error frame
when the agent does not exist). A call has one agent: a later
config frame is answered with an error frame. Then stream
microphone audio as audio frames (base64 16-bit mono PCM at
16 kHz); the agent's speech comes back as audio frames in the
same format, and every other pipeline event as an event frame.
Send dtmf for a key press and hangup to end the call.
When the socket closes for any reason the call is finalized: the
browser gets one event / hangup frame (reason normal, or
time_limit when the server's limit on a socket ended the call),
the Call is stored as completed with its end time, and the
conversation is kept like any other call's.
Args:
session_id: Id for the new Call (its provider call id); a
unique webrtc_... id is generated when omitted.
agent_id: Agent to answer when the config frame names none.
Query parameters
session_id: optional str. Id for the newCall(its provider call id); a uniquewebrtc_...id is generated when omitted.agent_id: optional str. Agent to answer when theconfigframe names none.
Heartbeat: the server pings every 25.0s; answer each with {"type": "pong"}.
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/calls/webrtc/stream?token=" + HILUS_SESSION_TOKEN);