Skip to main content

Realtime WebRTC HTTP endpoints

Browser voice applications use WebRTC rather than a WebSocket, and the OpenAI realtime protocol supports that with two HTTP calls: one to mint a short lived client secret, and one to exchange the browser's SDP offer for the provider's answer. The gateway now serves both, so WebRTC sessions get the same keys, budgets and logging as every other call.

What changed​

Three HTTP endpoints joined the realtime family on the gateway.

EndpointPurpose
POST /v1/realtime/client_secretsReturns an ephemeral secret the browser can hold, so the long lived virtual key stays on your server.
POST /v1/realtime/callsTakes the browser's SDP offer, forwards it to the provider under the gateway's credential, and returns the SDP answer.
POST /v1/realtime/transcription_sessionsStarts a transcription only session.

The existing WebSocket endpoint at /v1/realtime is unchanged.

How a browser session works​

Your backend calls client_secrets with a virtual key and hands the returned secret to the page. The page creates an RTCPeerConnection, posts its offer to /v1/realtime/calls with the secret, and sets the answer as the remote description. Audio then flows directly between the browser and the provider, while the gateway has recorded the session, applied the key's budget, and will record usage when the session ends.

curl -X POST http://localhost:4000/v1/realtime/client_secrets \
-H "Authorization: Bearer $SPANWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"session": {"type": "realtime", "model": "gpt-realtime"}}'

Why it matters​

Until now, teams that wanted WebRTC had to give browsers a provider key or run their own relay. With these endpoints the gateway is the only credential holder, and realtime sessions show up on the Logs and Usage pages like any other request. See the realtime page for configuration and the models that support it.