Basic application
Take your first steps with Anam
The Anam API provides a simple interface for implementing digital AI personas within your web applications. This guide will walk you through the process of setting up a minimal example of an interactive AI persona. By the end, you’ll have a working persona that can have real-time conversations in your web application.
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 quickstart creates a minimal web application with three main files organized in a simple project structure:
Create project directory
Initialize Node.js project
This creates a package.json
file for managing dependencies.
Create public directory
The public
folder will contain your HTML and JavaScript files that are served to the browser.
Install dependencies
We’re installing Express for the server and dotenv for environment variable management. The Anam SDK will be loaded directly from a CDN in the browser.
Create environment file
Create a .env
file in your project root to store your API key securely:
Replace your-api-key-here
with your actual Anam API key. Never commit this file to version control.
Step 1: Set up your server
For this example, we’ll create a basic Express server to handle session token generation. In a real application, you should integrate this functionality into your existing backend service.
The server endpoint exchanges your API key and persona configuration for a temporary session token that the client can safely use. This token has limited scope and expires, providing an additional security layer.
Step 2: Set up your HTML
Create a simple HTML page with a video element for the persona and controls to start/stop the chat:
Step 3: Initialize the Anam client
Create the client-side JavaScript to control your persona connection:
Step 4: Run your application
- Start your server:
-
Open http://localhost:3000 in your browser
-
Click “Start Chat” to begin your conversation with Cara!
You should see Cara appear in the video element and be ready to chat through voice interaction.
What’s happening?
- Server-Side Security: Your server safely exchanges your API key for a session token, keeping credentials secure
- Client Connection: The SDK creates a WebRTC connection for real-time video streaming when you start the chat
- Voice Interaction: Cara listens for your voice input and responds with synchronized audio and video
- Connection Control: Start and stop buttons give you full control over when the persona is active
Next Steps
Core Concepts
Learn how personas, tokens, and streaming work
Customize Your Persona
Change appearance, voice, and behavior
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
- Ensure the video element has autoplay and playsinline attributes
- Check browser console for errors
No audio?
- Make sure your browser allows autoplay with sound
- Check that the user has interacted with the page first (clicking “Start Chat” counts)
Connection issues?
- Verify your server can reach api.anam.ai
- Check network connectivity and firewall settings