Basic Usage
Install, setup, and deploy the Anam AI JavaScript SDK
Installation
Install the SDK in your project using npm:
DOM Elements
This quickstart example requires a video element to display the persona:
For this example we would include the following in our HTML:
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.
Basic Usage
It is important to not expose your API key publicly. Instead, you should:
- Exchange your API key for a short-lived session token on the server side
- Pass this token to the client
- Initialize the Anam SDK with the session token
Step 1: Getting a Session Token
From your server, make a request to get a session token using your API key and persona configuration:
Step 2: Initialize the Client
Once you have a session token, use the createClient
method to initialize the Anam client:
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.