Skip to main content
The signaling channel is a WebSocket connection used to exchange SDP offers/answers and ICE candidates between your client and the WebRTC Gateway.

Endpoint

Message format

All messages are JSON objects with a common top-level structure.
string
required
Message type. One of offer, answer, ice-candidate, error, close.
string
required
Session identifier. Send an empty string ("") when creating a new session with an offer.
object
Message-specific payload. Structure depends on the message type.
string
required
Authentication token. Required in every offer message, including studio draft and preview calls. Offers without a valid authToken are rejected with an UNAUTHORIZED error (Auth token required). Setting agentVersionOverride, accountId, or projectId does not exempt a call from authentication.The gateway accepts two token types:
  • Connector token — the same token used on your project’s SIP connector (the X-PolyAi-Auth-Token value provided by PolyAI). Use this for any client outside Agent Studio. It is durable across redeploys.
  • Studio-minted JWT — issued automatically by Agent Studio for in-Studio calls. It goes stale on redeploy and is not suitable for external integrations.
For widgets, native apps, and custom WebRTC clients, use the connector token.
string
Agent mode for the session. Defaults to end-to-end when omitted.Unknown values are rejected with an INVALID_ARGUMENT error. Legacy values (agent, agent_v1, agent_v2, cascaded, normal, realtime) are still accepted but resolve to a canonical value and may be removed in a future release. Update integrations to use the canonical names.
Echo mode is restricted to debug environments. Echo mode (mode: "echo") loops your audio back to the client and is intended for connectivity testing. Production gateways reject echo offers with a FORBIDDEN error before any session is created. Use agent mode (the default) for normal voice agent traffic.
string
Unique call identifier. This is distinct from the Outbound Calling API’s call_sid field.
string
Calling number.
string
Called number.
string
Account identifier.
string
Project identifier.
string
Optional variant override.
object
Optional pinning of a specific agent build. Both fields are required when set:
  • artifactVersion (string)
  • lambdaDeploymentVersion (string)
Setting agentVersionOverride does not bypass authentication. A valid authToken is still required.

Operations

Send offer

Direction: client to server Starts a new session. Send with an empty sessionId and include your authToken. The data field contains the SDP offer:
string
required
Must be "offer".
string
required
Full SDP string from your local peer connection.
Example

Receive answer

Direction: server to client Sent by the server in response to a valid offer. Contains the SDP answer and the assigned sessionId. Store the sessionId and use it for all subsequent messages. The data field contains the SDP answer:
string
required
Must be "answer".
string
required
Full SDP string from the server.
Example

Exchange ICE candidates

Direction: bidirectional Sent by both client and server to exchange network connectivity candidates. Continue exchanging until the WebRTC connection is established. The data field contains the ICE candidate:
string
required
ICE candidate string.
string
required
Media stream identification tag.
integer
required
Zero-based index of the media description in the SDP.
Example

Close

Direction: client to server Terminates the session gracefully. Send when you want to end the call.
Example

Error

Direction: server to client Sent when the server encounters an error during the session. The data field contains the error details:
string
required
Error code identifying the failure type.
string
required
Human-readable error description.
Example

Error codes

Connection flow

1

Open WebSocket

Connect to the signaling endpoint using a WebSocket client.
2

Send offer

Create a local RTCPeerConnection, add your microphone track, generate an SDP offer, and send it with your authToken.
3

Receive answer

The server responds with an SDP answer and a sessionId. Set the remote description on your peer connection.
4

Exchange ICE candidates

Forward ICE candidates from your onicecandidate handler. Add incoming candidates from the server to your peer connection.
5

Audio flows

Once ICE negotiation completes, bidirectional audio streams between the browser and the PolyAI agent.
6

Close session

Send a close message when the conversation ends.
Last modified on July 13, 2026