WebSocket
Create real-time, interactive voice conversations with AI agents
Create real-time, interactive voice conversations with AI agents
This documentation is for developers integrating directly with the ElevenLabs WebSocket API. For convenience, consider using the official SDKs provided by ElevenLabs.
The ElevenAgents WebSocket API enables real-time, interactive voice conversations with AI agents. By establishing a WebSocket connection, you can send audio input and receive audio responses in real-time, creating life-like conversational experiences.
wss://api.elevenlabs.io/v1/convai/conversation?agent_id={agent_id}For public agents, you can directly use the agent_id in the WebSocket URL without additional authentication:
For private agents or conversations requiring authorization, obtain a signed URL from your server, which securely communicates with the ElevenLabs API using your API key.
Request:
Response:
The following events can be sent from the client to the server:
Send non-interrupting contextual information to update the conversation state. This allows you to provide additional context without disrupting the ongoing conversation flow.
Use cases:
Key points:
Contextual updates are processed asynchronously and do not require a direct response from the server.
This example demonstrates how to implement a WebSocket-based conversational agent client in Next.js using the ElevenLabs WebSocket API.
While this example uses the voice-stream package for microphone input handling, you can
implement your own solution for capturing and encoding audio. The focus here is on demonstrating
the WebSocket connection and event handling with the ElevenLabs API.
First, install the necessary packages:
The voice-stream package handles microphone access and audio streaming, automatically encoding the audio in base64 format as required by the ElevenLabs API.
This example uses Tailwind CSS for styling. To add Tailwind to your Next.js project:
Then follow the official Tailwind CSS setup guide for Next.js.
Alternatively, you can replace the className attributes with your own CSS styles.
To ensure smooth conversations, implement these strategies: