Skip to main content
Stream Calls let your application stream the audio of a WhatsApp voice call in real time: you start the call with an HTTP request, open a WebSocket, and exchange audio in both directions — your user’s microphone to the other party, and the other party’s voice to the speaker.
You need an already connected unofficial WhatsApp connection and an API Key. Generate your key in the Dashboard.

How it works

The flow is always outbound (you call a number) and runs in the browser, where the microphone and speaker live:
1

Start the call

POST /calls/stream returns a callId and a wsUrl ready to open.
2

Open the WebSocket

The wsUrl already carries the authentication. Text frames are lifecycle events; binary frames are audio.
3

Exchange audio

Send the microphone as binary PCM and play the binary audio you receive.
4

Finish

Close the WebSocket to hang up. The recording is available at the end.
Under the hood, audio flows between the browser and the WhatsApp bridge; D-API is a bidirectional pipe. Incoming calls do not come through here — they arrive via the call.offer webhook.

With the Node SDK

d-api-sdk does the steps below for you: starts the call, opens the WebSocket, hands you the audio in 20 ms frames and reconnects if the network drops. The steps that follow describe the protocol, for integrations in other languages or straight in the browser.
Recommended: WebRTC. The same code with { transport: "webrtc" }: the audio goes over UDP with Opus and FEC, copes better with bad networks and falls back to the WebSocket on its own.

Step 1 — Start the call

Call POST /calls/stream with the session and the destination number (with country code, digits only).
The response contains the call identifier and the stream URL:
string
Call identifier. Use it to fetch the recording later.
string
Opaque WebSocket URL, with callId and token already embedded. Open it exactly as received — do not build the URL yourself.
string
Access token exclusive to this call, generated for each call. It is already inside the wsUrl. It is not your API Key: it only opens this call’s WebSocket and stops working when the call ends.
Your API Key must never reach the browser. Start the call from your backend and hand the browser only the wsUrl — it carries only the call token. Even so, treat the wsUrl as a short-lived secret (do not log it) while the call is active.
An example of starting the call from the backend, keeping the key out of the browser:

Step 2 — Connect to the WebSocket

Open the wsUrl and set binaryType to receive audio as an ArrayBuffer.
There is no post-connection handshake: authentication is in the URL. If the server refuses, it sends an error event and closes the connection.

Step 3 — Capture and play the audio

Audio on the wire is raw PCM (s16le, 16 kHz, mono), in frames of 20 ms = 320 samples = 640 bytes. The simplest way to get the format right is to run the AudioContext at 16 kHz — the browser resamples the microphone for you — and convert Float32 ⇄ Int16 inside an AudioWorklet.
Run the AudioContext at sampleRate: 16000. This way you avoid resampling the microphone by hand, and every worklet frame already comes out in the exact stream format.
In the browser, prefer the SDK with WebRTC. With transport: "webrtc", the browser plays the audio with its own jitter buffer and conceals packet loss, no worklet needed. If you build your own player, do not restart the pre-buffer on every missing sample: over the WebSocket a late frame is common, and each restart becomes ~100 ms of silence (choppy audio).
Create the voip-worklet.js worklet (reference implementation, the same one the SDK uses):
Wire up the microphone, the worklet, and the WebSocket:
Do not send microphone audio before the accepted event. Until then the other party is not ready yet. The canSendUplink flag above takes care of this.

Step 4 — Track the lifecycle

The WebSocket’s text frames are JSON events in the { "type": ... } format.
The ended event carries a reason: hangup, rejected, timeout, accepted_elsewhere, terminate (maximum duration reached), ws_closed, among others. If the WebSocket closes without an ended, treat it as the call ending.

Step 5 — Control the call

Just stop sending the microphone. The simplest way is to disable the audio track:
Alternatively, the server also accepts a text control message: ws.send(JSON.stringify({ type: "mute", muted: true })).
Closing the WebSocket hangs up the call — the server interprets the close as a hangup.
When you are done, stop the microphone and close the AudioContext:

Reconnection (optional)

By default, if the WebSocket drops, the server hangs up the call. To keep the call alive through a network drop or a server switch during a deploy, append &resume=1 to the wsUrl. With it:
  • A socket drop does not hang up: the call stays active and waits for you to reconnect for up to 20 seconds.
  • Reconnect with the same wsUrl. The server resumes the call and replays the events from the beginning (calling, ringing, accepted…). Ignore the ones you already handled.
  • The server may close the connection with code 1012 (service restart) so that you reconnect. Treat it as a drop.
  • To hang up, close with code 1000 — ws.close(1000) — or send { "type": "hangup" }. Any other close is treated as a drop.
  • If nobody reconnects within 20 seconds, the call is hung up. The recording covers the entire call, with silence for the period the socket was down.

Audio format

All audio, in both directions, follows exactly this format:
PCM s16le
Signed 16-bit integers, little-endian. Binary frames (not base64).
16000 Hz
1 (mono)
320 samples = 640 bytes = 20 ms
Send at real-time pace (one frame every ~20 ms), without accumulating and flushing in batches.

Recording

By default, stream calls are recorded. Near the end, the server sends:
The files are 16 kHz mono WAV (full = mix, sender/recipient = separate sides). The same recording is also available later at GET /api/v1/calls/:callId. To skip recording, send "record": false in POST /calls/stream:
The audio is discarded: nothing goes to storage, and there is no recording event or call.audio webhook.
The account can also turn off recording for all calls in the panel’s privacy settings. When it is off, "record": true does not turn it back on.

Errors and limits

Limit on new calls per user (default: 10 every 60 s). Prevents WhatsApp blocks caused by too many attempts. Wait before trying again.
The voice stream is currently unavailable. Try again later.
3600 s
When the limit is reached, the call ends with ended and reason: "terminate".
error events carry a code: unavailable, not_found, unauthorized, or forbidden.

Full example

A minimal client that starts the call (via your backend), connects, streams audio, and offers mute/hang up:

Next steps

Call webhooks

Receive incoming calls (call.offer) and the lifecycle via webhook.

API Reference

Authentication, sessions, and every D-API endpoint.