A realistic AI phone system using Twilio + GPT to automatically handle restaurant reservations.
- Ultra-realistic voice with OpenAI Realtime API
- Ultra-low latency (<500ms)
- Natural interruptions handled automatically
- Full reservation management (creation, availability check)
- SQLite database to store reservations
- REST API to view reservations
- Simple configuration via .env file
- Python 3.9+
- Twilio account (free for testing)
- OpenAI API key with Realtime API access
- Publicly accessible server (ngrok for dev, or a production server)
# Clone or navigate to the project folder
cd supacall
# Create a virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtCreate a .env file from the template:
cp .env.example .envEdit the .env file with your credentials:
# Twilio Configuration
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_PHONE_NUMBER=+33123456789
# OpenAI Configuration
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxx
# Server Configuration
SERVER_HOST=0.0.0.0
SERVER_PORT=8000
BASE_URL=https://your-domain.com
# Restaurant Configuration
RESTAURANT_NAME=Pizza 42
RESTAURANT_OPENING_HOURS=11:30-14:30,18:30-22:30
RESTAURANT_MAX_CAPACITY=50- Go to twilio.com
- Sign up (free for testing)
- Get a phone number
In the Twilio console:
- Go to Phone Numbers → Manage → Active numbers
- Click on your number
- In the Voice Configuration section:
- A call comes in: Webhook →
https://your-domain.com/incoming-call→ HTTP POST
- A call comes in: Webhook →
- Account SID: In the Twilio Dashboard
- Auth Token: In the Twilio Dashboard (click "Show")
- Go to platform.openai.com
- Create an API key
- Make sure you have access to the Realtime API (may require a paid account)
The Realtime API uses the gpt-4o-realtime-preview-2024-12-17 model.
To test locally:
# Terminal 1: Start the server
python main.py
# Terminal 2: Expose with ngrok
ngrok http 8000Copy the ngrok URL (e.g. https://abc123.ngrok.io) and use it as BASE_URL in Twilio.
- Install Railway CLI:
npm install -g @railway/cli- Deploy:
railway login
railway init
railway up- Configure environment variables in the Railway dashboard
- Create an account on render.com
- Create a new Web Service
- Connect your GitHub repo
- Configure:
- Build Command:
pip install -r requirements.txt - Start Command:
python main.py
- Build Command:
- Add environment variables
python main.pyThe server starts at http://0.0.0.0:8000
- Call the configured Twilio number
- The AI will answer automatically and guide the caller
- Reservations are saved to the database
Via the API:
curl http://localhost:8000/reservationsOr open in the browser: http://localhost:8000/reservations
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Home page / status |
/incoming-call |
POST | Twilio webhook (called automatically) |
/media-stream |
WebSocket | Bidirectional audio stream |
/reservations |
GET | List all reservations |
The system currently uses gpt-realtime (stable production version). You can change the model in main.py:
Available options:
# Option 1: gpt-realtime (RECOMMENDED - production version)
'wss://api.openai.com/v1/realtime?model=gpt-realtime'
# Option 2: gpt-realtime-mini (ECONOMICAL - cheaper)
'wss://api.openai.com/v1/realtime?model=gpt-realtime-mini'Comparison:
- gpt-realtime: Best quality, complex instructions, image support
- gpt-realtime-mini: More economical, good for high volume, still performant
Edit the SYSTEM_INSTRUCTIONS variable in main.py:
SYSTEM_INSTRUCTIONS = f"""Tu es l'assistant téléphonique du restaurant {RESTAURANT_NAME}.
...
"""In the .env file:
RESTAURANT_OPENING_HOURS=11:30-14:30,18:30-22:30
RESTAURANT_MAX_CAPACITY=50In main.py, add new functions to the tools list:
{
"type": "function",
"name": "cancel_reservation",
"description": "Cancels a reservation",
"parameters": {...}
}And implement in execute_function().
- Check that
BASE_URLis correct in.env - Check that the Twilio webhook points to
https://your-domain.com/incoming-call - Check server logs
- Check that your server supports WebSockets
- If using a proxy (nginx, etc.), configure correctly:
location /media-stream {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}- Check your internet connection
- The Realtime API requires a stable connection
- Try changing the voice in
session_update(options: alloy, echo, fable, onyx, nova, shimmer)
For any questions or issues:
- Check server logs
- Consult Twilio and OpenAI documentation
- Test locally with ngrok first
Built to automate restaurant reservations.