Installation
Environment variables
TheregisterNavaiExpressRoutes function automatically reads configuration from environment variables using getNavaiVoiceBackendOptionsFromEnv().
OpenAI configuration
Your OpenAI API key. Keep this secret and never expose it to the frontend.
The OpenAI Realtime model to use for voice sessions.
Default voice for the AI agent. Options include
marin, alloy, echo, fable, onyx, nova, shimmer.Base instructions for the AI session. These define the agent’s behavior and personality.
Language and voice customization
Response language (e.g., “Spanish”, “French”). This is automatically injected into instructions as: “Always reply in .”
Desired voice accent (e.g., “neutral Latin American Spanish”). Injected as: “Use a accent while speaking.”
Desired voice tone (e.g., “friendly and professional”). Injected as: “Use a tone while speaking.”
Security configuration
Client secret lifetime in seconds. Must be between
10 and 7200 (2 hours).Allow clients to pass their own API key in requests. Set to
true only for development or when you want users to provide their own keys.Security note: When OPENAI_API_KEY is set on the backend, this defaults to false. When the backend key is missing, it defaults to true as a fallback.Functions configuration
Comma-separated paths to scan for backend functions. Supports:
- Folder:
src/ai/functions-modules - Recursive:
src/ai/functions-modules/... - Wildcard:
src/features/*/voice-functions - File:
src/ai/functions-modules/secret.ts
Base directory for resolving function paths. Defaults to current working directory.
CORS configuration
Comma-separated list of allowed origins for CORS. Example:
http://localhost:5173,https://app.example.comCustom configuration
You can override environment variables by passing options directly toregisterNavaiExpressRoutes:
CORS setup
For production environments, configure CORS to only allow your frontend domains:API key policy
The backend enforces a strict API key policy:- Backend key always wins: If
openaiApiKeyis configured on the server, it is always used regardless of what the client sends - Request key as fallback: If backend key is missing, the client can provide
apiKeyin the request body (only whenallowApiKeyFromRequestistrue) - Security first: When backend key exists, request keys are rejected unless explicitly allowed with
NAVAI_ALLOW_FRONTEND_API_KEY=true
resolveApiKey function (index.ts:85-103):
Registered routes
When you callregisterNavaiExpressRoutes(app), these endpoints are registered:
POST /navai/realtime/client-secret
Generates ephemeral client secrets for OpenAI Realtime API. Request body:GET /navai/functions
Lists all available backend functions discovered by the runtime. Response:POST /navai/functions/execute
Executes a backend function by name. Request body:Production recommendations
- Keep
OPENAI_API_KEYonly on the server, never expose it to frontend - Set
NAVAI_ALLOW_FRONTEND_API_KEY=falsein production - Whitelist specific CORS origins, never use
* - Monitor and surface
warningsfrom runtime and function registry - Restart backend when function files change to reload the registry
- Use HTTPS in production with valid SSL certificates
- Implement rate limiting on client secret endpoint
- Add authentication/authorization before NAVAI routes if needed
Next steps
Client secrets
Learn how the client secret generation works and how to configure TTL
