Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Voice Call API
The Voice Call API provides Twilio voice integration with OpenAI’s Realtime API for voice-based AI interactions.
Base URL
Endpoints
Status Page
Check if the server is running.
Response
<html>
<head><title>Praison AI Call Server</title></head>
<body>
<h1>Praison AI Call Server is running!</h1>
</body>
</html>
Incoming Call Handler
Handle incoming Twilio calls and return TwiML response.
Twilio webhook for incoming calls
Response (TwiML)
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say></Say>
<Pause length="1"/>
<Connect>
<Stream url="wss://your-host/media-stream"/>
</Connect>
</Response>
WebSocket endpoint for real-time audio streaming between Twilio and OpenAI.
WebSocket for audio streaming
Connection Flow
- Twilio connects to WebSocket
- Server connects to OpenAI Realtime API
- Audio streams bidirectionally:
- Twilio → Server → OpenAI (user speech)
- OpenAI → Server → Twilio (AI response)
Twilio Events
| Event | Description |
|---|
start | Stream started |
media | Audio data chunk |
stop | Stream ended |
OpenAI Events
| Event | Description |
|---|
session.created | Session initialized |
session.updated | Session config updated |
input_audio_buffer.speech_started | User started speaking |
input_audio_buffer.speech_stopped | User stopped speaking |
response.audio.delta | AI audio response chunk |
response.done | AI response complete |
Configuration
Environment Variables
| Variable | Required | Default | Description |
|---|
OPENAI_API_KEY | Yes | - | OpenAI API key with Realtime access |
PORT | No | 8090 | Server port |
NGROK_AUTH_TOKEN | No | - | ngrok token for public URL |
PUBLIC | No | false | Enable public URL via ngrok |
Create a tools.py file in the working directory:
# tools.py
async def get_weather(location: str) -> dict:
"""Get weather for a location."""
return {"location": location, "temp": "72°F", "condition": "sunny"}
get_weather.definition = {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"]
}
}
tools = [(get_weather.definition, get_weather)]
Usage Example
Start Server
# Basic start
python -m praisonai.api.call
# With public URL
python -m praisonai.api.call --public
# Custom port
python -m praisonai.api.call --port 9000
Twilio Configuration
- Get your public URL (ngrok or deployed)
- In Twilio Console:
- Go to Phone Numbers → Your Number
- Set Voice webhook to:
https://your-url.ngrok.io/
- Method: POST
Python Usage
from praisonai.api.call import run_server
# Start the server
run_server(port=8090, use_public=True)
Session Configuration
The server sends this session configuration to OpenAI:
{
"type": "session.update",
"session": {
"turn_detection": {
"type": "server_vad",
"threshold": 0.5,
"prefix_padding_ms": 300,
"silence_duration_ms": 200
},
"input_audio_format": "g711_ulaw",
"output_audio_format": "g711_ulaw",
"voice": "alloy",
"tools": [],
"tool_choice": "auto",
"modalities": ["text", "audio"],
"temperature": 0.8
}
}
- CLI - Command-line interface
- Agent - Agent configuration