Skip to main content
Complete step one: Agent configuration first. In this step, add the server route that connects your ElevenLabs agent to Anam.

Prerequisites

  • Node.js 20.9+
  • A Next.js project using the App Router, or the demo project
  • An Anam account and API key (sign up free at lab.anam.ai)
  • A Cara 4 avatar from the Anam Lab Avatars page
  • An ElevenLabs account with a Conversational AI agent configured via the dashboard

Create the server route

You need one API route. It checks that the request came from your own site, fetches a signed URL from ElevenLabs, then passes it to Anam when creating a session token. API keys and IDs stay server-side. The route reads the avatar ID (which face to render) and the ElevenLabs agent ID from environment variables, so a caller can’t point your keys at a different agent or avatar.

Environment variables

None of these use the NEXT_PUBLIC_ prefix, so Next.js never sends them to the browser.

Protect the route

Every session uses minutes on your Anam account and your ElevenLabs agent. Without a check, any website or script could call the route and start sessions on your keys. These helpers add two checks:
  • Same origin. The route rejects requests that a browser sent from another site.
  • Start ticket. Just before each start, a server action signs a ticket with SESSION_SECRET, which never leaves the server. The route accepts each ticket once, within two minutes.
These checks stop other websites from using your route from a visitor’s browser. They aren’t user authentication and don’t stop someone who scripts requests against your site. In a real app, also check your own user session in the route and rate-limit it.

API route

The environment.elevenLabsAgentSettings field configures ElevenLabs as the session’s speech recognition, language model, and text-to-speech provider. avatarModel and directorNotes enable a warm Cara 4 performance at the start of the session.
The signed URL is short-lived (typically valid for 15 minutes). Anam uses it immediately when the client connects, so there’s no issue with expiry in normal usage. If you’re pre-fetching tokens, create them just before the client needs them.
Your server route is ready. Next, start an avatar session in your browser.

Step 3: Start the avatar session

Connect the browser, enable your microphone, and have your first conversation with the avatar.
Last modified on November 20, 2026