Overview

When deploying to production, it’s important not to expose your API key publicly. Instead, you should:

  1. Exchange your API key for a short-lived session token on the server side
  2. Pass this token to the client
  3. Initialize the Anam SDK with the session token

Getting a Session Token

From your server, make a request to get a session token:

const response = await fetch('https://api.anam.ai/v1/auth/session-token', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${apiKey}`,
  },
});
const data = await response.json();
const sessionToken = data.sessionToken;

Client Initialization

Once you have a session token, use the createClient method to initialize the Anam client:

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

const anamClient = createClient('your-session-token', {
  personaId: 'chosen-persona-id',
});

The client exposes the same methods whether initialized with an API key or session token.

Understanding a Session

The sequence diagram below shows how a typical session is started.

Next Steps