Looking to build with React/Next.js? Check out our Next.js
guide.
What You’ll Need
- An ElevenLabs agent created following this guide
npm
installed on your local system- Basic knowledge of JavaScript
Looking for a complete example? Check out our Vanilla JS demo on
GitHub.
Project Setup
1
Create a Project Directory
Open a terminal and create a new directory for your project:
2
Initialize npm and Install Dependencies
Initialize a new npm project and install the required packages:
3
Set up Basic Project Structure
Add this to your Create the following file structure:
package.json
:package.json
Implementing the Voice Chat Interface
1
Create the HTML Interface
In 
index.html
, set up a simple user interface:
index.html
2
Implement the Conversation Logic
In
script.js
, implement the functionality:script.js
3
Start the frontend server
Make sure to replace
'YOUR_AGENT_ID'
with your actual agent ID from
ElevenLabs.(Optional) Authenticate with a Signed URL
(Optional) Authenticate with a Signed URL
This authentication step is only required for private agents. If you’re using a public agent, you can skip this section and directly use the
agentId
in the startSession
call.1
Create Environment Variables
Create a
.env
file in your project root:.env
Make sure to add
.env
to your .gitignore
file to prevent accidentally committing sensitive credentials.2
Setup the Backend
- Install additional dependencies:
- Create a new folder called
backend
:
3
Create the Server
backend/server.js
4
Update the Client Code
Modify your
script.js
to fetch and use the signed URL:script.js
Signed URLs expire after a short period. However, any conversations initiated before expiration will continue uninterrupted. In a production environment, implement proper error handling and URL refresh logic for starting new conversations.
5
Update the package.json
package.json
6
Run the Application
Start the application with:
Next Steps
Now that you have a basic implementation, you can:- Add visual feedback for voice activity
- Implement error handling and retry logic
- Add a chat history display
- Customize the UI to match your brand
For more advanced features and customization options, check out the
@11labs/client package.