Overview
NAVAI uses environment variables to configure backend and frontend/mobile behavior. This guide covers all available variables and their usage.Backend Variables
Configure your Express backend with these variables in.env:
OpenAI Configuration
OPENAI_API_KEY
Required. Your OpenAI API key for Realtime API access.
OPENAI_REALTIME_MODEL
Optional. The OpenAI Realtime model to use.
Default: gpt-realtime
OPENAI_REALTIME_VOICE
Optional. The voice for the agent to use.
Default: marin
Options: marin, verse, alloy, echo, shimmer
OPENAI_REALTIME_INSTRUCTIONS
Optional. Custom system instructions for the agent.
Default: "You are a helpful assistant."
OPENAI_REALTIME_LANGUAGE
Optional. The language the agent should speak.
Default: Not set (English)
OPENAI_REALTIME_VOICE_ACCENT
Optional. The accent for the voice.
Default: Not set
OPENAI_REALTIME_VOICE_TONE
Optional. The tone of voice.
Default: Not set
OPENAI_REALTIME_CLIENT_SECRET_TTL
Optional. Time-to-live for client secrets in seconds.
Default: 600 (10 minutes)
Range: 10 to 7200 (2 hours)
NAVAI Backend Configuration
NAVAI_ALLOW_FRONTEND_API_KEY
Optional. Allow frontend to provide OpenAI API keys.
Default: false (if OPENAI_API_KEY is set)
Values: true, false, 1, 0
NAVAI_FUNCTIONS_FOLDERS
Optional. Paths to scan for backend function modules.
Default: src/ai/functions-modules
Format: Comma-separated paths with optional wildcards
NAVAI_FUNCTIONS_BASE_DIR
Optional. Base directory for function folder resolution.
Default: process.cwd()
Server Configuration
PORT
Optional. Port for the Express server.
Default: 3000
NAVAI_CORS_ORIGIN
Optional. Allowed CORS origins (comma-separated).
Default: Not set (no CORS)
Frontend Variables (Web)
Configure your React web app with these variables in.env:
Required
NAVAI_API_URL
Required. The URL of your NAVAI backend API.
Optional
NAVAI_ROUTES_FILE
Optional. Path to the routes configuration file.
Default: src/ai/routes.ts
NAVAI_FUNCTIONS_FOLDERS
Optional. Paths to scan for frontend function modules.
Default: src/ai/functions-modules
Format: Same as backend (comma-separated, wildcards supported)
NAVAI_REALTIME_MODEL
Optional. Override the Realtime model from backend.
Default: Uses backend setting
Frontend Variables (Mobile)
Configure your React Native/Expo app with these variables:Expo Configuration
Add toapp.config.js or app.json:
app.config.js
Environment File
Create.env:
Reading in Code
Setup Scripts
Auto-setup adds these npm scripts:Backend
No automatic scripts. Manually configure as needed.Frontend (Web)
package.json
Frontend (Mobile)
package.json
Disable Auto-Setup
Environment-Specific Configuration
Development
.env.development
Production
.env.production
Validation
NAVAI validates environment variables at runtime:Backend Validation
OPENAI_API_KEY: Required ifNAVAI_ALLOW_FRONTEND_API_KEY=falseOPENAI_REALTIME_CLIENT_SECRET_TTL: Must be 10-7200NAVAI_FUNCTIONS_FOLDERS: Warns if no files match
Frontend Validation
NAVAI_API_URL: Required (throws error if missing)NAVAI_ROUTES_FILE: Warns if file not found (falls back to default routes)NAVAI_FUNCTIONS_FOLDERS: Warns if no files match
Troubleshooting
”Missing openaiApiKey in NavaiVoiceBackendOptions”
EnsureOPENAI_API_KEY is set in backend .env and loaded with dotenv/config.
”NAVAI_API_URL is required”
Ensure frontend/mobile.env contains:
“clientSecretTtlSeconds must be between 10 and 7200”
Set a valid TTL:“Passing apiKey from request is disabled”
Either:- Set
OPENAI_API_KEYin backend.env - Or allow frontend keys:
NAVAI_ALLOW_FRONTEND_API_KEY=true
”CORS blocked for origin: …”
Add the origin toNAVAI_CORS_ORIGIN:
Best Practices
Environment-specific configs
Use
.env.development, .env.production, etc. for different environments.Next Steps
- Backend Setup - Configure your Express backend
- Web Integration - Set up a React web app
- Mobile Integration - Set up a React Native app