Overview
ThecreateNavaiBackendClient function creates an HTTP client for communicating with the Navai backend API. It handles authentication, function listing, and function execution.
Import
Type Signature
Parameters
Optional client configuration
Backend API base URLDefault:
http://localhost:3000Can also be set via env.NAVAI_API_URLEnvironment variables
Custom fetch implementation (defaults to global
fetch)Path for client secret endpointDefault:
/navai/realtime/client-secretPath for functions list endpointDefault:
/navai/functionsPath for function execution endpointDefault:
/navai/functions/executeReturn Value
Backend client instance with three methods
Create ephemeral client secret for OpenAI Realtime APIInput:Output:
List available backend functionsOutput:
Execute a backend functionInput:Output:Throws: Error if function fails or returns
ok: falseExamples
Basic Usage
With Custom Base URL
With Environment Variables
With Custom Fetch
With Custom Paths
With Model Override
Handling Function List Errors
Executing Backend Functions
Complete Integration Example
API Endpoints
POST /navai/realtime/client-secret
Create ephemeral client secret. Request:GET /navai/functions
List available backend functions. Response:POST /navai/functions/execute
Execute a backend function. Request:Error Handling
Client Secret Errors
Function List Errors
Function Execution Errors
Types
Related
- useWebVoiceAgent - Uses this client
- buildNavaiAgent - Consumes backend functions
- Backend Package - Server-side implementation
- Types - Type definitions