Installation

Install the SDK in your project using npm:

npm install @anam-ai/sdk

Local Development

The quickest way to start using the SDK is with a local development setup:

This example uses the unsafe_createClientWithApiKey method. This is not recommended for production use as it exposes your API key. See the Usage in Production guide for secure implementation.

import { unsafe_createClientWithApiKey } from '@anam-ai/js-sdk';

const anamClient = unsafe_createClientWithApiKey('your-api-key', {
  personaId: 'chosen-persona-id',
});

// Start streaming to video and audio elements
await anamClient.streamToVideoAndAudioElements(
  'video-element-id',
  'audio-element-id'
);

If you haven’t already created your own persona, you can use one of our default personas to get started. Try Leo, the AI receptionist with the ID 773a8ca8-efd8-4449-9305-8b8bc1591475.

DOM Elements

This quickstart example requires two DOM elements to stream to:

  • A video element to play the video stream of your persona
  • An audio element to play the voice stream of your persona

For this example we would include the following in our HTML:

<video id="video-element-id" autoplay playsinline></video>
<audio id="audio-element-id" autoplay></audio>

autoplay is used to start the stream as soon as the page loads. The playsinline attribute prevents the video from being played in fullscreen mode on mobile devices.

Stopping a Stream

To stop an active session, use the stopStreaming method. This will end the current session and release the audio and video elements.

await anamClient.stopStreaming();

Next Steps

Usage in Production

Before taking the next steps to release your persona to real users, learn the important considerations for using personas in production.