Skip to main content

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

app
Express
required
The Express application instance to register routes with.
options
RegisterNavaiExpressRoutesOptions
Configuration options for route registration.

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

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

Build docs developers (and LLMs) love