Skip to main content
AvatarKit follows a four-stage lifecycle: Initialize → Load → Connect → Cleanup. Each stage maps to a core component.

Overview

StageComponentWhat happens
InitializeAvatarSDKConfigures app ID, environment, audio format, and driving mode. Must be called once before any other API.
LoadAvatarManagerDownloads and caches avatar assets. Returns an Avatar instance.
RenderAvatarViewCreates the rendering surface and its associated AvatarController.
ConnectAvatarControllerOpens a WebSocket to the driving service. The avatar begins responding to audio.

Stage 1: Initialize

Call AvatarSDK.initialize() once at app startup. This sets global configuration that all subsequent operations depend on.
await AvatarSDK.initialize({
  appId: 'YOUR_APP_ID',
  audioFormat: { channelCount: 1, sampleRate: 16000 },
  drivingServiceMode: 'sdk',
});
Set AvatarSDK.sessionToken before connecting. The token authenticates your session with the driving service.

Stage 2: Load Avatar

Use AvatarManager to download and cache avatar assets. Loading is asynchronous and supports progress tracking.
const avatar = await AvatarManager.load('AVATAR_ID', (progress) => {
  console.log('Loading:', progress);
});
Loaded assets are cached locally. Subsequent loads for the same avatar ID skip the download. Use AvatarManager.clear(id:) or clearAll() to manage cache.

Stage 3: Render

Create an AvatarView with the loaded avatar. The view automatically creates an AvatarController you can access to manage the connection and send audio.
const avatarView = new AvatarView(containerElement, avatar);
const controller = avatarView.avatarController;

Stage 4: Connect and Interact

Call controller.start() to open the WebSocket connection. Once connected, send audio with controller.send() (SDK Mode) or controller.yield() (Host Mode).
Call controller.interrupt() to stop the current playback immediately. Call controller.close() when done.

Cleanup

Always clean up resources when the avatar is no longer needed to avoid memory leaks.
controller.close();
avatarView.destroy();
On Android, always call avatarView.cleanup() when the view is removed (e.g., in onDestroy). Failing to do so can leak GPU resources.