Endpoint
client_secret token by calling OpenAI’s Realtime API. This token is used by frontend/mobile clients to establish secure WebSocket connections to OpenAI’s Realtime service.
Authentication
This endpoint requires an OpenAI API key, which can be provided in two ways:- Server-side API key (recommended): Configure
OPENAI_API_KEYenvironment variable - Client-side API key: Pass
apiKeyin request body (only ifallowApiKeyFromRequestis enabled)
Request Headers
Must be
application/jsonRequest Body
All fields are optional. If not provided, defaults from environment variables or backend configuration will be used.OpenAI Realtime model name. Default:
gpt-realtimeVoice identifier for audio output. Default:
marinBase instructions for the AI assistant. Default:
You are a helpful assistant.Language for AI responses. When set, adds “Always reply in .” to instructions.
Voice accent specification. When set, adds “Use a accent while speaking.” to instructions.
Voice tone specification. When set, adds “Use a tone while speaking.” to instructions.
OpenAI API key from client. Only used if server-side key is not configured and
allowApiKeyFromRequest is enabled.Response
The ephemeral client secret token (starts with
ek_)Unix timestamp (seconds) when the token expires
Example Request
Example Response
Error Responses
500 - Missing API Key
500 - API Key from Request Disabled
apiKey in request but allowApiKeyFromRequest is false.
500 - Invalid TTL
clientSecretTtlSeconds configuration is outside the valid range (10-7200 seconds).
500 - OpenAI API Error
Configuration
The endpoint behavior is controlled byNavaiVoiceBackendOptions passed to registerNavaiExpressRoutes:
openaiApiKey: Server-side OpenAI API keydefaultModel: Default model (default:gpt-realtime)defaultVoice: Default voice (default:marin)defaultInstructions: Default instructionsdefaultLanguage: Default languagedefaultVoiceAccent: Default voice accentdefaultVoiceTone: Default voice toneclientSecretTtlSeconds: Token lifetime in seconds (10-7200, default: 600)allowApiKeyFromRequest: Whether to accept API keys from requests (default: auto)
Environment Variables
OPENAI_API_KEY: Server-side API keyOPENAI_REALTIME_MODEL: Default modelOPENAI_REALTIME_VOICE: Default voiceOPENAI_REALTIME_INSTRUCTIONS: Default instructionsOPENAI_REALTIME_LANGUAGE: Default languageOPENAI_REALTIME_VOICE_ACCENT: Default voice accentOPENAI_REALTIME_VOICE_TONE: Default voice toneOPENAI_REALTIME_CLIENT_SECRET_TTL: Token TTL in seconds (default: 600)NAVAI_ALLOW_FRONTEND_API_KEY: Whether to allow client API keys (true/false)
Security Notes
- Server-side API key always takes priority over client-provided keys
- If
OPENAI_API_KEYis set, client keys are denied unlessNAVAI_ALLOW_FRONTEND_API_KEY=true - If
OPENAI_API_KEYis not set, client keys are allowed by default as a fallback - In production, always use server-side API keys and set
NAVAI_ALLOW_FRONTEND_API_KEY=false
Implementation
Implemented inpackages/voice-backend/src/index.ts:207-219 via createExpressClientSecretHandler.