This is a sample application that demonstrates how to use the Bandwidth's Programmable Voice API with OpenAI's Realtime Websocket Interface to create a real-time AI-powered voice assistant.
In order to use the Bandwidth API users need to set up the appropriate application at the Bandwidth App and create API tokens.
To create an application log into the Bandwidth App and navigate to the Applications tab. Fill out the New Application form selecting Voice. All Bandwidth services require publicly accessible Callback URLs, for more information on how to set one up see Callback URLs.
For more information about API credentials see our Account Credentials page.
The sample app uses the below environmental variables.
BW_ACCOUNT_ID # Your Bandwidth Account ID
BW_USERNAME # Your Bandwidth API Username
BW_PASSWORD # Your Bandwidth API Password
OPENAI_API_KEY # Your OpenAI API Key
TRANSFER_TO # The phone number to transfer the call to (in E.164 format, e.g. +19195551212)
BASE_URL # The base URL for your application (e.g. https://myapp.ngrok.io)
LOG_LEVEL # (optional) The logging level for the application (default: INFO)
LOCAL_PORT # (optional) The local port for the application (default: 5000)This application is built using Python 3.13. You can use pip to install the required packages, or Docker Compose to run the application.
To install the required packages and run the application, you can use either of the following methods:
# Using Docker Compose
docker compose up --build# Using Python
python -m venv .venv
source .venv/bin/activate
cd app
pip install -r requirements.txt
python main.pyFor a detailed introduction, check out our Bandwidth Voice Webhooks page.
Below are the callback paths exposed by this application:
/health/webhooks/bandwidth/voice/initiate/webhooks/bandwidth/voice/status
A simple way to set up a local callback URL for testing is to use the free tool ngrok.
After you have downloaded and installed ngrok run the following command to open a public tunnel to your port ($LOCAL_PORT)
ngrok http $LOCAL_PORTYou can view your public URL at http://127.0.0.1:4040 after ngrok is running. You can also view the status of the tunnel and requests/responses here.