.env file in the root directory.
Setup
Copy the.env.example file to create your .env file:
Environment Variables Reference
FLASK_SECRET_KEY
Secret key used by Flask to sign session cookies and protect against CSRF attacks.
dev-secret-change-in-production
Usage in Code:
app.py:18
ELEVENLABS_API_KEY
ElevenLabs API key for text-to-speech and conversational AI phone calls.
- Text-to-speech audio generation in web chat (
/ttsendpoint) - Outbound phone calls through ElevenLabs + Twilio integration (
/api/callendpoint)
app.py:28
- Sign up at elevenlabs.io
- Navigate to your profile settings
- Generate an API key from the API section
The application will function without this key, but TTS features will be disabled and the
/api/call endpoint will return an error.OPENAI_API_KEY
OpenAI API key used to power the conversational AI agent in web chat mode.
- Web chat agent responses (
/api/chatendpoint) - Generating contextual customer/caller dialogue based on business descriptions
app.py:197-209
gpt-4o-mini
Where to Get:
- Sign up at platform.openai.com
- Navigate to API keys section
- Create a new API key
Without this key, the web chat will return a fallback message instead of generating intelligent responses.
ELEVENLABS_AGENT_ID
ElevenLabs Conversational AI agent ID used for outbound phone calls.
- Outbound phone calls (
/api/callendpoint)
app.py:239-245
- Log into your ElevenLabs account
- Navigate to Conversational AI section
- Create or select an existing agent
- Copy the agent ID from the agent settings
The agent should have prompt overrides enabled to allow the application to inject custom business descriptions and scenarios at call time.
ELEVENLABS_AGENT_PHONE_NUMBER_ID
ElevenLabs phone number ID connected to Twilio for outbound calling.
- Outbound phone calls (
/api/callendpoint)
app.py:247-255
- In ElevenLabs, navigate to Phone Numbers section
- Import or connect a Twilio-backed phone number
- Copy the phone number ID from the phone number settings
Optional Environment Variables
ELEVENLABS_API_BASE
Base URL for ElevenLabs API. Override this if using a custom endpoint or proxy.
app.py:20
Most users do not need to set this variable. The default value works for standard ElevenLabs accounts.
Validation Logic
Phone Number Format
When making outbound calls, phone numbers must be in E.164 format:app.py:24,91-92
+15551234567(US)+442071234567(UK)+81312345678(Japan)
5551234567(missing + and country code)+1 555 123 4567(contains spaces)(555) 123-4567(formatting characters)
Missing Variable Handling
Web Chat - Missing OPENAI_API_KEY
Web Chat - Missing OPENAI_API_KEY
The application will return a fallback message:Chat functionality works but responses are not intelligent.
app.py:199
Text-to-Speech - Missing ELEVENLABS_API_KEY
Text-to-Speech - Missing ELEVENLABS_API_KEY
TTS endpoint returns an error:Web chat will still return text responses but without audio.
app.py:154
Outbound Calls - Missing Required Variables
Outbound Calls - Missing Required Variables
The All three must be set for phone calls to work.
/api/call endpoint validates all three ElevenLabs variables:app.py:239-245
Complete Example .env File
Quick Reference Table
| Variable | Required | Used For | Default |
|---|---|---|---|
FLASK_SECRET_KEY | Yes | Session security | dev-secret-change-in-production |
ELEVENLABS_API_KEY | Yes | TTS & phone calls | None |
OPENAI_API_KEY | Yes | Web chat AI | None |
ELEVENLABS_AGENT_ID | For calls | Outbound calling | None |
ELEVENLABS_AGENT_PHONE_NUMBER_ID | For calls | Outbound calling | None |
ELEVENLABS_API_BASE | No | Custom endpoint | https://api.elevenlabs.io |
Next Steps
ElevenLabs Setup
Step-by-step guide to configuring ElevenLabs for phone calls
Quick Start
Get the application running in minutes