Skip to main content
A session goes through five stages from SDK startup to view destruction, followed by Cleanup. Each stage corresponds to an AvatarKit class or a connection prerequisite.

Stage 1: Initialize

Call AvatarSDK.initialize(appId, configuration) once when your app starts. This sets process-level configuration such as App ID, region, audio format, driving mode, and log level. AvatarKit must be initialized before you load an Avatar or create a view. Reference: Web | iOS | Android | Flutter

Stage 2: Load Avatar

AvatarManager.load(id, onProgress?) downloads avatar assets by avatar-id and returns an Avatar instance. In-flight loads for the same ID are reused, and successful loads are cached. The onProgress callback has three states: downloading, completed, and failed. progress ranges from 0 to 1. Reference: Web | iOS | Android | Flutter

Stage 3: Render

Mount the loaded Avatar into an AvatarView. The view creates the render surface and automatically creates the associated AvatarController. Do not construct the controller directly. After mounting:
  • The Avatar can play idle animation.
  • Your app can access the AvatarController.
  • Once the connection path is online and motion data arrives, playback can start.
Reference: Web | iOS | Android | Flutter

Stage 4: Authentication

Authentication differs by integration path. Only Direct Mode requires the client to hold a Spatius Session Token; the other paths authenticate inside their own transport. The API Key must only ever live on your backend.
Direct Mode reconnect: if a sessionTokenExpired / sessionTokenInvalid error fires during reconnect, fetch a fresh Session Token from your backend and call AvatarSDK.setSessionToken() again before restarting the connection. RTC / Platform Integration / Backend Mode reconnects don’t go through this flow — the Spatius client never sees a Motion Server token in those paths.
For Direct Mode session-token issuance details, see Server API: Session Token Auth Flow.

Stage 5: Connect & Interact

Use AvatarController to start connections, send and receive data, and control playback. Connection ownership differs by mode in this stage:
Do not treat controller.start() as a universal connection step. It is only the Direct Mode connection path. In Backend Mode and Platform Integrations, the Motion Server connection is established outside the client.
For audio source and timing guidance, see Audio. For state observation, see State & Events. Reference: Web | iOS | Android | Flutter

Cleanup

Release resources when the Avatar is no longer used.
Web and Android must explicitly call dispose(). iOS cleans up automatically when the view is released.
Reference: Web AvatarView | iOS AvatarView | Android AvatarView | Flutter