You’ll need an OpenAI API key with access to the Realtime API. Get one at platform.openai.com.
Prerequisites
- Node.js 20 or higher
- npm or yarn package manager
- OpenAI API key
- A React application (we’ll use Vite)
Backend setup
First, set up an Express backend that generates OpenAI credentials and exposes function execution routes.Create environment variables
Create a
.env file in your backend directory:Key settings:
OPENAI_API_KEY: Your OpenAI API key (keep this secret!)OPENAI_REALTIME_CLIENT_SECRET_TTL: Credential lifetime in seconds (10-7200)NAVAI_CORS_ORIGIN: Comma-separated list of allowed originsNAVAI_FUNCTIONS_FOLDERS: Paths to your backend function modules
Create the Express server
Create The
src/server.ts:registerNavaiExpressRoutes function automatically registers:POST /navai/realtime/client-secretGET /navai/functionsPOST /navai/functions/execute
Create a backend function (optional)
Create
src/ai/functions/hello.ts:Backend functions are automatically discovered from the folders specified in
NAVAI_FUNCTIONS_FOLDERS. The function name becomes the tool name that the AI agent can call.Frontend setup
Now integrate the voice agent into your React application.Configure environment variables
Create a
.env file in your frontend directory:These variables are prefixed with
NAVAI_ (not VITE_ or REACT_APP_). The NAVAI packages handle the environment variable resolution internally.Define your routes
Create
src/ai/routes.ts:Each route needs a
name, path, and description. Add synonyms to help the AI understand different ways users might refer to the same page.Generate module loaders
Create
src/ai/generated-module-loaders.ts:If you install
@navai/voice-frontend, you can run npx navai-generate-web-loaders to automatically generate this file based on your NAVAI_FUNCTIONS_FOLDERS.Test your integration
Now you can test the voice navigation:Speak commands
Try these voice commands:
- “Take me to the profile page”
- “Go to settings”
- “Navigate to home”
- “Open profile”
The AI agent understands natural variations of commands. You can say “take me to”, “go to”, “open”, “show me”, etc.
Add a frontend function
You can also create functions that run in the browser: Createsrc/ai/functions-modules/session/logout.fn.ts:
Frontend functions receive a
context object with the navigate function, allowing them to programmatically change routes.Common issues
Next steps
Backend configuration
Learn about advanced backend options and custom function execution
Frontend hooks
Explore the full API of
useWebVoiceAgent and customization optionsFunction execution
Understand how to create and organize voice-enabled functions
Mobile integration
Add voice navigation to React Native and Expo apps
