App ID is required on every integration path and identifies your Spatius application (it scopes which avatars you can load). Session Token is only required for Direct Mode (DrivingServiceMode.sdk), where it authenticates the Motion Server WebSocket; RTC / Platform Integration / Backend Mode paths do not need it. See Credentials for the per-path breakdown.
For the minimum end-to-end integration walkthrough (install, build configuration, init, load, connect), see the Direct Mode guide for Web.
region is accepted at runtime by @spatius/[email protected], but the published TypeScript types do not yet expose it on Configuration. To pass it without a type error, drop one declaration-merging file into your project:
Set the Session Token used to authenticate the Motion Server WebSocket. Only required in Direct Mode (DrivingServiceMode.sdk); AvatarController.start() opens that WebSocket and authenticates with the token.
AvatarSDK.setSessionToken('your-session-token')
Required for DrivingServiceMode.sdk before calling AvatarController.start().
Not required for DrivingServiceMode.host (LiveKit Agents Integration, RTC Adapter path, Backend Mode). Those paths receive audio + motion through their own transport and do not open a Motion Server WebSocket from the client; AvatarManager.load() fetches avatar metadata over an App-ID-scoped public endpoint.
The token must be obtained from your backend (see Session token API).
Maximum 24-hour validity.
Token must be paired with the App ID used in initialize().
setSessionToken() can be called before or after initialize(). If called before, the token is applied automatically during initialization.
Send avatar speech audio. Returns the conversationId for the current round.
const conversationId = controller.send( audioData, // PCM16, mono, ArrayBuffer end, // true = end of conversation round)
Parameter
Type
Description
audioData
ArrayBuffer
PCM16 mono audio data
end
boolean
Whether this is the final chunk of the current round
send() behavior:
end: false — continues the current conversation round.
end: true — marks the end of audio input for the current round. The avatar plays the remaining animation, then returns to idle (notified via onConversationState). Sending new audio after this starts a new round and interrupts any ongoing playback.
Provide encoded motion frames when using DrivingServiceMode.host. The conversationId must match the one returned by the corresponding yieldAudioData() call.
Available in both DrivingServiceMode.sdk and DrivingServiceMode.host.
controller.pause() // Pause audio + animationcontroller.resume() // Resume playbackcontroller.interrupt() // Stop current playback// Volume control (avatar audio only, not system volume)controller.setVolume(0.5) // 0.0 to 1.0controller.getVolume() // returns current volume
See Regions for endpoint details and override options. See the Note in initialize() about the region type-augmentation pattern needed for @spatius/[email protected].
enum ConversationState { idle = 'idle', // Breathing animation, waiting for input playing = 'playing', // Active conversation playback paused = 'paused', // Paused during playback}
State transitions are notified immediately when the transition starts, not when the animation completes. For example, playing is reported as soon as the transition from idle begins.
// 1. Dispose the current viewcurrentAvatarView.dispose()// 2. Load a new avatarconst newAvatar = await AvatarManager.shared.load('new-avatar-id')// 3. Create a new view (reuse the same container)currentAvatarView = new AvatarView(newAvatar, container)// 4. Reconnectawait currentAvatarView.controller.initializeAudioContext()await currentAvatarView.controller.start()
If the WebSocket connection fails within 15 seconds, the SDK automatically enters audio-only fallback mode — audio continues playing without animation. This keeps playback uninterrupted when Motion Server is unreachable.
Fallback mode is interruptible like normal playback.
onConnectionState reports failed when the connection times out.