# Voice API

> Live voice sessions, call history, voice engines and phone line requests.

Part of the AGNT API reference. AGNT (https://agnt.ai) is the developer platform behind OpenAssistant (https://openassistant.us). Docs index: https://agnt.ai/llms.txt. Web page: https://agnt.ai/reference/api/voice

Base URL: `https://api.agnt.ai`. Auth: `Authorization: Bearer ak_live_...`.

## POST /voice/live/session

Create a live voice session

Creates a short-lived voice session between the user and one of their assistants, scoped to a chat or task. When you pass neither, a new chat is created. Connect your client to `websocketUrl` with `sessionToken`.

Acts as one user: send `X-User-Email`.

**Request body** (JSON)

- `assistantId` (string): Defaults to the assistant of the chat or task.
- `chatId` (string | null)
- `taskId` (string | null)

**Responses**

- `200`: Session
  - `ok` (boolean)
  - `provider` (string): Voice engine for this assistant.
  - `sessionId` (string): Pass to POST /voice/live/cancel to cancel before connecting.
  - `websocketUrl` (string): Where the client connects.
  - `sessionToken` (string): Single-use token for that connection.
  - `inputSampleRate` (integer): Microphone audio rate in Hz.
  - `outputSampleRate` (integer): Assistant audio rate in Hz.
  - `metadata` (object): Ids the session is bound to: accountId, userId, assistantId, chatId, taskId.
- `404`: call_context_not_found: the assistant, chat or task is not this user's.
- `409`: voice_engine_not_configured or voice_not_configured
- `429`: voice_session_rate_limited: too many sessions in a short time.

```bash
curl 'https://api.agnt.ai/voice/live/session' \
  -X POST \
  -H "Authorization: Bearer ak_live_..." \
  -H "X-User-Email: user@example.com" \
  -H "Content-Type: application/json" \
  -d '{
  "assistantId": "6660c4a1f2e3b7d8a9c01234",
  "chatId": "6660c4a1f2e3b7d8a9c01234",
  "taskId": "6660c4a1f2e3b7d8a9c01234"
}'
```

Example response:

```json
{
  "ok": true,
  "provider": "provider",
  "sessionId": "3f6c2a9e-8b41-4d7a-9c15-2e7b0d4a6f18",
  "websocketUrl": "wss://voice.agnt.ai/live"
}
```

## POST /voice/live/cancel

Cancel a live voice session

Cancels a live voice session the user created that has not connected yet. Returns `404` with `invalid_session` when there is no such session.

Acts as one user: send `X-User-Email`.

**Request body** (JSON)

- `sessionId` (string, required)

**Responses**

- `200`: Success
  - `ok` (enum, required) One of: `true`.
  - `cancelled` (enum, required) One of: `true`.
- `404`: Voice unavailable or invalid context
  - `status` (integer, required)
  - `error_code` (string)
  - `error` (string, required)

```bash
curl 'https://api.agnt.ai/voice/live/cancel' \
  -X POST \
  -H "Authorization: Bearer ak_live_..." \
  -H "X-User-Email: user@example.com" \
  -H "Content-Type: application/json" \
  -d '{
  "sessionId": "6660c4a1f2e3b7d8a9c01234"
}'
```

Example response:

```json
{
  "ok": true,
  "cancelled": true
}
```

## GET /voice/providers

List voice engines

Returns the voice engines configured for your app, each with its voices and default voice. `available` says whether an engine can take calls now.

**Responses**

- `200`: Voice catalog
  - `ok` (boolean, required)
  - `providers` (object[], required)
    - `id` (string): Voice engine id (provider)
    - `name` (string)
    - `enabled` (boolean)
    - `available` (boolean)
    - `defaultVoiceId` (string)
    - `voices` (object[])
      - `voiceId` (string)
      - `name` (string)
      - `gender` (enum) One of: `male`, `female`, `other`.
      - `description` (string)

```bash
curl 'https://api.agnt.ai/voice/providers' \
  -H "Authorization: Bearer ak_live_..."
```

Example response:

```json
{
  "ok": true,
  "providers": [
    {
      "id": "6660c4a1f2e3b7d8a9c01234",
      "name": "Ava",
      "enabled": true,
      "available": true
    }
  ]
}
```

## GET /voice/calls

List calls

Returns the user's calls, newest first: calls placed for them and each call their assistant made on their tasks. Requires `X-User-Email`.

Acts as one user: send `X-User-Email`.

**Query parameters**

- `limit` (integer)

**Responses**

- `200`: Calls
  - `ok` (boolean)
  - `calls` (object[])
    - `source` (enum) One of: `direct`, `task`.
    - `id` (string)
    - `taskId` (string): Task rows only
    - `taskTitle` (string | null)
    - `relationship` (enum): user: a call with the user. internal: someone in the user's organization. third_party: anyone else. One of: `user`, `internal`, `third_party`.
    - `target` (object | null)
      - `phoneNumber` (string)
      - `displayName` (string)
    - `goal` (string | null)
    - `status` (string): direct: calling, completed, failed, no_answer, voicemail; task: pending, preparing, calling, in_progress, completed, failed, needs_input
    - `disposition` (string | null)
    - `startedAt` (string | null)
    - `endedAt` (string | null)
    - `durationSeconds` (number)
    - `resultSummary` (string | null)
    - `transcript` (string | null)
- `400`: missing_user: send X-User-Email

```bash
curl 'https://api.agnt.ai/voice/calls' \
  -H "Authorization: Bearer ak_live_..." \
  -H "X-User-Email: user@example.com"
```

Example response:

```json
{
  "ok": true,
  "calls": [
    {
      "source": "direct",
      "id": "6660c4a1f2e3b7d8a9c01234",
      "taskId": "6660c4a1f2e3b7d8a9c01234",
      "taskTitle": "tasktitle"
    }
  ]
}
```

## POST /phone-line-requests

Create a phone line request

Requests phone numbers for the user's primary assistant. When the numbers are ready, they appear on the assistant under `channels`.

Acts as one user: send `X-User-Email`.

**Request body** (JSON)

- `requestedChannels` (object): Each defaults to false
  - `imessage` (boolean)
  - `sms` (boolean)
  - `whatsapp` (boolean)
  - `voice` (boolean)
- `notes` (string)

**Responses**

- `201`: Created
  - `ok` (boolean)
  - `request` (object)
    - `id` (string)
    - `assistant` (string | null)
    - `requestedChannels` (object)
      - `imessage` (boolean)
      - `sms` (boolean)
      - `whatsapp` (boolean)
      - `voice` (boolean)
    - `notes` (string | null)
    - `status` (enum) One of: `pending`, `fulfilled`, `dismissed`.
    - `reviewedAt` (string | null)
    - `dismissalReason` (string | null)
    - `createdAt` (string)
- `400`: The user has no assistant, or a request is pending
- `401`: No user on the call: send X-User-Email with an account key, or use a user-scoped key
  - `status` (integer)
  - `error_code` (string)
  - `error` (string)

```bash
curl 'https://api.agnt.ai/phone-line-requests' \
  -X POST \
  -H "Authorization: Bearer ak_live_..." \
  -H "X-User-Email: user@example.com" \
  -H "Content-Type: application/json" \
  -d '{
  "requestedChannels": {
    "imessage": true,
    "sms": true,
    "whatsapp": true,
    "voice": true
  },
  "notes": "notes"
}'
```

Example response:

```json
{
  "ok": true,
  "request": {
    "id": "6660c4a1f2e3b7d8a9c01234",
    "assistant": "assistant",
    "requestedChannels": {
      "imessage": true,
      "sms": true,
      "whatsapp": true,
      "voice": true
    },
    "notes": "notes"
  }
}
```

## GET /phone-line-requests/mine

Retrieve the latest phone line request

Returns the user's most recent phone line request for their primary assistant, or `request: null` when there is none.

Acts as one user: send `X-User-Email`.

**Responses**

- `200`: Latest request
  - `ok` (boolean)
  - `request` (object | null)
    - `id` (string)
    - `assistant` (string | null)
    - `requestedChannels` (object)
      - `imessage` (boolean)
      - `sms` (boolean)
      - `whatsapp` (boolean)
      - `voice` (boolean)
    - `notes` (string | null)
    - `status` (enum) One of: `pending`, `fulfilled`, `dismissed`.
    - `reviewedAt` (string | null)
    - `dismissalReason` (string | null)
    - `createdAt` (string)
- `401`: No user on the call: send X-User-Email with an account key, or use a user-scoped key
  - `status` (integer)
  - `error_code` (string)
  - `error` (string)

```bash
curl 'https://api.agnt.ai/phone-line-requests/mine' \
  -H "Authorization: Bearer ak_live_..." \
  -H "X-User-Email: user@example.com"
```

Example response:

```json
{
  "ok": true,
  "request": {
    "id": "6660c4a1f2e3b7d8a9c01234",
    "assistant": "assistant",
    "requestedChannels": {
      "imessage": true,
      "sms": true,
      "whatsapp": true,
      "voice": true
    },
    "notes": "notes"
  }
}
```
