Endpoint
NAVAI_FUNCTIONS_FOLDERS can be executed. This endpoint is typically called by AI agents during voice interactions.
Authentication
No authentication required. This endpoint is public by default. Implement your own authentication middleware if needed.Request Headers
Must be
application/jsonRequest Body
The normalized name of the function to execute (snake_case lowercase). Must match a name from
GET /navai/functions.Arguments to pass to the function. Structure depends on the function signature and invocation style.
Explicit array of arguments. If present, used directly as function arguments.
Single value argument. If
args is not present, this becomes the first argument.For class methods: arguments to pass to the class constructor.
For class methods: arguments to pass to the method.
Response
Success Response
Always
true for successful executionsThe normalized name of the executed function
Source file path and export name in format
path/to/file.ts#exportNameThe return value from the executed function. Can be any JSON-serializable value.
Example Requests
Basic Function Call
Using value Instead of args
Object as First Argument
args and value are not present, the entire payload object becomes the first argument.
Class Method Execution
Example Success Response
Error Responses
400 - Missing Function Name
function_name is missing, empty, or not a string.
404 - Unknown Function
function_name is not in the loaded registry. The response includes a list of available functions.
500 - Execution Error
500 - Runtime Loading Error
Argument Resolution
The runtime resolves function arguments using this priority:-
If
payload.argsexists: Use as argument list directly→fn("arg1", "arg2") -
Else if
payload.valueexists: Use as first argument→fn("arg1") -
Else if payload has keys: Use entire payload as first argument
→
fn({ name: "John", age: 30 }) -
If function arity expects one more argument: Append context
Context includes
{ req }(Express Request object)
Class Method Handling
For functions derived from class methods:- Instantiate the class:
new DatabaseClient("postgresql://localhost/mydb") - Call the method:
instance.query("SELECT * FROM users", [])
Context Object
If your function signature expects a context parameter, it will receive:Security Considerations
- Only functions from configured
NAVAI_FUNCTIONS_FOLDERScan be executed - Function names are normalized and validated before execution
- Unknown function names are rejected with 404
- The endpoint is public by default - implement authentication middleware if needed
- Function code runs in the same process as your Express server
- Be cautious about exposing sensitive operations through this endpoint
Runtime Behavior
- Function runtime is lazy-loaded on first request
- Runtime is cached in-memory after initial load
- File changes require process restart to take effect
- Both
GET /navai/functionsandPOST /navai/functions/executeshare the same runtime instance
Configuration
Control function execution withRegisterNavaiExpressRoutesOptions:
Environment Variables
NAVAI_FUNCTIONS_FOLDERS: Comma-separated list of folders/patterns to scanNAVAI_FUNCTIONS_BASE_DIR: Base directory for relative paths (default:process.cwd())
Implementation
Implemented inpackages/voice-backend/src/index.ts:298-330 via registerNavaiExpressRoutes.