Realtime WebSocket mode

A second way to run a conversational call, for integrations written in code. One socket per call instead of one HTTP round trip per turn.

When to use it

The conversational webhook asks your endpoint for a reply once per turn and plays the audio file you return. That works for any tool that can answer an HTTP request, including n8n and Flowise, and it stays the default.

Realtime mode is for code. CallNode opens a WebSocket to your server when the call starts and keeps it open until the call ends. You receive transcripts as the caller speaks (partials and finals), the settled utterance as a turn, keypad digits, and, if you ask for it, the caller's raw audio. You send audio back whenever you like, ask for a transfer, or hang up. The caller can interrupt: speech or a keypress while your audio is playing stops it and you are told.

  • No per-turn HTTP round trip, no audio file hosting, no polling. Your reply starts playing as soon as the first frame arrives.
  • Your server must be reachable from the internet over TLS (wss://) and hold one socket per live call.
  • The webhook stays configured as the fallback: if your endpoint cannot be reached, or the socket dies mid-call, the call continues on the webhook. A number with neither ends the call with a busy tone rather than silence.

Enabling it

  • Per number: number page → Realtime WebSocket (advanced), or PATCH /api/v1/numbers/:id with { "voice": { "realtime": { "url": "wss://…", "auth": { "type": "bearer", "value": "…" } } } }. "realtime": null turns it off. Inbound calls to the number then use the socket.
  • At purchase: POST /api/v1/numbers takes the same voice.realtime block, so a number is live on the socket the moment it activates — no follow-up PATCH needed.
  • Per outbound call: POST /api/v1/outbound/calls with "realtime": { "url": "wss://…", "auth": { … } }. It overrides the from-number's setting for that call.
  • Auth uses the same shapes as the webhook: bearer (Authorization: Bearer), basic (user:password), or header (a header name and value). The secret is write-only; reads show valueSet: true.
  • The URL must be wss:// on a public hostname or IP. Private, link-local and CallNode infrastructure addresses are refused.

The connection

CallNode connects once per call with the headers X-CallNode-Call-Id (the same id as the API and call logs),User-Agent: CallNode-Realtime/1 and your auth header. Accept the upgrade within 15 seconds or the call falls back. Every frame in both directions is a JSON text message with a type field; binary frames are not used. Unknown frame types you send get an error frame back and are otherwise ignored, so new fields and frames can be added without breaking you.

Frames CallNode sends

typeFieldsWhen
session.startcallId, direction, from, to, number, metadata, audioIn { encoding, sampleRate, channels, optIn }, audioOut { accepts, rawEncoding, defaultSampleRate }, say { enabled, maxChars, maxQueued }, atFirst frame after the upgrade. The call is already answered. number is the CallNode number whose settings (voice) apply.
transcript.partialtext, atInterim recognition while the caller speaks, at most every 150 ms. Text is replaced by the next partial or final.
transcript.finaltext, speechFinal, atA finalised fragment. speechFinal marks the recogniser’s end-of-utterance guess.
turntext, atThe settled utterance, joined from finals after the same settle window the webhook mode uses. Most integrations act on this frame only.
audio.inaudioData (base64)Caller audio, only after you opt in with session.options. 16-bit signed little-endian PCM, 16 kHz, mono, one frame per ~20 ms.
dtmfdigit, atOne keypad digit (0-9, *, #, A-D). No buffering or terminator in this mode; you decide what a digit means.
say.startedid, durationMs, at, streamed?, estimated?A say frame is on its way to the caller. Speech is streamed: this frame arrives as soon as the first audio is queued, with an estimated durationMs (streamed: true, estimated: true), and say.done follows with the real length. A say that could not be streamed is rendered whole first; its say.started then carries the real length and no streamed flag.
say.doneid, durationMs, atThe speech for a streamed say frame is complete and durationMs is its real length. Use this frame, not the estimate, to know the caller has heard the whole sentence.
playback.startedat, queuedYour first audio of the call (audio.out or say) was queued for the caller; it starts within about half a second.
playback.interruptedtext, atThe caller spoke (a final transcript) or pressed a key while your audio was playing or queued; CallNode stopped the playing file and dropped the rest of the queue.
transfer.pendingto, atYour transfer was accepted for dialling. The transfer gates still run; a blocked transfer returns the caller to you.
errorcode, message, idSomething you sent was invalid or failed (unknown_frame, unsupported_audio, invalid_transfer_destination, invalid_text, text_too_long, say_queue_full, tts_failed). id echoes the say frame it refers to.
pongatReply to your ping.
session.endreason, durationSecs, sayChars, sayCount, atLast frame; the socket closes right after. The reason is the call’s end reason (caller hangup, your hangup, transfer, …).

Frames you send

typeFieldsEffect
session.optionsaudioIn (boolean)Opt in to audio.in frames. Off by default; transcripts arrive either way.
audio.outdata { audioDataType, sampleRate, audioData }, id (optional)Play audio to the caller. audioDataType raw (16-bit PCM, sampleRate required, 8000 or 16000), wav, mp3 or ogg; audioData base64, up to 2 MB per frame. Frames are queued and played in order, starting within about half a second; 8 kHz mono WAV or raw plays as-is, anything else is transcoded first.
saytext (≤ 1000 chars), id (optional)Speak text to the caller in the voice set on the number. Says play in order, never overlap, and are dropped by clear or a caller interruption. You get say.started and then say.done per frame, or error tts_failed.
clearStop playback and drop anything queued, including queued says. Use it to interrupt yourself; caller interruptions are handled for you.
transferto (E.164 or sip: URI)Hand the caller to a phone number or SIP endpoint. Same gates and billing as a webhook transfer; the socket receives transfer.pending, then session.end when the leg connects or the call ends.
hangupdrainMs (optional, default 1500)End the call once queued says have finished playing, plus drainMs for any audio.out still playing. A goodbye say followed by hangup is the natural pattern.
metadatadata (object)Merge into the call’s metadata (shown in call logs and status webhooks).
pingLiveness check; answered with pong. Standard WebSocket ping/pong works too.

Text mode: say

If you would rather not run a speech engine, send text. A say frame is rendered by CallNode with the voice chosen on the number (number page → Realtime WebSocket → Voice for spoken replies, or voice.realtime.voice on the API with an id from GET /api/v1/numbers/voices) and played to the caller. With no voice chosen, the platform default voice speaks.

Spoken replies come in two voice tiers. Standard Voice is a set of clear, natural voices at the realtime rate. Premium Voice is our most natural voice set, with far more languages and accents to choose from, at $0.04 per started minute. Pick the tier on the number page or with voice.realtime.tier ("standard" or "premium"); Premium voice ids come from GET /api/v1/numbers/voices?tier=premium. Premium is accepted only while it is offered on your account; otherwise the request fails with 400 validation_error and a message naming premium_not_available. Each tier has its own voice list, so switching tiers resets the voice to that tier's default until you pick one.

  • Up to 1000 characters per frame and 8 frames queued per call. Frames play in the order you send them and never overlap; say.started tells you when each one begins (with an estimated length) and say.done when the caller has heard it (with the real length).
  • Speech is streamed: the caller hears the first words a few hundred milliseconds after your frame, while the rest of the sentence is still being rendered. Send the first sentence as soon as you have it rather than waiting for a whole paragraph; later sentences of the same reply join the stream without a gap.
  • A caller interruption or your own clear drops queued says as well as the audio playing; a transfer does the same.
  • Mixing is fine: say for the words, audio.out for a jingle or a pre-recorded prompt.
  • Speech rendering is included in the realtime rate below; there is no per-character charge. Characters spoken are reported on the session.end frame.

Audio formats

  • To you (audio.in): 16-bit signed PCM, 16 kHz, mono, little-endian, base64 in JSON. About 32 kB/s per call; frames are dropped rather than queued if your socket falls more than 256 kB behind, so a slow reader loses audio, never the call.
  • From you (audio.out): raw 16-bit PCM at the sampleRate you state (8000 plays as-is; 16000 is resampled), or a complete wav, mp3 or ogg file. Each frame is one playback unit: send a sentence or a whole reply per frame, not 20 ms slices, and keep frames under 2 MB.
  • Speech recognition is CallNode's in both modes. If you only need text in and audio out, ignore audio.in entirely.

A minimal server

callnode-realtime-echo.js is a complete Node.js reference server (one dependency, ws): with RT_SAY=1 it greets, repeats what the caller said with say and says goodbye before hanging up; without it, it answers with beeps (audio.out). It hangs up on 9 and transfers on 5. The core of it:

const WebSocket = require('ws'); // Your agent: what the caller said in, the text to speak out. async function myAgent(text) { return 'You said: ' + text; } const wss = new WebSocket.Server({ port: 8765 }); wss.on('connection', (ws, req) => { const callId = req.headers['x-callnode-call-id']; ws.on('message', async (raw) => { const f = JSON.parse(raw); if (f.type === 'session.start') { ws.send(JSON.stringify({ type: 'session.options', audioIn: false })); ws.send(JSON.stringify({ type: 'say', id: 'greeting', text: 'Hi, how can I help?' })); } if (f.type === 'turn') { // f.text is what the caller said; answer with text (say) or your own audio (audio.out) const reply = await myAgent(f.text); ws.send(JSON.stringify({ type: 'say', id: 'reply', text: reply })); } if (f.type === 'dtmf' && f.digit === '9') { ws.send(JSON.stringify({ type: 'say', text: 'Goodbye.' })); ws.send(JSON.stringify({ type: 'hangup' })); // waits for the goodbye to finish } }); });

Behaviour and limits

  • Barge-in: a final transcript or a keypress while your audio is playing or queued stops it and sends playback.interrupted. Whatever the caller said still arrives as transcripts and a turn.
  • Fallback: connect failure, refusal, or a socket that closes before the call ends → the number's webhook takes over from the greeting; with no webhook the caller hears a busy tone and the call ends with reason realtime_unavailable or realtime_lost.
  • Transfers go through the same allowlist, destination-class, do-not-call, verification and volume gates as webhook transfers, and bill the same way. sip: destinations bill as SIP egress.
  • Front-door routing (hours, IVR, voicemail, failover) runs before the socket is opened; realtime mode is what the “webhook agent” leaf becomes when the number has a realtime URL.
  • One socket per call, opened by CallNode. There is no shared control socket; use the REST API for anything outside a live call.
  • Available on inbound calls, outbound calls and Web Voice; not on BYOC SIP delivery (there is no agent in that path) or wholesale trunks.

Billing

The call itself bills as usual (inbound or outbound minutes, including Pro Bundle minutes where they apply). Realtime mode adds $0.02 per started minute of socket time, drawn from your wallet and never from included minutes, as a realtime_charge line on Billing → History. That one rate covers speech rendering for say frames too. The rate is on GET /api/plans as realtimePerMinuteRate. A call that falls back to the webhook before the socket connected pays nothing extra. With Premium Voice chosen on the number, the socket time bills $0.04 per started minute instead (realtimePremiumPerMinuteRate), and only when every say frame on the call was rendered by the Premium engine; a call where a reply fell back to the standard engine bills the standard rate.

What is next

SDK examples in more languages. Tracked on the roadmap.