@navai/voice-backend package provides the server-side infrastructure for NAVAI voice applications. It handles two critical responsibilities:
- Minting secure ephemeral client secrets for OpenAI Realtime API
- Discovering, validating, and executing backend functions from your codebase
What it provides
Client secret generation
The package securely mints ephemeralclient_secret tokens by proxying requests to OpenAI’s Realtime API. This keeps your OpenAI API key secure on the server while allowing frontend clients to establish WebRTC connections.
Backend function system
The dynamic function loading system automatically discovers callable functions in your codebase and exposes them as tools that the AI agent can invoke. Functions are loaded from configurable directories and validated at runtime.Express routes
Out-of-the-box Express middleware registers these HTTP endpoints:POST /navai/realtime/client-secret- Generate client secretsGET /navai/functions- List available backend functionsPOST /navai/functions/execute- Execute a backend function
Architecture
The package has three internal layers:Entry layer (index.ts)
Exposes the public API, client secret helpers, and Express route registration
Discovery layer (runtime.ts)
Resolves
NAVAI_FUNCTIONS_FOLDERS, scans files, applies path matching rules, and builds module loadersRequest flow
Here’s how a typical request flows through the system:- Frontend/mobile calls
POST /navai/realtime/client-secret - Backend validates options and API key policy
- Backend calls OpenAI
POST https://api.openai.com/v1/realtime/client_secrets - Frontend/mobile calls
GET /navai/functionsto discover allowed tools - Agent calls
POST /navai/functions/executewithfunction_nameandpayload - Backend executes only tool names loaded in the registry
Installation
express is a peer dependency and must be installed separately.Quick example
Here’s a minimal Express server with NAVAI backend routes:src/ai/functions-modules.
Next steps
Express setup
Complete Express integration guide with CORS and environment variables
Client secrets
Learn how client secret generation works and configure TTL
Functions
Create backend functions that the AI agent can invoke
Other frameworks
Use NAVAI with Laravel, Django, Rails, or custom backends
