Install the JavaScript SDK
In your Next.js project, install the SDK with your package manager:Connect the browser
Add a server action that signs a start ticket. The browser calls it just before each start, so the ticket is always fresh:streamToVideoElement() starts microphone capture and renders the avatar’s video and audio in the element with the matching ID.
Working component example
Below is a React component with connection lifecycle and a streaming transcript. TheMESSAGE_STREAM_EVENT_RECEIVED event fires for each chunk of text from both the user and the agent. Accumulate chunks by message ID to build the full transcript.
The component also cleans up after itself. When the session ends, the connection closes, or the component unmounts, it removes its event listeners and calls stopStreaming(), so the session and the microphone don’t outlive the page. If it unmounts while still connecting, it ends the new session as soon as it opens.
Run your first conversation
- Save the server action as
app/actions.tsand the component asapp/AvatarChat.tsx, and render<AvatarChat />from a page such asapp/page.tsx. The route reads your avatar and agent IDs fromANAM_AVATAR_IDandELEVENLABS_AGENT_ID, so the component doesn’t need them. - Start your development server with your project’s dev command, such as
npm run dev. Open the page on localhost. - Click Start and allow microphone access. The avatar video should appear and the button should change to Stop.
- Speak to the agent. Confirm that you hear its reply, see the avatar speaking in sync, and see both sides of the conversation in the transcript.
- Click Stop to end the session. Click Start again to check that you can reconnect, then stop the session when you finish testing. If you navigate away during a session, the component ends it for you.
Quickstart complete. You now have a working ElevenLabs agent with an Anam avatar.
Upgrade your avatar
Your avatar session is running. Build on it with expressive performance, personalised conversations, and actions in your app:- Director Notes: add expressions that follow ElevenLabs audio tags.
- Session customisation: pass user-specific variables, override settings, or attach a user ID.
- Client tools: let the agent trigger actions in your browser and receive the results.
Next: Add Director Notes
Connect ElevenLabs audio tags to the avatar’s performance.

