https://webrtc-bridge.us-1.platform.polyai.app. See Endpoints.
Create a call
POST /api/v1/call
Creates a call and returns the credentials the client needs to connect. Send this request from your backend.
Headers
Body
The bridge gets the account, project and environment from the WebRTC token. The project settings select the agent stack. The gateway
mode values (end-to-end, traditional and the older aliases) are not accepted.
200
The paths are relative to the base URL. Use the returned paths, not paths that you build yourself.
Signaling routes
The signaling routes use the call token. Send it in theX-Call-Token header:
Send the microphone offer
POST /api/v1/call/{callId}/sdp
Send this within 30 seconds of provision. Gather ICE candidates first. The bridge does not accept trickled ICE candidates.
Response
200
sdp as the remote description, with type answer.
Pull the agent track
POST /api/v1/call/{callId}/sdp/pull
Send this when the peer connection is connected. The bridge does not read the body.
Response 200
sdp as the remote description, with type offer. Then create an answer and send it to the renegotiate route. If sdp is empty, there is nothing new to pull.
Answer the pull offer
POST /api/v1/call/{callId}/sdp/renegotiate
A
2xx response means the agent track is connected.
End a call
DELETE /api/v1/call/{callId}
Send the call token in the X-Call-Token header. The response is 204, also when the call does not exist or has already ended.
When the events WebSocket closes, the call also ends. You do not need to send both.
Events WebSocket
wss://<base host>{creds.extra.eventsUrl}
Open this socket after you receive the /sdp answer. Keep it open for the whole call. When an authenticated socket closes, the bridge ends the call. The bridge does not keep events that it sends before the socket opens.
Open one socket for each call. The bridge closes a second socket for the same call.
Authenticate
Send this message immediately after the socket opens:1008. The call continues. Open a new socket and authenticate, or send DELETE.
Keepalive
The bridge sends a WebSocket ping every 10 seconds. If it receives nothing from the client for 30 seconds, it ends the call. Your client must answer pings. Browsers do this automatically. Some native WebSocket libraries do not answer pings by default.Messages from the bridge
Each message is JSON with anevent field:
Ignore events that you do not recognise. New events can be added.
Messages to the bridge
Send one DTMF message for each keypress. The agent applies its own timeout between digits. The bridge does not support
RTCDTMFSender or RFC 4733 DTMF in the media. Send DTMF on the events socket only.
The bridge drops a DTMF message with characters that are not allowed, or with more than 32 digits. It does not send a reply. It ignores JSON messages that it does not recognise. A message that it cannot read, for example one larger than 32 KiB, ends the call.
Close codes
When a call ends, the bridge closes the socket without a close code, so the browser reports
1006. Use the call_ended event to find out why.
Errors
Error bodies are plain text unless this table says otherwise.
WebRTC configuration
Troubleshooting
401 on the signaling routes
- Send the call token from this call’s provision response, not the WebRTC token.
- Send the token in the
X-Call-Tokenheader.
403 when you create a call
- Set
modeto"voice-agent".
Browser requests fail with a CORS error
The bridge does not accept cross-origin requests from your domain. Send the HTTPS requests from your backend. See Call the bridge from your backend.The microphone does not work
- The user must allow the microphone. If they deny it,
getUserMediathrowsNotAllowedError. Do not create the call until you have the microphone. getUserMediaworks only on HTTPS pages and onlocalhost.- If no microphone is connected,
getUserMediathrowsNotFoundError.
The call connects, but there is no agent audio
- Pull the agent track after the peer connection is
connected. - Answer the pull offer with
POST .../sdp/renegotiate. - Pull again when you receive a
repullevent.
ICE does not connect
- Pass
creds.iceServerstoRTCPeerConnection. They include Cloudflare TURN. - A corporate firewall can block UDP. TURN over TLS on TCP 443 (
turns:turn.cloudflare.com:443) can get through most firewalls. - If the network inspects TLS traffic, TURN over TLS can fail. Ask the network team to exempt
turn.cloudflare.com.
The audio is choppy or has a long delay
- Call
pc.getStats(). Look atpacketsLost,jitterandroundTripTimeon theinbound-rtpandremote-inbound-rtpreports. - Find the
candidate-pairreport that isnominated, and look up its local candidate. IfcandidateTypeisrelay, the media goes through TURN. TURN adds delay.
The call ends after a few seconds
- Keep the events WebSocket open. When it closes, the bridge ends the call.
- Answer WebSocket pings. See Keepalive.
- Send the microphone offer within 30 seconds of provision. See Time limits.

