Skip to main content
This guide creates a minimal but complete web application with an interactive AI persona. You will build a Node.js server that handles authentication and a client that streams the persona to a video element.
Looking for a faster start? The Quickstart guide gets you running in a single HTML file without a server.

Prerequisites

  • Node.js (version 16 or higher) and npm installed on your system
  • Basic knowledge of JavaScript
  • An Anam API key (get one here)
  • A microphone and speakers for voice interaction

Project Setup

This example creates a web application with three main files:
1

Create project directory

2

Initialize Node.js project

3

Create public directory

4

Install dependencies

5

Create environment file

Create a .env file in your project root to store your API key securely:
.env
Replace your-api-key-here with your actual Anam API key. Never commit this file to version control.

Step 1: Set up your server

Create a basic Express server to handle session token generation. In a production application, integrate this into your existing backend service.
server.js
The server exchanges your API key for a temporary session token. This token has limited scope and expires, so your API key stays secure on the server.

Step 2: Set up your HTML

Create an HTML page with a video element for the persona and controls to start/stop the chat:
public/index.html

Step 3: Initialize the Anam client

Create the client-side JavaScript to control your persona connection:
public/script.js
For details on createClient, streamToVideoElement, and stopStreaming, see the SDK Reference.

Step 4: Run your application

  1. Start your server:
  1. Open http://localhost:3000 in your browser
  2. Click “Start Chat” to begin your conversation with Cara
You should see Cara appear in the video element, ready to chat through voice interaction.

How it works

  1. Server-side authentication: Your server exchanges the API key for a session token, keeping credentials secure
  2. Client connection: The SDK creates a WebRTC connection for real-time video streaming
  3. Voice interaction: Cara listens for your voice input and responds with synchronized audio and video
  4. Connection control: Start and stop buttons control when the persona is active

Next steps

Cookbook: Basic Next.js App

Full tutorial for building a Next.js app with the Anam SDK

Core Concepts

Learn how personas, tokens, and streaming work

Handle Events

React to conversation events and user interactions

Production Setup

Deploy your persona securely at scale

Common issues

Persona not appearing?
  • Check that your API key is set correctly in .env
  • Ensure the video element has autoplay and playsinline attributes
  • Check the browser console for errors
No audio?
  • Make sure your browser allows autoplay with sound
  • The user must interact with the page first (clicking “Start Chat” satisfies this)
Connection issues?
  • Verify your server can reach api.anam.ai
  • Check network connectivity and firewall settings
Last modified on June 26, 2026