Skip to content

Stream token

A single endpoint that authenticates the realtime event stream WebSocket. Mint it on your backend, then hand it to the browser.

POST /stream/token

Returns { token: string, ttl_seconds: integer }.

Terminal window
curl https://api.sautipbx.com/api/stream/token \
-H "Authorization: Bearer sk_live_..."
# → 200 OK
# { "token": "eyJhbGc...", "ttl_seconds": 60 }

Open a WebSocket to the stream endpoint, passing the token as a query parameter:

const ws = new WebSocket("wss://api.sautipbx.com/api/stream?token=" + token);
ws.addEventListener("message", (e) => {
const ev = JSON.parse(e.data);
// ev.code is the stable machine code: switch on this
console.log(ev.code, ev.event, ev.sid, ev.data?.reason_code);
});

Every message uses the same envelope as a status callback, minus the id and accountId fields the socket omits. The code values are catalogued under Events & codes.