# Types

> Field-level reference for every DTO.

Every type below is a serde envelope. Fields are encoded in the order
listed. See [Envelope Format](/rpc/envelope-format) for primitive encodings.

## Enums

### `ErrorCode` (encoded as `int32`)

| Value | Name                       | Meaning                                        |
| ----: | -------------------------- | ---------------------------------------------- |
| `0`   | `SUCCESS`                  | Request accepted.                              |
| `1`   | `ERR_INVALID_TRUNK`        | Unknown or unauthorized `trunk_id`.            |
| `2`   | `ERR_INVALID_DESTINATION`  | `to` could not be parsed or routed.            |
| `3`   | `ERR_RATE_LIMITED`         | Per-tenant CPS budget exhausted.               |
| `4`   | `ERR_CIRCUIT_BREAKER`      | Trunk is unhealthy; gateway is shedding load.  |
| `5`   | `ERR_INTERNAL_ERROR`       | Unspecified gateway-side failure.              |
| `6`   | `ERR_VALIDATION_FAILED`    | DTO failed schema validation.                  |
| `7`   | `ERR_UNAUTHORIZED`         | JWT missing, expired, or wrong tenant.         |

### `DialplanAction` (encoded as `int32`)

Values 0-6 are usable as `default_app` on `Originate`. Values 7-12 are
**call-control verbs** — only valid through `ExecuteDialplan` against
an active `call_sid`.

| Value | Name                     | Notes                                                                  |
| ----: | ------------------------ | ---------------------------------------------------------------------- |
| `0`   | `HANGUP`                 |                                                                        |
| `1`   | `PARK`                   |                                                                        |
| `2`   | `MUSIC_ON_HOLD`          |                                                                        |
| `3`   | `PLAYBACK`               | `app_args` = absolute path to .wav                                     |
| `4`   | `UNPARK_AND_BRIDGE`      | `app_args` = target call_sid                                           |
| `5`   | `ANSWER`                 |                                                                        |
| `6`   | `AI_BIDIRECTIONAL_STREAM`| `app_args` = agent_id                                                  |
| `7`   | `TRANSFER`               | RFC 3515 SIP REFER. `app_args` = destination URI or E.164.             |
| `8`   | `MUTE`                   | `app_args` = "" (gateway-side TX silence) or `"wire"` (also recvonly re-INVITE). |
| `9`   | `UNMUTE`                 | Same `app_args` shape as MUTE.                                         |
| `10`  | `HOLD`                   | sendrecv → sendonly re-INVITE; opposite leg gets MOH if trunk-configured.|
| `11`  | `UNHOLD`                 | Lifts a previous HOLD.                                                 |
| `12`  | `SEND_DTMF`              | `app_args` = `"<digit>:<mode>:<duration_ms>"` (mode = rfc2833 \| info; `inband` is not supported today). |

### `InboundRule` (encoded as `int32`)

| Value | Name                  |
| ----: | --------------------- |
| `0`   | `REJECT`              |
| `1`   | `PLAY_AND_HANGUP`     |
| `2`   | `NOTIFY_AND_HANGUP`   |
| `3`   | `HANDLE_AI`           |

### `EventType` (encoded as `int32`)

| Value | Name                       |
| ----: | -------------------------- |
| `0`   | `UNKNOWN`                  |
| `1`   | `CHANNEL_CREATE`           |
| `2`   | `CHANNEL_ANSWER`           |
| `3`   | `CHANNEL_HANGUP_COMPLETE`  |
| `4`   | `CHANNEL_HOLD`             |
| `5`   | `CHANNEL_RESUME`           |

## Request DTOs

### `OriginateRequest`

| Field                  | Type             | Notes                                                |
| ---------------------- | ---------------- | ---------------------------------------------------- |
| `trunk_id`             | `string`         | Configured outbound trunk to use.                    |
| `to`                   | `string`         | E.164 number or full SIP URI.                        |
| `call_from`            | `string`         | Caller-ID. Subject to per-trunk allow-listing.       |
| `ai_websocket_url`     | `string`         | If set, gateway dials AI bridge over WS for this call. |
| `ai_quic_url`          | `string`         | Same, but QUIC. One of the two should be set when using `AI_BIDIRECTIONAL_STREAM`. |
| `tenant_id`            | `string`         | Echoed for audit; must match JWT tenant.             |
| `max_duration_ms`      | `int32`          | Hard cap. `0` = trunk default.                       |
| `call_sid`             | `string`         | Optional client-provided idempotency key.            |
| `default_app`          | `DialplanAction` | What the call lands in once answered. The control-plane API (`telephony.originate`) defaults this to `AI_BIDIRECTIONAL_STREAM` (=6) when omitted. The polyglot SDK signatures default to `PARK` (=1) at the C-FFI boundary. |
| `default_app_args`     | `string`         | Per-app argument string (e.g. playback URL, agent_id). With `default_app=AI_BIDIRECTIONAL_STREAM` and an empty `default_app_args` the runtime has no agent to bridge — the call answers silent. |
| `auto_barge_in`        | `bool`           | Allow late `Barge` calls without re-handshake.       |
| `barge_in_patience_ms` | `int32`          | Grace window for the bargee before forced merge.     |
| `client_id`            | `string`         | UUID of the SDK process. Routes `CallEvent`s back.   |

### `BulkRequest`

| Field                          | Type             | Notes                                                  |
| ------------------------------ | ---------------- | ------------------------------------------------------ |
| `csv_url`                      | `string`         | HTTPS URL of a CSV; first column = E.164 destination.  |
| `template_trunk_id`            | `string`         | Same as `OriginateRequest.trunk_id` for every row.     |
| `template_to`                  | `string`         | Override the CSV's `to` (rarely used).                 |
| `template_call_from`           | `string`         |                                                        |
| `template_ai_websocket_url`    | `string`         |                                                        |
| `template_ai_quic_url`         | `string`         |                                                        |
| `template_tenant_id`           | `string`         |                                                        |
| `template_max_duration_ms`     | `int32`          |                                                        |
| `template_default_app`         | `DialplanAction` |                                                        |
| `template_default_app_args`    | `string`         |                                                        |
| `calls_per_second`             | `int32`          | Pacing.                                                |
| `max_concurrent_calls`         | `int32`          | Cap on simultaneous in-flight calls.                   |
| `campaign_id`                  | `string`         | Used by `AbortBulk`.                                   |

### Single-field requests

| DTO                          | Field                                             |
| ---------------------------- | ------------------------------------------------- |
| `AbortBulkRequest`           | `string campaign_id`                              |
| `TerminateRequest`           | `string call_sid`                                 |
| `BargeRequest`               | `string call_sid`                                 |
| `EventStreamRequest`         | `string client_id`                                |
| `GetIncomingCallsRequest`    | `string trunk_id`                                 |
| `BucketRequest`              | `string bucket_id`                                |

### `SetInboundRoutingRequest`

| Field              | Type          |
| ------------------ | ------------- |
| `trunk_id`         | `string`      |
| `rule`             | `InboundRule` |
| `audio_url`        | `string`      |
| `webhook_url`      | `string`      |
| `ai_websocket_url` | `string`      |
| `ai_quic_url`      | `string`      |

### `AnswerIncomingCallRequest`

| Field              | Type     |
| ------------------ | -------- |
| `call_sid`         | `string` |
| `ai_websocket_url` | `string` |
| `ai_quic_url`      | `string` |

### `BucketActionRequest`

| Field       | Type     | Notes                                       |
| ----------- | -------- | ------------------------------------------- |
| `bucket_id` | `string` |                                             |
| `action`    | `int32`  | `0=hangup`, `1=unpark+bridge`, `2=playback` |

### `ExecuteDialplanRequest`

| Field      | Type             |
| ---------- | ---------------- |
| `call_sid` | `string`         |
| `action`   | `DialplanAction` |
| `app_args` | `string`         |

## Response DTOs

### `OriginateResponse` / `TerminateResponse` / `AnswerIncomingCallResponse`

| Field           | Type        |
| --------------- | ----------- |
| `call_sid`      | `string`    |
| `status`        | `string`    |
| `error_message` | `string`    |
| `error_code`    | `ErrorCode` |
| `timestamp_ms`  | `int64`     |

### `BulkResponse`

| Field            | Type     |
| ---------------- | -------- |
| `status`         | `string` |
| `loaded_numbers` | `int32`  |

### `GetIncomingCallsResponse`

| Field   | Type                       |
| ------- | -------------------------- |
| `calls` | `vector<IncomingCallInfo>` |

### `IncomingCallInfo`

| Field                | Type     |
| -------------------- | -------- |
| `call_sid`           | `string` |
| `call_from`          | `string` |
| `start_timestamp_ms` | `int64`  |

### `ListBucketsResponse`

| Field     | Type                  |
| --------- | --------------------- |
| `buckets` | `vector<BucketInfo>`  |

### `BucketInfo`

| Field            | Type     |
| ---------------- | -------- |
| `bucket_id`      | `string` |
| `pending_count`  | `int32`  |

### `BucketCallList`

| Field       | Type             |
| ----------- | ---------------- |
| `call_sids` | `vector<string>` |

### `BucketActionResponse`

| Field             | Type    |
| ----------------- | ------- |
| `processed_count` | `int32` |

### `ExecuteDialplanResponse`

| Field           | Type        |
| --------------- | ----------- |
| `status`        | `string`    |
| `error_message` | `string`    |
| `error_code`    | `ErrorCode` |

### `Empty`

No fields. The serde envelope is just the 6-byte header (`v=0`, `cv=0`,
`payload_size=0`).

## Streaming DTOs

### `AudioFrame` — see [Audio Frames](/rpc/audio-frames)

### `CallEvent` — see [Events](/rpc/events)
