MOD-04 / WEBRTC & SDK REFERENCE API VERSION: 2026-10-01
WebRTC Session Quickstart
Mint a short-lived session credential on your backend, negotiate an SDP offer directly with the closest Sonora media relay, and receive structured tool events over the same peer connection.
01 / MINT EPHEMERAL TOKEN (SERVER) HTTPS POST
curl -X POST https://api.sonoravoice.example/v4/sessions \
-H "Authorization: Bearer $SONORA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "sonora-s2s-4.2",
"region": "auto",
"voice": "editorial-neutral",
"barge_in_ms": 40,
"codec": "opus/48000"
}' 02 / CONNECT WEBRTC PEER (CLIENT) TYPESCRIPT
import { createVoicePeer } from "@sonora/webrtc";
const { client_secret, edge_url } = await fetch("/api/sonora-token", {
method: "POST",
}).then((r) => r.json());
const peer = await createVoicePeer({
token: client_secret,
edgeUrl: edge_url,
echoCancellation: true,
});
peer.on("agent.tool_call", async (call) => {
const result = await runBackendLookup(call.arguments);
peer.sendToolResult(call.call_id, result);
}); DataChannel Event Reference
JSON Frames| Event Type | Direction | Payload Fields | Behavior |
|---|---|---|---|
| session.ready | Server -> Client | session_id, ice_servers, negotiated_codec | Confirms WebRTC peer state and active edge PoP assignment. |
| input.speech_started | Server -> Client | ts_ms, vad_confidence | Fires within 40ms of caller speech onset; flushes client audio queue. |
| agent.tool_call | Server -> Client | call_id, name, arguments_json | Requests structured backend lookup without halting ambient filler. |
| agent.turn_complete | Server -> Client | turn_id, latency_ms, billed_ms | Reports verified end-to-end turn latency and exact metered duration. |
Need Capacity Sizing Before Launch?
Use the interactive concurrency estimator on the overview plate to project latency and spend.