Skip to main content

Live call monitoring

Create a call-scoped WebSocket session to receive live transcripts and optional audio through the platform.

Create a monitoring session for an ongoing call using your API token on your backend:

curl -X POST 'https://api.upon-ai.com/api/v1/calls/CALL_ID/monitor' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"audio": true}'

Omit audio, or set it to false, for transcripts only. Your token must have access to the call's workspace and, for restricted users, the agent. Requesting audio also requires live-audio access for the workspace. Approval does not guarantee the call has a supported active media connection; browser-only calls may have transcripts without audio.

The response has websocket_path, expires_in: 60, and audio. Connect within 60 seconds using the same API origin with the wss: scheme. Each ticket can be used once. Keep the API token on your backend; only send the short-lived ticket to an authorized browser. Do not log tickets or share them between clients.

// Run on your backend with SDK 0.1.4 or later:
const session = await client.createCallMonitorSession({
path: { callId: 'CALL_ID' },
body: { audio: true },
});
// Return only the session to your authenticated frontend.
// Browser: apiOrigin is your configured API origin, never a dashboard URL.
const url = new URL(session.websocket_path, apiOrigin);
url.protocol = 'wss:';
const socket = new WebSocket(url);
const items = new Map();
socket.onmessage = ({ data }) => {
const event = JSON.parse(data);
if (['transcript_snapshot', 'transcript_updated'].includes(event.type)) {
for (const item of event.transcripts) items.set(item.id, item);
// Render sorted by time_sec, then order for ties.
}
};

No client messages are needed. All frames are JSON text. Each connection is limited to one call; it cannot switch calls or use dashboard controls. The platform proxies the stream and never returns upstream credentials or media-server URLs.

EventFields and behavior
readycall_id, audio (requested mode, not proof that audio has connected).
transcript_snapshotcall_id, transcripts: conversation available when joining. May initially be empty while the stream connects.
transcript_updatedcall_id, transcripts: complete current conversation, including replacements of growing turns.
call_endedcall_id; followed by WebSocket close code 1000, reason call_ended.
audio_startedcall_id, stream_id, encoding: "pcm_s16le", sample_rate, channels. May repeat when the media format changes.
audio_chunkcall_id, stream_id, audio: base64 PCM bytes, aligned to complete frames.
audio_stoppedcall_id, stream_id, reason.
audio_errorcall_id, error: audio could not start; transcripts remain available.

Transcript items have id, role, content, timestamp, time_sec, and order. Roles include agent, user, tool_call_invocation, tool_call_result, node_transition, dtmf, sms, and injected. Tool and transition items include their available structured fields (tool_call_id, name, arguments, successful, node identifiers/names, transition_type, and digit). Pre-session tools appear in the same array with pre:-prefixed IDs. Transcripts are normalized platform events, not an upstream wire-protocol passthrough. Live text is raw, before post-call privacy processing.

PCM is signed 16-bit little-endian, interleaved when channels is 2. Use the announced sample rate and channel count; do not assume a fixed format. Typical phone audio is 8 kHz stereo. This is live delivery without audio replay. Slow consumers may lose audio frames; sustained congestion closes the connection with code 1013.

Closing the WebSocket releases that viewer's audio subscription. Other authorized viewers keep their shared stream. Audio entitlement is checked during streaming and revocation stops audio. API-token validity and call access are rechecked at connection time and every 15 seconds; loss of access closes with 1008. Transient monitoring failures can also close the stream. Reconnect with backoff by requesting a new ticket, and merge its fresh snapshot by item ID.

Session creation returns 400 for an invalid audio option, 401 for invalid authentication, 403 when requested audio is not enabled, 404 for a missing/inaccessible monitoring call, 409 when the call ended, 429 for ticket capacity, and 503 for temporary unavailability. A newly started call may briefly return 404 until discovery completes; retry with backoff. Expired or reused tickets fail the handshake with 401; revoked access fails with 403. Reconnecting does not restore a consumed ticket.

Example events​

The same item ID can arrive repeatedly as a spoken turn grows. Keep the latest version:

{
"type": "transcript_updated",
"call_id": "CALL_ID",
"transcripts": [
{"id": "agent_0", "role": "agent", "content": "How can I help?", "timestamp": null, "time_sec": 0.9, "order": 0},
{"id": "user_0", "role": "user", "content": "I need to reschedule", "timestamp": null, "time_sec": 2.1, "order": 1}
]
}

Audio format and a minimal silent stereo PCM frame:

{"type":"audio_started","call_id":"CALL_ID","stream_id":"STREAM_ID","encoding":"pcm_s16le","sample_rate":8000,"channels":2}
{"type":"audio_chunk","call_id":"CALL_ID","stream_id":"STREAM_ID","audio":"AAAAAA=="}

audio_started announces the requested or negotiated format; the first audio_chunk confirms media is arriving. Decode base64 to bytes, then read little-endian signed 16-bit samples. For two channels, consecutive samples alternate between the two channels. In a browser:

function decodePcm(base64) {
const bytes = Uint8Array.from(atob(base64), char => char.charCodeAt(0));
const view = new DataView(bytes.buffer);
const samples = new Float32Array(bytes.byteLength / 2);
for (let i = 0; i < samples.length; i++) {
samples[i] = view.getInt16(i * 2, true) / 32768;
}
return samples; // Interleaved samples; use audio_started for rate/channels.
}

For playback, buffer and schedule samples using the announced sample rate; starting a new player for each chunk will introduce gaps. Do not treat PCM bytes as a WAV or MP3 file. If you mix stereo to mono, average the channels to avoid clipping.

Reconnect and deployment behavior​

There is no session affinity requirement. The platform routes the ticket to its issuing server. During a deployment or server replacement, an existing socket can disconnect and an unused ticket can become unavailable. Obtain a fresh ticket with backoff rather than retrying a consumed ticket. The new transcript snapshot restores the conversation so far; audio resumes from the current point without replay.

A normal call end sends call_ended and closes with 1000. Code 1008 means monitoring access is unavailable; 1011 indicates a transport/server interruption; 1013 indicates a slow consumer. A network failure may appear as 1006 in the client without a close frame. Check call state and credentials before retrying, and stop retrying ended or inaccessible calls.

The API reference documents the authenticated session-creation request, response and error statuses.

Search documentation

Type to filter pages. Use ↑ ↓ to choose, then Enter to open.

0 matching pages
AI questions are sent only when you select Ask AI or press Enter on it. Don’t include API keys or customer data.