Endpoint
Message format
All messages are JSON objects with a common top-level structure.Message type. One of
offer, answer, ice-candidate, error, close.Session identifier. Send an empty string (
"") when creating a new session with an offer.Message-specific payload. Structure depends on the message type.
Authentication token. Required in the
offer message only.Optional call identifier.
Optional caller identifier.
Optional callee identifier.
Operations
Send offer
Direction: client to server
sessionId and include your authToken.
The data field contains the SDP offer:
Must be
"offer".Full SDP string from your local peer connection.
Example
Receive answer
Direction: server to client
sessionId. Store the sessionId and use it for all subsequent messages.
The data field contains the SDP answer:
Must be
"answer".Full SDP string from the server.
Example
Exchange ICE candidates
Direction: bidirectional
data field contains the ICE candidate:
ICE candidate string.
Media stream identification tag.
Zero-based index of the media description in the SDP.
Example
Close
Direction: client to server
Example
Error
Direction: server to client
data field contains the error details:
Error code identifying the failure type.
Human-readable error description.
Example
Error codes
| Code | Description |
|---|---|
UNAUTHORIZED | Invalid or missing authentication token |
INVALID_MESSAGE | Malformed or unsupported message format |
HANDLER_ERROR | Error processing the signaling message |
MEDIA_BRIDGE_FAILURE | Failed to establish the media connection |
AGENT_FAILURE | Error connecting to the PolyAI agent |
Connection flow
Send offer
Create a local
RTCPeerConnection, add your microphone track, generate an SDP offer, and send it with your authToken.Receive answer
The server responds with an SDP answer and a
sessionId. Set the remote description on your peer connection.Exchange ICE candidates
Forward ICE candidates from your
onicecandidate handler. Add incoming candidates from the server to your peer connection.Audio flows
Once ICE negotiation completes, bidirectional audio streams between the browser and the PolyAI agent.

