Overview
The registerNavaiExpressRoutes function registers all necessary NAVAI voice backend routes to an Express application. This includes the client secret endpoint for OpenAI Realtime API authentication and optional function execution routes.
Function Signature
function registerNavaiExpressRoutes (
app : Express ,
options ?: RegisterNavaiExpressRoutesOptions
) : void
Parameters
The Express application instance to register routes with.
options
RegisterNavaiExpressRoutesOptions
Configuration options for route registration. Show RegisterNavaiExpressRoutesOptions properties
env
Record<string, string | undefined>
Environment variables. Defaults to process.env.
Backend configuration options. If not provided, options are derived from environment variables.
Whether to include function list and execution routes. Set to false to only register the client secret endpoint.
clientSecretPath
string
default: "/navai/realtime/client-secret"
Path for the client secret endpoint.
functionsListPath
string
default: "/navai/functions"
Path for the functions list endpoint (GET).
functionsExecutePath
string
default: "/navai/functions/execute"
Path for the function execution endpoint (POST).
Base directory for scanning function modules. Defaults to process.cwd().
Comma-separated list of folder patterns to scan for function modules. Can use glob patterns.
File extensions to include when scanning for function modules.
Glob patterns to exclude when scanning for function modules.
Routes Created
This function registers the following routes:
1. Client Secret Endpoint
POST {clientSecretPath} (default: /navai/realtime/client-secret)
Creates an OpenAI Realtime API client secret for frontend authentication.
Request Body:
{
model ?: string ;
voice ?: string ;
instructions ?: string ;
language ?: string ;
voiceAccent ?: string ;
voiceTone ?: string ;
apiKey ?: string ;
}
Response:
{
value : string ;
expires_at : number ;
}
2. Functions List Endpoint
GET {functionsListPath} (default: /navai/functions)
Returns all available functions in the registry.
Response:
{
items : Array <{
name : string ;
description : string ;
source : string ;
}>;
warnings : string [];
}
3. Function Execution Endpoint
POST {functionsExecutePath} (default: /navai/functions/execute)
Executes a registered function by name.
Request Body:
{
function_name : string ;
payload ?: Record < string , unknown > ;
}
Response:
{
ok : true ;
function_name : string ;
source : string ;
result : unknown ;
}
Example Usage
Basic Setup
Custom Configuration
Without Functions
import express from 'express' ;
import { registerNavaiExpressRoutes } from '@navai/voice-backend' ;
const app = express ();
app . use ( express . json ());
registerNavaiExpressRoutes ( app );
app . listen ( 3000 , () => {
console . log ( 'NAVAI backend running on port 3000' );
});
The function automatically loads backend options from environment variables if backendOptions is not provided. See createRealtimeClientSecret for environment variable details.
Source Reference
Defined in: packages/voice-backend/src/index.ts:253