> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vobiz.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Realtime SIP Call Handler

> Connect inbound Vobiz SIP calls directly to OpenAI's Realtime API for natural, low-latency AI voice conversations across 130+ countries including India.

<img className="block w-full rounded-xl border border-gray-200" src="https://mintcdn.com/vobizai/OZ7y9Kg025aXyvCH/images/integration-bg/openairealtime.png?fit=max&auto=format&n=OZ7y9Kg025aXyvCH&q=85&s=00a68d055c196163fa5805642dcca342" width="3600" height="2160" data-path="images/integration-bg/openairealtime.png" />

This integration connects inbound SIP calls through Vobiz directly to the OpenAI Realtime API, enabling AI-powered voice conversations. When someone calls your Vobiz number, the AI answers and converses with the caller in real time over SIP.

## Architecture

```text theme={null}
Caller → Vobiz SIP trunk → OpenAI SIP endpoint → Webhook → Your service → OpenAI Realtime API
```

Flow overview:

1. Caller dials your Vobiz number (for example, `+918046733659`).
2. Vobiz routes the call to OpenAI's SIP endpoint.
3. OpenAI sends a webhook notification to your service.
4. Your service accepts the call via the OpenAI API.
5. A WebSocket connection is established for audio streaming.
6. The AI converses with the caller in real time.

## Prerequisites

* **OpenAI account** - you need your API key, project ID, and webhook secret from the [OpenAI Platform](https://platform.openai.com).
* **Vobiz account** - a SIP trunk configured and a phone number assigned.
* **Development environment** - Python 3.8+ and `ngrok` installed to handle webhooks locally.

## Step 1: Configure Vobiz

Before receiving calls, create an origination URI and point your Vobiz SIP trunk to the OpenAI SIP endpoint.

<Steps>
  <Step title="Create the origination URI">
    Navigate to [Origination URIs](https://console.vobiz.ai/app/sip/in/uri).

    Add a new URI with the destination set to `proj_xyz123@sip.api.openai.com:5061`.

    <Warning>
      It is critical to explicitly include port `5061`.
    </Warning>
  </Step>

  <Step title="Create the inbound trunk">
    Navigate to [Inbound Trunks](https://console.vobiz.ai/app/sip/in/trunks).

    Create a new trunk and attach the Origination URI you just created. Ensure the trunk is associated with your active Vobiz phone number.
  </Step>
</Steps>

## Step 2: Install the service

### Install Python dependencies

```bash theme={null}
# Create virtual environment
python -m venv venv

# Activate (Windows)
venv\Scripts\activate
# Activate (macOS/Linux)
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt
```

### Configure environment variables

Copy `.env.example` to `.env` and fill in:

```bash theme={null}
OPENAI_API_KEY=sk-...
OPENAI_PROJECT_ID=proj_...
OPENAI_WEBHOOK_SECRET=whsec_...
SKIP_SIGNATURE_VALIDATION=false
```

### Run the service

```bash theme={null}
python app.py
```

The service automatically starts an ngrok tunnel, displays the webhook endpoint for OpenAI configuration, and launches the server.

## Step 3: Production deployment

For production, deploy to a server with a static public URL such as Render, Railway, AWS EC2, or Google Cloud Run.

* Ensure HTTPS is enabled (required by OpenAI).
* Use a production WSGI server (for example, `gunicorn -w 4 -b 0.0.0.0:8000 app:app`).
* Ensure `SKIP_SIGNATURE_VALIDATION=false`.

## Step 4: Test the integration

### Test webhook endpoint

1. In the [OpenAI webhooks page](https://platform.openai.com/settings/organization/webhooks), click **Send test event**.
2. Select event type `realtime.call.incoming` and click **Send**.

Expected result: service logs should show `Received webhook` and OpenAI should report `Received HTTP 200`.

### Test a real call

1. Call your assigned Vobiz number.
2. The AI should answer within 2-3 seconds and open a conversational loop.

## Troubleshooting

### Webhook returns 401 (invalid signature)

Webhook secret mismatch.

* Verify `OPENAI_WEBHOOK_SECRET` in `.env` matches the OpenAI platform value.
* Check there are no extra spaces or quotes.
* Restart the service.
* Use `SKIP_SIGNATURE_VALIDATION=true` for debugging only.

### Call returns 500 error from OpenAI

Webhook not configured or unreachable via the ngrok tunnel.

* Verify the webhook is configured in OpenAI.
* Ensure the ngrok URL is online and reachable.
* Test the webhook with **Send test event** and inspect logs.

### "No session found for call\_id"

Expected behavior for test events - OpenAI uses fake call IDs for testing. Place a real phone call to test actual streaming functionality.

## Next steps

* Explore the [OpenAI Realtime API documentation](https://platform.openai.com/docs/guides/realtime).
* Set up call recording in your Vobiz application - see [recording](/recording/export-historical-recordings).
* Manage your trunks via the [SIP trunks docs](/trunks).
