1. Authentication & Configuration
All requests to the Lyzr Voice API require anx-api-key header containing your organization’s API key.
- Base URL:
https://ba-dc3c74596474493fba4d44a9ea25b57f.ecs.us-east-1.on.aws - Authentication Header:
x-api-key: <YOUR_LYZR_API_KEY>
2. The Integration Flow
Step 1: Start a Session
Before connecting via WebRTC, you must request a session token from the Lyzr backend. This “dispatches” the agent to a specific room.- Endpoint:
POST /v1/sessions/start - Request Body:
- Response: You will receive a
userTokenand alivekitUrl.
Step 2: Connect to the Agent Room
Lyzr uses the LiveKit SDK for real-time audio transport. Use theuserToken and livekitUrl from the previous step to join the room.
In a React environment, you can use the <LiveKitRoom> component:
Step 3: Stream Audio & Handle Events
Once connected, publish your microphone track. The agent will automatically respond with audio and transcription data events.- Audio Output: Use the standard LiveKit
RoomAudioRendererfor the agent’s voice. - Background Audio: Lyzr agents often publish a secondary track named
background_audiofor ambient sounds and “thinking” sound effects. You must manually attach this track to an HTML audio element. - Transcriptions: Use the
useTrackTranscriptionhook to display real-time captions for both the user and the agent.
Step 4: End the Session
To prevent unnecessary costs and clean up resources, explicitly end the session when the user hangs up.- Endpoint:
POST /v1/sessions/end - Body:
{ "roomName": "room-id-from-start-response" }
3. Reference Implementation
API Client (src/lib/api-client.ts)
The demo uses a centralized apiFetch wrapper to inject the API key and handle prefixes:
Session Hook (src/hooks/useLyzrSession.ts)
This hook manages the state transition from idle to connected: