Skip to main content
The WebRTC Bridge connects a WebRTC client to a PolyAI voice agent. Your client sends and receives audio over WebRTC. Cloudflare carries the media. The bridge does the signaling over HTTPS, and sends call events on one WebSocket.
The WebRTC Bridge replaces the WebRTC Gateway. The gateway endpoint (wss://webrtc-gateway.<region>.platform.polyai.app/api/v1/webrtc/signal) is retired and does not accept calls. The WebRTC token that you used with the gateway also works with the bridge.
To add a voice call to a web page without code, use the Web Calling widget or the Android and iOS voice SDKs. Use this API only when you build your own WebRTC client.

Before you start

  • A WebRTC token for your project. See Authentication.
  • A browser or WebRTC library that supports Unified Plan SDP and renegotiation. Current versions of Chrome, Edge, Firefox and Safari do.
  • Permission to use the microphone. Browsers allow getUserMedia only on HTTPS pages and on localhost.

How a call works

  1. Provision. Your backend creates the call with your WebRTC token. The bridge returns a call ID, a call token and the ICE servers.
  2. Connect the microphone. The client sends an SDP offer for its microphone track. The bridge returns the answer.
  3. Open the events socket. The client opens a WebSocket for call events. It keeps the socket open for the whole call.
  4. Pull the agent audio. When the peer connection is connected, the client asks for the agent track. The bridge returns a new offer, and the client answers it.
  5. Hang up. Close the events socket, or send DELETE /api/v1/call/{callId}.
The bridge does not use trickle ICE. Gather candidates before you send an offer. Stop after about 2 seconds, and send the candidates that you have.

Time limits

If setup fails at any step, send DELETE /api/v1/call/{callId}. If you do not, the call holds resources until a time limit ends it.

Call the bridge from your backend

The bridge only accepts cross-origin browser requests from PolyAI origins. A page on your own domain cannot read the bridge’s HTTPS responses. Send every HTTPS request from your backend:
  • POST /api/v1/call uses your WebRTC token. Do not send the WebRTC token to the browser.
  • The signaling routes (/sdp, /sdp/pull, /sdp/renegotiate) and DELETE use the call token. Your backend relays them for the browser.
  • Authenticate your own users before you provision a call. If you do not, anyone can start calls on your account.
The browser connects directly for two things only:
  • The WebRTC peer connection, to Cloudflare.
  • The events WebSocket, to the bridge. WebSocket connections are not subject to CORS. If your page has a Content Security Policy, add your bridge host from Endpoints to connect-src with the wss:// scheme, for example wss://webrtc-bridge.us-1.platform.polyai.app.
A native or server client, which is not a browser, can call every route directly.
The bridge limits HTTPS requests from each source IP address to 10 a second, with bursts of up to 20. When you relay through your backend, all your users share your backend’s IP address. One call uses 4 to 6 requests, and 2 more for each repull. If you expect more than 2 new calls a second, contact PolyAI before you go live.

Authentication

Keep the WebRTC token on your server. The call token is safe to give to the browser.

Endpoints

Use the host in the region where your project is deployed. See the API reference for each route.

Example

This example has two parts: a Node.js backend that relays requests, and the browser code. It uses us-1. Change the host for your region. It is a starting point, not production code.

Backend (Node.js 22 or later, Express 5)

Browser

Load this as a module: <script type="module" src="call.js"></script>. Start it from a click, so that the browser lets the page play audio. To cancel during setup, pass an AbortSignal and abort it.
A production client also needs a timeout on each request, and must handle a lost connection. The API reference lists the failures to handle.
Last modified on December 2, 2026