> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.rasen.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.rasen.ai/_mcp/server.

# Connect a SIP trunk

> Connect a workspace SIP setup, manage inbound connections and outbound trunks, import an existing number, and follow setup operations over SSE.

## Summary

This guide connects a workspace SIP setup, configures its connections and trunks, and imports an existing number.
It also follows asynchronous operations and shows how to edit or remove the setup.
It does not cover agent assignments; see [Route phone calls](/guides/phone-numbers).

## Facts

| Item                | Value                                                                                                                                                                       |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Capability          | `numbers.assign`                                                                                                                                                            |
| Setup operations    | `getSipTrunkSetup`, `connectSipTrunk`, `disconnectSipTrunk`, `regenerateSipAddress`                                                                                         |
| Setup paths         | `GET`, `POST`, `DELETE /telephony/sip-trunk`; `POST /telephony/sip-trunk/address/regenerate`                                                                                |
| Inbound operations  | `createSipInboundConnection`, `updateSipInboundConnection`, `deleteSipInboundConnection`                                                                                    |
| Inbound paths       | `POST /telephony/sip-trunk/inbound-connections`; `PATCH`, `DELETE /telephony/sip-trunk/inbound-connections/{connection_id}`                                                 |
| Outbound operations | `createSipOutboundTrunk`, `updateSipOutboundTrunk`, `deleteSipOutboundTrunk`                                                                                                |
| Outbound paths      | `POST /telephony/sip-trunk/outbound-trunks`; `PATCH`, `DELETE /telephony/sip-trunk/outbound-trunks/{trunk_id}`                                                              |
| Number import       | `importSipNumber`: `POST /telephony/sip-trunk/phone-numbers/import`                                                                                                         |
| Stream              | `streamSipTrunkSetup`: `GET /telephony/sip-trunk/stream`, `text/event-stream`                                                                                               |
| Headers             | `Authorization` on every request; `Idempotency-Key` on every mutation; `If-Match` on edits, deletes and address regeneration                                                |
| Regions             | `india`, `global`; each entry of the setup's `addresses` has a `region` and a `region_state` (`open` or `closed`)                                                           |
| Credentials         | Outbound trunk `username` and `password` are write-only; reads expose `has_password`                                                                                        |
| Failure fields      | `failed_step` and `failure_reason` on the setup; `failure_reason` on each operation. Both are `null` when nothing failed                                                    |
| `failure_reason`    | `provider_refused`, `provider_conflict`, `provider_unavailable`, `provider_auth_failed`, `provider_rate_limited`, `sip_trunk_not_ready`, `internal_error`. The list is open |
| Environment         | `RASEN_API_BASE` (ending in `/v1`), `RASEN_API_KEY`, `ETAG`, `CONNECTION_ID`, `TRUNK_ID`, `SIP_ENDPOINT`, `PHONE_NUMBER`                                                    |
| Python              | 3.10 or later, with `httpx`                                                                                                                                                 |
| TypeScript          | Node.js 22 or later, with built-in `fetch`                                                                                                                                  |

## Steps

Set `SIP_ENDPOINT` to your carrier or PBX host name, without a scheme or path.
Set `PHONE_NUMBER` to an E.164 number you already own at your carrier.
Use the returned `resource_id` for `CONNECTION_ID` after creating an inbound connection, and for `TRUNK_ID` after creating an outbound trunk.
For an existing setup, read those IDs from `inbound_connections` and `outbound_trunks`.

### 1. Read the setup and its ETag

**`curl`**

```bash curl
curl --fail-with-body -sS -i "$RASEN_API_BASE/telephony/sip-trunk" \
  -H "Authorization: Bearer $RASEN_API_KEY"
```

**`Python`**

```python Python
import os

import httpx

response = httpx.get(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}'},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk`, {
  headers: { Authorization: `Bearer ${RASEN_API_KEY}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

Set `ETAG` to the returned `ETag`, including its quotes.
Refresh `ETAG` from a mutation response or repeat this read before each later edit.
If `enabled` is `false`, SIP trunking is unavailable for the workspace.
A `null` address has not been created yet.

### 2. Connect or resume the setup

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X POST "$RASEN_API_BASE/telephony/sip-trunk" \
  -H "Authorization: Bearer $RASEN_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" -d '{"label":"Support SIP"}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.post(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4())},
    json={"label": "Support SIP"},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk`, {
  method: "POST",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
  body: JSON.stringify({ label: "Support SIP" }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The `202` response contains `setup`, `resource_id` and `operation_id`.
Acceptance does not mean the asynchronous operation succeeded.

This request is also the retry for a failed setup.
If the setup reports `state: failed`, read `failed_step` and `failure_reason` first, then send the request again with a new `Idempotency-Key`.
If the same `failure_reason` comes back, contact support with the `X-Request-Id` of the retry.

### 3. Follow setup operations

**`curl`**

```bash curl
curl --fail-with-body -N -sS "$RASEN_API_BASE/telephony/sip-trunk/stream" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Accept: text/event-stream"
```

**`Python`**

```python Python
import os

import httpx

with httpx.stream(
    "GET", f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/stream',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Accept": "text/event-stream"},
    timeout=None,
) as response:
    response.raise_for_status()
    for line in response.iter_lines():
        print(line)
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/stream`, {
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, Accept: "text/event-stream" },
});
if (!response.ok || !response.body) throw new Error(`HTTP ${response.status}`);
const decoder = new TextDecoder();
for await (const chunk of response.body) console.log(decoder.decode(chunk, { stream: true }));
```

Each `sip.setup` event contains a `SipTrunkSnapshot`: `setup`, up to 100 recent `operations`, and `revision`.
Match `operation_id` to an operation's `id`, then inspect its `state`.
States include `requested`, `dispatched`, `running`, `succeeded`, `failed` and `cancelled`.
A `failed` operation has a `failure_reason`, with the same codes as the setup's `failure_reason`.
A `bind_number` operation that failed with `sip_trunk_not_ready` ran before the setup was ready: wait for `state: ready`, then provision the number again.

Keep the last SSE `id` and send it as `Last-Event-ID` when reconnecting.
This suppresses an unchanged snapshot; reconnecting returns the latest state rather than a historical event log.
The stream never creates or retries work, and it checks API-key authorization again on every read.
Treat unknown states as unknown rather than success.

### 4. Create an inbound connection

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X POST "$RASEN_API_BASE/telephony/sip-trunk/inbound-connections" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" -d '{"region":"global"}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.post(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/inbound-connections',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4())},
    json={"region": "global"},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/inbound-connections`, {
  method: "POST",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
  body: JSON.stringify({ region: "global" }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The answer is `201` with a `SipTrunkMutation`.
Give your carrier the `uri` of the entry in the returned `setup.addresses` whose `region` matches the connection: the setup's addresses are the SIP addresses your carrier points at.
A `null` `uri` does not exist yet; read the setup again or follow the stream until it has a value.
Use `carrier_ips` and `enforce_carrier_ips` to restrict which carrier IP addresses or CIDR ranges can send calls.

### 5. Create an outbound trunk

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X POST "$RASEN_API_BASE/telephony/sip-trunk/outbound-trunks" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"kind":"carrier","label":"Support carrier","region":"global","endpoint":"'"$SIP_ENDPOINT"'"}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.post(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/outbound-trunks',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4())},
    json={"kind": "carrier", "label": "Support carrier", "region": "global", "endpoint": os.environ["SIP_ENDPOINT"]},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, SIP_ENDPOINT } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/outbound-trunks`, {
  method: "POST",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
  body: JSON.stringify({ kind: "carrier", label: "Support carrier", region: "global", endpoint: SIP_ENDPOINT }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The answer is `202`. Follow the operation until the trunk is `active`.
The default port is `5060` and the default transport is `udp`; set these to the values your carrier requires.
Use `kind: pbx` for a PBX trunk.
If your carrier requires credentials, supply `username` and `password` from your secret manager in the write body.
Neither credential is returned by reads.

### 6. Import an existing SIP number

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X POST "$RASEN_API_BASE/telephony/sip-trunk/phone-numbers/import" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"e164":"'"$PHONE_NUMBER"'","inbound_connection_id":"'"$CONNECTION_ID"'","outbound_trunk_id":"'"$TRUNK_ID"'"}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.post(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/phone-numbers/import',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4())},
    json={"e164": os.environ["PHONE_NUMBER"], "inbound_connection_id": os.environ["CONNECTION_ID"], "outbound_trunk_id": os.environ["TRUNK_ID"]},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, PHONE_NUMBER, CONNECTION_ID, TRUNK_ID } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/phone-numbers/import`, {
  method: "POST",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "Content-Type": "application/json" },
  body: JSON.stringify({ e164: PHONE_NUMBER, inbound_connection_id: CONNECTION_ID, outbound_trunk_id: TRUNK_ID }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The answer is `201`. Import does not buy a number.
Continue with [Route phone calls](/guides/phone-numbers) to assign a published agent.

### 7. Edit an inbound connection

Use these maintenance steps when you need to change an existing setup.
Read the current setup and refresh `ETAG` before each mutation that requires `If-Match`.
This example restricts inbound calls to an illustrative carrier IP; replace it with your carrier's documented addresses.

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X PATCH "$RASEN_API_BASE/telephony/sip-trunk/inbound-connections/$CONNECTION_ID" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $ETAG" \
  -H "Content-Type: application/json" -d '{"carrier_ips":["192.0.2.10/32"],"enforce_carrier_ips":true}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.patch(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/inbound-connections/{os.environ["CONNECTION_ID"]}',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["ETAG"]},
    json={"carrier_ips": ["192.0.2.10/32"], "enforce_carrier_ips": True},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, CONNECTION_ID, ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/inbound-connections/${CONNECTION_ID}`, {
  method: "PATCH",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": ETAG, "Content-Type": "application/json" },
  body: JSON.stringify({ carrier_ips: ["192.0.2.10/32"], enforce_carrier_ips: true }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

### 8. Edit an outbound trunk

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X PATCH "$RASEN_API_BASE/telephony/sip-trunk/outbound-trunks/$TRUNK_ID" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $ETAG" \
  -H "Content-Type: application/json" -d '{"label":"Support carrier updated"}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.patch(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/outbound-trunks/{os.environ["TRUNK_ID"]}',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["ETAG"]},
    json={"label": "Support carrier updated"},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, TRUNK_ID, ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/outbound-trunks/${TRUNK_ID}`, {
  method: "PATCH",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": ETAG, "Content-Type": "application/json" },
  body: JSON.stringify({ label: "Support carrier updated" }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The answer is `202`; follow any returned `operation_id` on the setup stream.

### 9. Regenerate the workspace SIP address

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X POST "$RASEN_API_BASE/telephony/sip-trunk/address/regenerate" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $ETAG"
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.post(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/address/regenerate',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["ETAG"]},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/address/regenerate`, {
  method: "POST",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": ETAG },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The answer is `202`. Follow the setup stream and use the resulting address for your carrier configuration.

### 10. Delete an unused inbound connection

Remove dependencies first if the API refuses deletion with `in_use` or `number_bound`.

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X DELETE "$RASEN_API_BASE/telephony/sip-trunk/inbound-connections/$CONNECTION_ID" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $ETAG"
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.delete(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/inbound-connections/{os.environ["CONNECTION_ID"]}',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["ETAG"]},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, CONNECTION_ID, ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/inbound-connections/${CONNECTION_ID}`, {
  method: "DELETE",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": ETAG },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

### 11. Delete an unused outbound trunk

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X DELETE "$RASEN_API_BASE/telephony/sip-trunk/outbound-trunks/$TRUNK_ID" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $ETAG"
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.delete(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk/outbound-trunks/{os.environ["TRUNK_ID"]}',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["ETAG"]},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, TRUNK_ID, ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk/outbound-trunks/${TRUNK_ID}`, {
  method: "DELETE",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": ETAG },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The answer is `202`; follow its operation before treating the trunk as deleted.

### 12. Disconnect the setup

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X DELETE "$RASEN_API_BASE/telephony/sip-trunk" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $ETAG"
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.delete(
    f'{os.environ["RASEN_API_BASE"]}/telephony/sip-trunk',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["ETAG"]},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/sip-trunk`, {
  method: "DELETE",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": ETAG },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log(await response.json());
```

The answer is `202`; inspect the operation's result on the stream.

## Rules

* MUST send the same body and `Idempotency-Key` when retrying a lost response.
* MUST read the current setup and send its ETag on operations that require `If-Match`.
* MUST inspect the operation state after a `202` response.
* MUST NOT put carrier credentials in logs or client-side applications.
* MUST NOT treat an unfamiliar stream state as success.
* MUST keep carrier number ownership and routing configuration consistent with your imported numbers.
* MUST wait for `state: ready` before you provision a number on the SIP trunk.
* MUST keep an unknown `failure_reason` or `failed_step` value, and treat it as a failure.

## Verify

```bash
curl --fail-with-body -sS -i "$RASEN_API_BASE/telephony/sip-trunk" \
  -H "Authorization: Bearer $RASEN_API_KEY"
```

After connection succeeds, expect `state: ready` and the addresses for available regions.
If the setup reports `state: failed`, `failed_step` names the step that failed and `failure_reason` says why.
A setup with `state: ready`, `address_regenerating: true` and a `failed_step` that starts with `address_` has a stopped address regeneration, and the old address still routes. Retry it with `regenerateSipAddress`: `connectSipTrunk` answers `409 conflict` while the setup is ready.
After a maintenance operation, confirm its result in the setup and its terminal state in the stream.

## Errors

| Code                                                                                                                                      | Cause                                                                                              | Fix                                                                                                                                    |
| ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `sip_trunk_not_enabled`                                                                                                                   | SIP trunking is not enabled for the workspace.                                                     | Check `getSipTrunkSetup` and the workspace's SIP availability.                                                                         |
| `carrier_not_activated`                                                                                                                   | The carrier named in `details.carrier` is not available to the workspace yet.                      | Do not resend the unchanged request; contact support to activate the carrier.                                                          |
| `ingress_unconfigured`                                                                                                                    | The ingress is not configured.                                                                     | Contact support; resending an unchanged request does not fix configuration.                                                            |
| `conflict` (`stale_revision`)                                                                                                             | The setup changed after your read.                                                                 | Read it again and reconcile before a new edit.                                                                                         |
| `conflict` (`sip_trunk_connected`)                                                                                                        | A setup is already connected.                                                                      | Read the existing setup before choosing another action.                                                                                |
| `conflict` (`sip_job_running`)                                                                                                            | A SIP operation is running.                                                                        | Follow the operation on the stream before a new action.                                                                                |
| `conflict` (`in_use`)                                                                                                                     | The resource is in use.                                                                            | Reconcile its dependencies before deletion.                                                                                            |
| `conflict` (`number_bound`)                                                                                                               | A number is bound to the resource.                                                                 | Reconcile the number binding before deletion.                                                                                          |
| `conflict` (`trunk_exists`)                                                                                                               | The requested trunk already exists.                                                                | Read the existing trunks and use or edit the matching trunk.                                                                           |
| `revision_required`                                                                                                                       | An edit omitted `If-Match`.                                                                        | Read the setup and send its ETag.                                                                                                      |
| `telephony_not_connected`                                                                                                                 | Telephony is not connected.                                                                        | Read the setup and connect it before repeating the intended action.                                                                    |
| `invalid_request`                                                                                                                         | A field or body is invalid.                                                                        | Check the API reference and fix the indicated field.                                                                                   |
| `provider_unavailable` (`details.reason`: `sip_trunk_not_ready`)                                                                          | `provisionPhoneNumber` ran for a SIP number before the setup was ready. No carrier was contacted.  | Wait for `state: ready` (or retry a failed setup with `connectSipTrunk`), then send the request again with a new `Idempotency-Key`.    |
| Setup `failure_reason` `provider_refused`, `provider_conflict`, `provider_unavailable`, `provider_auth_failed` or `provider_rate_limited` | The SIP provider refused, could not be reached, refused the platform's access or limited requests. | Retry with `connectSipTrunk`, or with `regenerateSipAddress` when `failed_step` starts with `address_`. Contact support if it repeats. |
| Setup `failure_reason` `internal_error`                                                                                                   | A platform fault stopped the setup.                                                                | Retry with `connectSipTrunk`. Contact support if it repeats.                                                                           |

## Related

* [Telephony connections](/guides/telephony)
* [Route phone calls](/guides/phone-numbers)
* [Configure call transfers](/guides/call-transfers)
* [Idempotency and replay](/concepts/idempotency)