Overview
DispatchAI uses environment variables for all configuration. Variables are loaded from a.env file via python-dotenv at application startup.
Configuration File
Create a.env file in the project root:
Required Variables
Server Configuration
Port for the uvicorn server. Must match the port configured in ngrok tunnels.
Application environment. Valid values:
dev, prodControls storage backend selection:dev: Uses in-memory storage (data lost on restart)prod: Currently uses in-memory storage (Postgres support planned)
Telephony (Telnyx)
Telnyx REST API key for call control operations.Obtain from: https://portal.telnyx.comUsed for:
- Answering incoming calls
- Starting audio streams
- TTS greeting playback
app/main.py:27Optional webhook signature verification secret.Currently not enforced but recommended for production deployments.
Public URLs (ngrok)
ngrok authentication token for persistent tunnels.Obtain from: https://dashboard.ngrok.comRequired for
dev_start.sh to automatically start tunnels.Public WebSocket URL for Telnyx to stream audio frames.Format:
wss://your-domain.ngrok.io/wsReferenced in: app/main.py:28, app/main.py:206Public HTTP URL for webhook endpoints.Format:
https://your-domain.ngrok.ioSpeech-to-Text (Deepgram)
Deepgram API key for speech transcription and sentiment analysis.Obtain from: https://console.deepgram.comUsed for:
- Batch transcription of call recordings (Nova-2 model)
- Real-time sentiment analysis via Text Intelligence API
app/main.py:29, app/agents/emotion.py:11AI Models (OpenAI)
OpenAI API key for GPT-powered features.Obtain from: https://platform.openai.com/api-keysUsed for:
- Call summary generation (gpt-4o-mini)
- Emotion classification (optional, falls back to heuristic)
app/agents/summary.py:6, app/agents/emotion.py:9OpenAI model to use for emotion analysis when
EMOTION_PROVIDER=openai.AI Provider Selection
Emotion analysis provider. Valid values:
heuristic: Rule-based classifier using distress score + keyword matching (no API cost)deepgram: Deepgram Text Intelligence sentiment APIopenai: GPT-based emotion classification
app/agents/emotion.py:8Database (Planned)
PostgreSQL connection string.Format:
postgresql://user:pass@host:5432/dbnameCurrently unused. The system uses in-memory storage via InMemoryCallStore.Referenced in: app/main.py:83Storage (Planned)
S3 bucket name for call recording storage.Currently unused. Call recordings are stored locally in
data/recordings/.Referenced in: app/main.py:84Example Configuration
Development
Production
Environment Variable Loading
Variables are loaded at application startup inapp/main.py:
Configuration Validation
The application performs minimal validation at startup. Missing critical variables will cause runtime errors:- If
TELNYX_API_KEYis missing: Call control operations will fail - If
WS_PUBLIC_URLis missing: Audio streaming will not start - If
DEEPGRAM_API_KEYis missing: Transcription will be skipped - If
OPENAI_API_KEYis missing: Falls back to heuristic summaries
Runtime Configuration Changes
To apply configuration changes:Troubleshooting
Variables not loading
Symptom: Configuration values areNone or default values are used
Solution:
- Verify
.envfile exists in project root - Check file format (no spaces around
=, one variable per line) - Ensure no quotes around values unless part of the actual value
- Restart the application
ngrok tunnel URL changes
Symptom: Webhooks stop working after restart Solution:- Check ngrok console output for new public URL
- Update
WS_PUBLIC_URLin.env - Update webhook URL in Telnyx portal dashboard
- Restart application
API key authentication failures
Symptom: 401 Unauthorized errors from external APIs Solution:- Verify API key is valid and not expired
- Check for extra whitespace in
.envvalues - Confirm API key has required permissions
- Test API key directly with curl before debugging application