What You’ll Need
- An ElevenLabs agent created following this guide
npm
installed on your local system.- We’ll use Typescript for this tutorial, but you can use Javascript if you prefer.
Looking for a complete example? Check out our Next.js demo on
GitHub.

Setup
1
Create a new Next.js project
Open a terminal window and run the following command:It will ask you some questions about how to build your project. We’ll follow the default suggestions for this tutorial.
2
Navigate to project directory
3
Install the ElevenLabs dependency
4
Test the setup
Run the following command to start the development server and open the provided URL in your browser:

Implement Conversational AI
1
Create the conversation component
Create a new file
app/components/conversation.tsx
:app/components/conversation.tsx
2
Update the main page
Replace the contents of
app/page.tsx
with:app/page.tsx
(Optional) Authenticate the agents with a signed URL
(Optional) Authenticate the agents 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.What You’ll Need
- An ElevenLabs account and API key. Sign up here.
1
Create environment variables
Create a
.env.local
file in your project root:.env.local
- Make sure to add
.env.local
to your.gitignore
file to prevent accidentally committing sensitive credentials to version control. - Never expose your API key in the client-side code. Always keep it secure on the server.
2
Create an API route
Create a new file
app/api/get-signed-url/route.ts
:app/api/get-signed-url/route.ts
3
Update the Conversation component
Modify your
conversation.tsx
to fetch and use the signed URL:app/components/conversation.tsx
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.
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/react package.