# Voice API

> Place AI or human-bridged calls, follow and end them, read call history, transcripts and recordings, manage voice numbers and human operators.

Place AI or human-bridged phone calls, follow and end them, read call history
with transcripts and recordings, and manage your voice numbers and the people
your AI agents can escalate to. Everything an operator does with voice in the
app is available here.

## Authentication

Use an API key with the **voice** scope (or `voice:read` for read-only access,
`voice:write` for read and write), sent as a bearer token. Create one on the API
Keys page of the app. The organization is taken from the key; you never send it,
and ids that belong to another organization behave exactly like ids that do not
exist (`404`).

```
Authorization: Bearer pk_live_xxxxxxxxxxxxxxxx
```

Base URL: `https://api.pingx.ai`. The same service is also available over
Connect/gRPC at `pingx.voice.v1.VoiceService`.

Scope rule: `Get*`, `List*` and `Download*` calls need `voice:read`; every other
call needs `voice:write`.

Conventions: phone numbers are E.164 (`+919876543210`; spaces, dashes, dots and
parentheses are stripped); times are RFC3339 UTC; JSON field names are camelCase
over REST; every list takes `pageSize` (default 50, max 200) and `pageToken` and
returns `nextPageToken` (empty on the last page).

## Endpoints

| Method | Path | Scope | What it does |
|---|---|---|---|
| POST | `/voice/v1/calls` | write | `PlaceCall`: AI agent calls a customer |
| POST | `/voice/v1/human-calls` | write | `PlaceHumanCall`: bridge a human and a customer |
| GET | `/voice/v1/dials/{dialId}/status` | read | `GetCallStatus` |
| POST | `/voice/v1/dials/{dialId}:end` | write | `EndCall` |
| GET | `/voice/v1/calls` | read | `ListCalls` |
| GET | `/voice/v1/calls/{callId}` | read | `GetCall` |
| GET | `/voice/v1/calls/{callId}/transcript` | read | `GetCallTranscript` |
| GET | `/voice/v1/calls/{callId}/recording` | read | `DownloadCallRecording` (raw audio) |
| GET | `/voice/v1/numbers` | read | `ListNumbers` |
| POST | `/voice/v1/numbers` | write | `AddNumber` |
| DELETE | `/voice/v1/numbers/{numberId}` | write | `RemoveNumber` |
| POST | `/voice/v1/numbers/{numberId}:setDefault` | write | `SetDefaultNumber` |
| POST | `/voice/v1/numbers/{numberId}:setInboundAgent` | write | `SetInboundAgent` |
| GET | `/voice/v1/humans` | read | `ListHumans` |
| POST | `/voice/v1/humans` | write | `AddHuman` |
| PATCH | `/voice/v1/humans/{humanId}` | write | `UpdateHuman` (full replace of the fields) |
| DELETE | `/voice/v1/humans/{humanId}` | write | `RemoveHuman` |
| GET | `/voice/v1/human-assignments` | read | `ListHumanAssignments` |
| PUT | `/voice/v1/human-assignments/{agentId}/{humanId}` | write | `SetHumanAssignment` |

## Place a call

Calls are asynchronous. `PlaceCall` validates the request, queues the call and
returns a `dialId` immediately; the customer's phone rings a moment later.
Credit checks, number selection and registration checks happen at dial time, as
for calls placed from the app. A call refused (for example for insufficient credits) shows up
as `status: "failed"` with the reason in `outcome`.

```bash
curl -X POST https://api.pingx.ai/voice/v1/calls \
  -H "Authorization: Bearer $PINGX_API_KEY" -H "Content-Type: application/json" \
  -d '{"agentId": 12, "phone": "+919876543210", "name": "Asha K"}'
# {"dialId":"4821","status":"dialing"}
```

`PlaceCall` is **not idempotent**: each successful request places a new call.
After a timeout, check `GET /voice/v1/calls?leadId=<dialId>` before retrying.
`agentId` comes from the Agents API.

Poll the status every 2-5 seconds:

```bash
curl https://api.pingx.ai/voice/v1/dials/4821/status -H "Authorization: Bearer $PINGX_API_KEY"
# {"status":"in_progress","outcome":"","callId":"9021","hasTranscript":false,...}
```

`status` is `dialing`, `in_progress`, `completed` or `failed`. `callId` appears
once the call exists. Hang up an active call:

```bash
curl -X POST https://api.pingx.ai/voice/v1/dials/4821:end -H "Authorization: Bearer $PINGX_API_KEY"
# {"ended":true}
```

### Human-bridged call

Rings one of your humans first, then the customer, and joins them. No AI speaks;
the call is still recorded, transcribed and scored. The human must be active and
have a `phone`.

```bash
curl -X POST https://api.pingx.ai/voice/v1/human-calls \
  -H "Authorization: Bearer $PINGX_API_KEY" -H "Content-Type: application/json" \
  -d '{"humanId": 7, "phone": "+919876543210"}'
```

## Call history, transcripts, recordings

```bash
# newest first; filters: agentId, humanId, leadId, startedAfter, startedBefore (RFC3339)
curl "https://api.pingx.ai/voice/v1/calls?pageSize=20&startedAfter=2026-03-01T00:00:00Z" \
  -H "Authorization: Bearer $PINGX_API_KEY"

curl https://api.pingx.ai/voice/v1/calls/9021/transcript -H "Authorization: Bearer $PINGX_API_KEY"
# {"turns":[{"role":"assistant","text":"Hello, ..."},{"role":"user","text":"Hi"}]}
```

Each call has a `direction` (`outbound`, `inbound` or `human`), outcome, AI
summary, sentiment (1-5, 0 = unscored), your scored metrics, and
`hasTranscript` / `hasRecording`. Browser test calls made in the app are not
listed.

### Recording download

`DownloadCallRecording` returns the audio file itself (Ogg/Opus,
`Content-Type: audio/ogg`), authenticated by the same API key. There are no
signed URLs to fetch or expire:

```bash
curl -H "Authorization: Bearer $PINGX_API_KEY" -o call-9021.ogg \
  https://api.pingx.ai/voice/v1/calls/9021/recording
```

Whole-file only (no HTTP Range). `404` if the call has no recording
(`hasRecording` is false) or is not yours; `412` if the file is over 32 MiB.

## Numbers

```bash
curl -X POST https://api.pingx.ai/voice/v1/numbers -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" -d '{"number":"+14155550123","label":"Sales"}'
# a non-empty "syncError" means the number is saved but not yet dialable; it is retried automatically

# which AI agent answers inbound calls to this number (agentId 0 clears it; an
# unbound number refuses inbound calls)
curl -X POST https://api.pingx.ai/voice/v1/numbers/31:setInboundAgent \
  -H "Authorization: Bearer $PINGX_API_KEY" -H "Content-Type: application/json" -d '{"agentId": 12}'
```

Only voice numbers are managed here; WhatsApp numbers live in the WhatsApp API.

## Humans and escalation

```bash
curl -X POST https://api.pingx.ai/voice/v1/humans -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Raj","phone":"+911111111111","whatsappMobile":"+911111111111","purpose":"technician"}'

# allow agent 12 to escalate to human 7 over WhatsApp ("channel": "" revokes)
curl -X PUT https://api.pingx.ai/voice/v1/human-assignments/12/7 \
  -H "Authorization: Bearer $PINGX_API_KEY" -H "Content-Type: application/json" -d '{"channel":"whatsapp"}'
```

## Errors

`400` invalid input, `401` bad key, `403` key lacks the scope, `404` unknown id
or another organization's id, `409` already exists, `412` precondition (human
has no phone, recording too large), `500` internal.

## Not in this API

- **Leads and pipeline decisions.** Not available yet. A call creates its own lead record;
  `dialId` is that record's id.
- Browser (WebRTC) test calls and streaming.
- Agents and knowledge bases (Agents API).

