> 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.

# Configure call transfers

> Configure named transfer destinations on an agent draft, confirm carrier setup when needed, publish the policy, and inspect transfer results.

## Summary

This guide configures named destinations for the built-in transfer tool and confirms any carrier setup needed to use them.
It also publishes the policy and reads transfer outcomes.
It does not configure SIP trunks; see [Connect a SIP trunk](/guides/sip-trunk).

## Facts

| Item             | Value                                                                                                                                                       |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Operations       | `getTelephonyConnection`, `setTelephonyConnectionTransferFlow`, `getAgentDraft`, `updateAgentDraft`, `publishAgent`, `getCall`                              |
| Connection paths | `GET /telephony/connections/{connection_id}`, `PUT /telephony/connections/{connection_id}/transfer-flow`                                                    |
| Agent paths      | `GET`, `PATCH /agents/{agent_id}/draft`; `POST /agents/{agent_id}/publish`                                                                                  |
| Result path      | `GET /calls/{call_id}`                                                                                                                                      |
| Capabilities     | `numbers.assign` for connections, `config.read` for draft reads, `agents.write` for draft edits, `agents.publish` for publication, `calls.read` for results |
| Headers          | `Authorization` on every request; `Idempotency-Key` and `If-Match` on the mutations shown here                                                              |
| Destination list | 1 to 10 destinations when enabled; writing `destinations` replaces the whole list                                                                           |
| Targets          | `e164`; `trunk_extension` on SIP trunk numbers; `sip_uri` on SIP trunk numbers in `global`                                                                  |
| Ring timeout     | `ring_timeout_s`: 10 to 60 seconds, default 30                                                                                                              |
| Environment      | `RASEN_API_BASE` (ending in `/v1`), `RASEN_API_KEY`, `CONNECTION_ID`, `AGENT_ID`, `CALL_ID`, `CONNECTION_ETAG`, `DRAFT_ETAG`                                |
| Python           | 3.10 or later, with `httpx`                                                                                                                                 |
| TypeScript       | Node.js 22 or later, with built-in `fetch`                                                                                                                  |

## Steps

Set `CONNECTION_ID` to a connection's `id` from `listTelephonyConnections`.
Set `AGENT_ID` to an agent's `id` from `listAgents` or `createAgent`.
Set `CALL_ID` to a call's `id` from `listCalls` after the published agent handles a call.

### 1. Read the connection's transfer requirements

**`curl`**

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

**`Python`**

```python Python
import os

import httpx

response = httpx.get(
    f'{os.environ["RASEN_API_BASE"]}/telephony/connections/{os.environ["CONNECTION_ID"]}',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}'},
)
response.raise_for_status()
connection = response.json()
print(connection["revision"])
print(connection["transfer"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, CONNECTION_ID } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/connections/${CONNECTION_ID}`, {
  headers: { Authorization: `Bearer ${RASEN_API_KEY}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const connection = await response.json();
console.log(connection.revision);
console.log(connection.transfer);
```

Read `transfer.open`, `mechanism`, `setup_required`, `setup_confirmed` and `setup_action`.
If `setup_required` is true, complete the step described by `setup_action` in your carrier's dashboard.
For Exotel, this means the flow applets after the Voicebot applet.
Set `CONNECTION_ETAG` to the connection's returned `revision`; the connection response has no `ETag` header.

### 2. Confirm the carrier's transfer flow when required

Skip this request when `setup_required` is false: a carrier needing no setup step returns `invalid_request`.

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X PUT "$RASEN_API_BASE/telephony/connections/$CONNECTION_ID/transfer-flow" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $CONNECTION_ETAG" \
  -H "Content-Type: application/json" -d '{"confirmed":true}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.put(
    f'{os.environ["RASEN_API_BASE"]}/telephony/connections/{os.environ["CONNECTION_ID"]}/transfer-flow',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["CONNECTION_ETAG"]},
    json={"confirmed": True},
)
response.raise_for_status()
print(response.json()["transfer"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, CONNECTION_ID, CONNECTION_ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/telephony/connections/${CONNECTION_ID}/transfer-flow`, {
  method: "PUT",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": CONNECTION_ETAG, "Content-Type": "application/json" },
  body: JSON.stringify({ confirmed: true }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log((await response.json()).transfer);
```

This records confirmation without calling the carrier.
Send `confirmed: false` to withdraw it after reading the connection again.
Calls on this connection's numbers offer transfer only after required setup is confirmed.

### 3. Read the agent draft

**`curl`**

```bash curl
curl --fail-with-body -sS -i "$RASEN_API_BASE/agents/$AGENT_ID/draft" \
  -H "Authorization: Bearer $RASEN_API_KEY"
```

**`Python`**

```python Python
import os

import httpx

response = httpx.get(
    f'{os.environ["RASEN_API_BASE"]}/agents/{os.environ["AGENT_ID"]}/draft',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}'},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json()["default_tools"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, AGENT_ID } = process.env;
const response = await fetch(`${RASEN_API_BASE}/agents/${AGENT_ID}/draft`, {
  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()).default_tools);
```

Set `DRAFT_ETAG` to this draft's `ETag` header before editing.
It is a different token from `CONNECTION_ETAG`; do not send one resource's token to the other.

### 4. Enable a named destination

Replace the illustrative phone number with a number you control.
This sample replaces the entire destination list with one E.164 destination.

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X PATCH "$RASEN_API_BASE/agents/$AGENT_ID/draft" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $DRAFT_ETAG" \
  -H "Content-Type: application/json" \
  -d '{"default_tools":{"transfer":{"enabled":true,"destinations":[{"label":"Support team","when_to_use":"The caller asks to speak to support.","target":{"kind":"e164","e164":"+12025550123"},"ring_timeout_s":30}]}}}'
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.patch(
    f'{os.environ["RASEN_API_BASE"]}/agents/{os.environ["AGENT_ID"]}/draft',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["DRAFT_ETAG"]},
    json={"default_tools": {"transfer": {"enabled": True, "destinations": [{
        "label": "Support team", "when_to_use": "The caller asks to speak to support.",
        "target": {"kind": "e164", "e164": "+12025550123"}, "ring_timeout_s": 30,
    }]}}},
)
response.raise_for_status()
print(response.headers["ETag"])
print(response.json()["default_tools"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, AGENT_ID, DRAFT_ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/agents/${AGENT_ID}/draft`, {
  method: "PATCH",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": DRAFT_ETAG, "Content-Type": "application/json" },
  body: JSON.stringify({ default_tools: { transfer: { enabled: true, destinations: [{
    label: "Support team", when_to_use: "The caller asks to speak to support.",
    target: { kind: "e164", e164: "+12025550123" }, ring_timeout_s: 30,
  }] } } }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(response.headers.get("ETag"));
console.log((await response.json()).default_tools);
```

Keep the server-generated destination `id` when editing that destination; omit `id` to add a new one.
The model sees `id`, `label` and `when_to_use`, but never the target.
The optional `handoff_message` is spoken before transfer; `null` uses the default text.
Set `DRAFT_ETAG` to the updated draft's `ETag` header before publication.

### 5. Publish the policy

Ensure the rest of the draft is ready before publishing; publication freezes the complete draft configuration.

**`curl`**

```bash curl
curl --fail-with-body -sS -i -X POST "$RASEN_API_BASE/agents/$AGENT_ID/publish" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "If-Match: $DRAFT_ETAG"
```

**`Python`**

```python Python
import os
import uuid

import httpx

response = httpx.post(
    f'{os.environ["RASEN_API_BASE"]}/agents/{os.environ["AGENT_ID"]}/publish',
    headers={"Authorization": f'Bearer {os.environ["RASEN_API_KEY"]}', "Idempotency-Key": str(uuid.uuid4()), "If-Match": os.environ["DRAFT_ETAG"]},
)
response.raise_for_status()
print(response.json())
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, AGENT_ID, DRAFT_ETAG } = process.env;
const response = await fetch(`${RASEN_API_BASE}/agents/${AGENT_ID}/publish`, {
  method: "POST",
  headers: { Authorization: `Bearer ${RASEN_API_KEY}`, "Idempotency-Key": crypto.randomUUID(), "If-Match": DRAFT_ETAG },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

New calls use the published policy; running calls keep their original version.
At call time, the carrier and region determine which destinations the transfer tool can offer.
A destination that the call cannot use is omitted from the tool.

## Rules

* MUST supply at least one destination when transfer is enabled.
* MUST preserve each existing destination's `id` when editing it.
* MUST include every destination you want to keep when replacing `destinations`.
* MUST NOT write `destinations` and `destination_number` in the same body.
* MUST NOT confirm carrier setup before completing the carrier's step.
* MUST publish after changing the draft policy to use it on new calls.

`destination_number` remains supported for a single E.164 destination.
Writing it alone replaces the list with that destination.
On reads, it is an alias of the first E.164 destination, or `null` when there is none.
Disabling transfer can retain the destinations for later use.

A `trunk_extension` target contains `trunk_id` and a 1 to 8 digit `extension`.
A `sip_uri` target contains `uri`, for example `sip:support@pbx.example.com`.
These targets require eligible SIP trunk numbers; a SIP URI also requires the `global` region.

## Verify

```bash
curl --fail-with-body -sS "$RASEN_API_BASE/calls/$CALL_ID" \
  -H "Authorization: Bearer $RASEN_API_KEY"
```

`end_reason` says why a call ended.
A call that the agent ended, with its `end_call` tool or its goodbye, reports `agent_hangup`.
An answered call whose line failed reports `line_dropped`, and a call that reached a voicemail reports `voicemail_detected`.
`completed` means that the call ended and nothing says who ended it.
Keep an `end_reason` value you do not know.
Inspect `transfer_destination_label` after a call ends in a transfer: it has a value only when the call ended `transferred` or `transfer_failed`.
It identifies the last destination by label, without exposing its number or address.
`transfer_duration_ms` is the carrier-reported time connected to the destination.
It is `null` when no transfer connected or when the time has not been reported.
These fields also appear in call list and search results and in webhook payloads containing a `Call`.

## Errors

| Code                             | Cause                                                                                                             | Fix                                                                           |
| -------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `invalid_request`                | Both destination shapes were written, the policy is invalid, or this carrier needs no transfer-flow confirmation. | Send one valid destination shape; confirm only when `setup_required` is true. |
| `conflict` (`stale_revision`)    | The connection changed after your read.                                                                           | Read the connection again and reconcile before confirming.                    |
| `draft_conflict`                 | The agent publication token is stale.                                                                             | Read the draft again and reconcile before editing or publishing.              |
| `revision_required`              | A mutation omitted `If-Match`.                                                                                    | Read the resource and send its ETag.                                          |
| `telephony_not_connected`        | The carrier connection is unavailable.                                                                            | Read and restore the connection before confirming setup.                      |
| `invalid_request` on publication | The draft cannot be published as supplied.                                                                        | Validate the draft and resolve the reported reasons.                          |

## Related

* [Build and publish an agent](/guides/agents)
* [Connect a SIP trunk](/guides/sip-trunk)
* [Route phone calls](/guides/phone-numbers)
* [Webhook events](/reference/webhook-events)