A Hedra avatar session.

This class manages the connection between a LiveKit agent and a Hedra avatar, routing agent audio output to the avatar for visual representation.

Example

// Using an avatar ID
const avatar = new AvatarSession({
avatarId: 'your-avatar-id',
apiKey: 'your-hedra-api-key',
});
await avatar.start(agentSession, room);

// Using a custom avatar image
const imageBuffer = fs.readFileSync('avatar.jpg');
const avatar = new AvatarSession({
avatarImage: {
data: imageBuffer,
mimeType: 'image/jpeg',
filename: 'avatar.jpg',
},
apiKey: 'your-hedra-api-key',
});
await avatar.start(agentSession, room);

Constructors

Methods

Constructors

  • Creates a new AvatarSession.

    Parameters

    Returns AvatarSession

    Throws

    HedraException if neither avatarId nor avatarImage is provided, or if HEDRA_API_KEY is not set

Methods

  • Starts the avatar session and connects it to the agent.

    This method:

    1. Creates a LiveKit token for the avatar participant
    2. Calls the Hedra API to start the avatar session
    3. Configures the agent's audio output to stream to the avatar

    Parameters

    • agentSession: AgentSession<unknown>

      The agent session to connect to the avatar

    • room: Room

      The LiveKit room where the avatar will join

    • options: StartOptions = {}

      Optional LiveKit credentials (falls back to environment variables)

    Returns Promise<void>

    Throws

    HedraException if LiveKit credentials are not available or if the avatar session fails to start