***

title: Forward Calls to Synthflow
slug: forward-calls-to-synthflow
description: >-
How to initiate a call in your system and forward it to a Synthflow AI agent
using SIP transfer and custom logic.
------------------------------------

You can start a call from your own telephony system (e.g., Asterisk) and seamlessly transfer it to a Synthflow AI agent after the customer answers. This is useful if you want to handle your own voicemail detection or apply custom logic before handing off to the AI.

You can also pass custom variables into the conversation.

## Call flow

```mermaid
flowchart LR
    A[Your System - Start Call] --> B[Customer - Connected]
    A --> C[Prepare Call via API POST /v2/prepare_inbound]
    B --> D[Transfer Call via SIP Add Header X-EI]
    D --> E[Synthflow AI Agent - Continues Call]
```

***

## Prerequisites

* You must have an **inbound Synthflow agent** already set up and active.
* You need a **valid Synthflow API token**.

***

## Step 1: Prepare the inbound call in Synthflow

Before transferring the call, you must prepare it in Synthflow by making a POST request to:

```
POST /v2/prepare_inbound
```

### Headers

```json
{
  "Content-Type": "application/json",
  "Authorization": "Bearer {YOUR_API_TOKEN}"
}
```

### Body

```json
{
  "from_number": "+1234567890",
  "to_number": "+1987654321",
  "model_id": "your-model-id",
  "workspace_id": "your-workspace-id",
  "custom_variables": {
    "customer_name": "John Doe",
    "account_id": "A12345"
  }
}
```

### Response

This request returns a JSON response containing the `synthflow_call_id` that you'll use in the next step.

```json
{
  "call_status": "registered",
  "synthflow_call_id": "ebe4bd96-dcb1-4abd-9aa5-686877dab061",
  "direction": "inbound",
  "model_id": "b336ab4e-8f1e-4b6c-aca1-d8f95b5b3ef6",
  "workspace_id": "1738660423280x428309622607052800",
  "custom_variables": {
    "customer_name": "John Doe",
    "account_id": "A12345"
  }
}
```

> **Note:** Extract the `synthflow_call_id` from this response to use in the SIP transfer header.

***

## Step 2: Transfer the live call to Synthflow

Once your call is connected to the customer (and your custom logic has completed), you can transfer the call to Synthflow via SIP.

### Generic SIP example

When initiating the SIP INVITE, include the `X-EI` header with the Synthflow Call ID and transfer to the Synthflow SIP endpoint:

```
INVITE sip:<NUMBER>@sip.synthflow.ai:32681 SIP/2.0
X-EI: S.<SYNTHFLOW_CALL_ID>;
...
```

* Replace `<SYNTHFLOW_CALL_ID>` with the `synthflow_call_id` you received from the `/v2/prepare_inbound` API call.
* Replace `<NUMBER>` with the number associated with your inbound Synthflow AI Agent (must be in +E.164 format, e.g., `+1234567890`).
* The `X-EI` header format must be exactly `S.<SYNTHFLOW_CALL_ID>;` (note the semicolon at the end).
* The SIP destination must be `sip.synthflow.ai:32681` (port 32681).

### Asterisk example

For Asterisk systems, you can implement the transfer like this:

```asterisk
same => n,Set(PJSIP_HEADER(add,X-EI)=S.<SYNTHFLOW_CALL_ID>;)
same => n,Transfer(SIP/<NUMBER>@sip.synthflow.ai:32681)
```

This will initiate a SIP INVITE to Synthflow, carrying the context of the original call.

***

## Notes

* The header `X-EI` must include the Synthflow Call ID and the format `S.<SYNTHFLOW_CALL_ID>;`
* The SIP transfer should only occur after the customer has answered the call.
* The destination number must be linked to an active Synthflow AI agent.
