Voice Calls
Start calls, connect WebSockets, send commands, and retrieve recordings.
Voice has two surfaces:
- REST endpoints under
/callsfor call lifecycle, stream tokens, events, and recordings. - A bidirectional WebSocket from
POST /calls/{id}/stream-tokenfor live audio and commands.
For calls with more than two people, see Conference Calls.
Start an outbound call
These examples use the HTTP API directly and do not depend on an unreleased SDK. API reference pages show SDK examples only when the method is available in the verified stable package.
Set PINNACLE_API_KEY, PINNACLE_FROM_NUMBER, and PINNACLE_TO_NUMBER in your server environment. Set PINNACLE_IDEMPOTENCY_KEY to a new UUID for each intended call, and retain it when retrying that call. Only call recipients who have agreed to receive the call.
These examples create a call and a stream token. They do not enable recording. Enable recording only after obtaining the consent required for your use case; see recordings.
Requires Node.js 24 or later.
const apiKey = process.env.PINNACLE_API_KEY;
const from = process.env.PINNACLE_FROM_NUMBER;
const to = process.env.PINNACLE_TO_NUMBER;
const key = process.env.PINNACLE_IDEMPOTENCY_KEY;
if (!apiKey || !from || !to || !key) throw new Error("Set the four required environment variables");
async function post<T>(path: string, body: unknown, headers: Record<string, string> = {}): Promise<T> {
const response = await fetch(`https://api.pinnacle.sh${path}`, {
method: "POST",
headers: { "PINNACLE-API-Key": apiKey!, "Content-Type": "application/json", ...headers },
body: JSON.stringify(body),
signal: AbortSignal.timeout(30_000),
});
if (!response.ok) throw new Error(`Pinnacle returned HTTP ${response.status}`);
return await response.json() as T;
}
const call = await post<{ id: string }>("/calls", { from, to }, { "Idempotency-Key": key });
const stream = await post<{ stream_url: string }>(`/calls/${encodeURIComponent(call.id)}/stream-token`, {
commands_enabled: true,
stream_id: "agent",
});
// Pass stream.stream_url to your WebSocket client; do not log this bearer credential.Manual REST flow
- Create the call with
POST /calls, or use an existing inbound or outbound call ID. - Create a short-lived token with
POST /calls/{id}/stream-token. - Open the returned
stream_urlwith your WebSocket client and wait for the connection to open before sending commands. See Voice WebSockets.
Create a fresh stream token when reconnecting after expiry. The examples do not automatically reconnect. Use a bounded retry policy with backoff and stop when the call has ended.
Retrying safely
A create request that times out or fails mid-flight leaves you unsure whether a
call was placed. Retrying blindly dials the recipient twice. Send an
Idempotency-Key header and the call happens at most once, no matter how many
times you repeat the request.
curl -X POST https://api.pinnacle.sh/calls \
-H "PINNACLE-API-KEY: $PINNACLE_API_KEY" \
-H "Idempotency-Key: 2f1c8b34-9a1e-4a51-8f0f-6c4a1f4c21f7" \
-H "Content-Type: application/json" \
-d '{"from":"+14155559876","to":"+14155551234","record":true}'Reusing the key returns the original call rather than placing another:
| Situation | Response |
|---|---|
| First use of the key | 201 with the new call |
| Same key, same request | 200 with the original call — nothing was dialled |
| Same key, different request | 422 — the key is bound to its first request |
| Same key, first attempt still running | 409 — retry once it settles |
The 200 is how you tell a replay from a fresh call. Treat 409 as "wait and
retry with the same key"; sending a new key at that point is what causes the
second dial you were trying to avoid.
Keys are scoped to your team and expire after 24 hours, so the same value can
be reused for a genuinely new call after that. Two requests count as the same
when to, from, record and metadata match — metadata key order does not
matter.
If a call cannot be confirmed — a network timeout, or a 5xx — the key stays
bound rather than being released. That is deliberate: we cannot tell whether
the call was placed, and the safe assumption is that it was.
Pricing
| Call | Price |
|---|---|
| Outbound | $0.01 per minute |
| Inbound | $0.0085 per minute |
You pay for answered time only, rounded up to the whole minute, deducted from your credits when the call ends. Calls that never connect (busy, no answer, failed) are free. Recording is included. People in a conference also pay a conference fee on top of their call.
Direction and status values
Call objects use state; CALL.STATUS webhook payloads use status. Both fields share the same lifecycle values.
Direction values:
| Value | Meaning |
|---|---|
INBOUND | The call originated from an external caller and was received by one of your Pinnacle voice-enabled phone numbers. |
OUTBOUND | The call was created from Pinnacle and dialed out from one of your voice-enabled phone numbers. |
Status values:
| Value | Meaning |
|---|---|
INITIATED | Pinnacle accepted the call request and is setting up the call with the voice provider. |
RINGING | The call is ringing and has not been answered yet. |
ANSWERED | The call has been answered and is active. |
BRIDGED | The call is connected to another call leg, such as after a transfer or bridge command. |
ENDED | The call ended normally. |
FAILED | The call could not be established or could not continue because of a provider or system failure. |
NO_ANSWER | The call rang until timeout without being answered. |
BUSY | The destination was busy. |
CANCELED | The call was canceled before normal completion. |
Commands and audio frames
Voice WebSockets are bidirectional. Your app sends command frames to control the call and optional media frames when you generate live outbound audio. Pinnacle sends ack, event, and media frames back.
Command frame
Every command has the same envelope:
{
"event": "command",
"command_id": "cmd_welcome",
"action": "audio.play",
"params": {
"text": "Thanks for calling. How can I help?",
"voice": "female",
"language": "en-US"
}
}| Field | Meaning |
|---|---|
event | Always command for commands sent by your app. |
command_id | Your unique ID for matching the later ack; generate a new ID for each command. |
action | The command to run. See the catalog below. |
params | Command-specific options. Omit it for commands with no options. |
Pinnacle acknowledges each command with the same command_id:
{
"event": "ack",
"command_id": "cmd_welcome",
"action": "audio.play",
"status": "ok",
"sequence_number": 12
}Command catalog
See the Voice Command Reference for all 19 commands, required and optional fields, and example payloads.
Common command examples
Answer and start the conversation:
{
"event": "command",
"command_id": "cmd_answer",
"action": "call.answer",
"params": {
"as": "Support"
}
}Play text-to-speech:
{
"event": "command",
"command_id": "cmd_play_tts",
"action": "audio.play",
"params": {
"text": "Thanks for calling. Please hold while I look that up.",
"voice": "female",
"language": "en-US"
}
}Play a public audio URL. Replace the placeholder URL with your publicly accessible audio file:
{
"event": "command",
"command_id": "cmd_play_url",
"action": "audio.play",
"params": {
"url": "https://example.com/hold.wav",
"loop": 1,
"overlay": true
}
}Collect keypad input:
{
"event": "command",
"command_id": "cmd_input_digits",
"action": "input.get",
"params": {
"prompt": {
"text": "Enter your four digit PIN, then press pound."
},
"minDigits": 4,
"maxDigits": 4,
"terminatingDigit": "#",
"timeoutMs": 8000
}
}Collect structured speech:
{
"event": "command",
"command_id": "cmd_input_ai",
"action": "input.get",
"params": {
"prompt": {
"text": "Briefly describe what you need help with."
},
"ai": {
"extract": {
"type": "object",
"properties": {
"intent": {
"type": "string"
}
},
"required": ["intent"]
},
"instructions": "Classify the caller's support intent."
}
}
}Update call metadata:
{
"event": "command",
"command_id": "cmd_state",
"action": "call.update_state",
"params": {
"metadata": {
"ticket_id": "tkt_123",
"handoff": "billing"
}
}
}Audio frames
Use command helpers for most audio playback. Send raw media frames only when your app generates live audio itself.
Outbound media from your app to the call:
{
"event": "media",
"media": {
"track": "outbound",
"payload": "base64-mulaw-audio",
"chunk": 1,
"timestamp": "2026-06-24T00:00:00.000Z"
}
}Inbound media from Pinnacle to your app:
{
"event": "media",
"stream_sid": "stream_123",
"sequence_number": 42,
"media": {
"track": "inbound",
"payload": "base64-mulaw-audio",
"chunk": 7,
"timestamp": "2026-06-24T00:00:01.400Z"
}
}The stream uses 8 kHz, 8-bit mu-law audio. payload is base64-encoded audio bytes. sequence_number is monotonic for server frames and should be used for ordering.
Outbound audio is queued and played at real-time speed, so you can send it faster than real time. To interrupt it, for example when the caller starts talking, send the audio.clear command: it stops what's playing and drops what's still queued.
Server events
Pinnacle sends lifecycle and command-result events as event frames:
{
"event": "event",
"type": "call.answered",
"stream_sid": "stream_123",
"sequence_number": 8,
"payload": {
"call_id": "call_123"
}
}Listen for ack when you care whether a command was accepted. Listen for event for call lifecycle and input results. Listen for media for inbound audio.
Webhooks and recordings
Attach a webhook to a phone number with event: "CALL.STATUS" to receive call lifecycle updates. Recording download URLs are available from GET /calls/{id}/recording after the call is terminal and the recording has finished processing.
Reading recording status
record and recording_state answer different questions, and you need both to
tell a problem from a non-event:
record | recording_state | Meaning |
|---|---|---|
false | null | No recording was asked for. |
true | null | Asked for, none yet. While the call is live this is normal; once the call is terminal it means none was produced. |
true | PENDING | Audio uploaded, still being assembled. GET .../recording answers 425 until it is ready. |
true | READY | Downloadable. |
true | FAILED | Upload exhausted its retries. The audio is not recoverable. |
| any | DELETED | Removed on request or by retention. Deliberate, not lost. |
Download URLs are short-lived signed credentials. Fetch one when you need it rather than storing it, and treat it as a secret: anyone holding it can fetch the audio until it expires.
Consent and retention
Recording is off unless you ask for it, per call. What we do not do is anything about consent — that stays with you:
- Obtaining consent. Some jurisdictions require every participant to consent, others only one. We do not detect jurisdiction or verify consent.
- Announcing the recording. No notice or beep is played. If one is required, play it yourself.
- Honouring withdrawal mid-call.
recording.stopis available, but nothing triggers it automatically.
Recordings are retained for 90 days, after which they are deleted along
with their stored audio and recording_state becomes DELETED. Deletion runs
on a daily sweep, so treat the deadline as 90 days plus up to a day rather than
exactly 90. You can delete a recording sooner with
DELETE /calls/{id}/recording.
Voice is not currently supported for HIPAA or other PHI traffic. That needs a separate agreement and data-flow review — talk to us before sending it.