This directory contains examples demonstrating how to use the websocket modality of the Aplisay LLM Agent API.
This example shows how to:
- Create an agent
- Activate it for websocket connections
- Join a websocket room
- Receive and send binary audio data from/to the speaker in node.js
- Clean up resources properly
- Node.js (v20 or higher)
- Access to an LLM Agent API server (default: http://localhost:5000/api)
- API key for authentication
- Install dependencies:
yarn install- Configure the API key:
- Create a
.envfile in the examples directory if it doesn't exist - Add your API key to the
.envfile:API_KEY="your-api-key-here" - The example uses this key for bearer authentication with the API
- Create a
Run the WebSocket monitor example:
yarn startThe example will:
- Get available models from the API
- Create an agent using the first available model
- Activate the agent for WebRTC/websocket connections
- Get room join information
- Connect to the websocket
- Read and write audio for 60 seconds
- Clean up by deleting the listener and agent
GET /models- Get available modelsPOST /agents- Create a new agentPOST /agents/{agentId}/listen- Activate an agentPOST /rooms/{listenerId}/join- Get join information for a roomDELETE /agents/{agentId}/listen/{listenerId}- Delete a listenerDELETE /agents/{agentId}- Delete an agent
The example uses bearer authentication with an API key. The key should be stored in a .env file in the examples directory. The API client automatically includes the key in the Authorization header for all requests.
The example includes error handling:
- API call errors are caught and logged
- WebSocket connection errors are handled
- Resources are properly cleaned up in case of errors
- Graceful shutdown on completion or error