Quick Reference
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.direct), where it authenticates the Motion Server WebSocket; RTC / Platform Integration / Backend Mode paths do not need it. See Credentials for the per-path breakdown.AvatarSDK
Main entry point for SDK initialization and global configuration.Static properties
Static methods
initialize(appId, configuration)
Initialize the SDK. Must be called before any other operation.setSessionToken(token)
Set the Session Token used to authenticate the Motion Server WebSocket. Only required in Direct Mode (DrivingServiceMode.direct); AvatarController.start() opens that WebSocket and authenticates with the token.
- Required for
DrivingServiceMode.directbefore callingAvatarController.start(). - Not required for
DrivingServiceMode.backend(LiveKit Agents Integration, RTC Adapter path, Backend Mode). Those paths receive audio and motion data 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.setUserId(userId)
Set a user identifier for logging and telemetry.setRenderQuality(quality)
Update the global rendering quality tier. The change takes effect on the next rendered frame across activeAvatarView instances.
setRenderResolutionCap(enabled, maxHeight?)
Cap the render backing-buffer height while keeping the same CSS size. This is useful on high-DPI displays where rendering above the source avatar asset resolution adds cost without visible benefit.deviceScore()
Run a short CPU/GPU benchmark and return device scores.isDeviceSupported()
Check whether the current device can run AvatarKit. In1.2.0, this runs the same benchmark path used by deviceScore().
cleanup()
Release all SDK resources. Call when the SDK is no longer needed.AvatarManager
Handles avatar asset loading and caching. Access via the singletonAvatarManager.shared.
Static properties
Instance methods
load(id, onProgress?, useCompressedModel?)
Load an avatar by ID. Downloads and caches the avatar’s assets.
Returns:
Promise<Avatar>
cancelLoad(id)
Cancel a pending or running avatar load task.retrieve(id)
Return a cached avatar instance, if available.clear(id)
Clear a specific avatar from cache.clearAll()
Clear all cached avatar resources.AvatarView
3D rendering view. Automatically creates a Canvas element and an associatedAvatarController.
Constructor
Render over an Avatar Background
Download the optional 16:9 background from Spatius Studio and store it as an application asset. Set it on the same stage element that you pass toAvatarView; the SDK-created canvas has a transparent background.
Instance properties
Transform coordinates
Instance methods
dispose()
Release all view resources. Call when the view is no longer needed (see Lifecycle management for details).exportBitmap()
Capture the current rendered avatar frame as a PNGBlob. Returns null if the canvas is not initialized or not currently rendering.
getCameraConfig() / updateCameraConfig(cameraConfig)
Read or update the camera used by the renderer.pauseRendering() / resumeRendering()
Pause or resume GPU/canvas rendering without stopping audio playback.isRenderingEnabled()
Check whether the render loop is currently active.getBoundingRect()
Return the approximate avatar bounds in CSS pixels, ornull if the view is not ready. Recalculate after container size or avatarTransform changes.
AvatarController
Handles runtime communication with Motion Server and playback control.Event callbacks
Instance properties
DrivingServiceMode.direct methods
Available when drivingServiceMode is DrivingServiceMode.direct (the Direct Mode path).
initializeAudioContext()
Initialize the audio context. Must be called inside a user-gesture handler (e.g. aclick listener).
start()
Connect to Motion Server.send(audioData, end)
Send avatar speech audio. Returns theconversationId for the current round.
For audio source and timing guidance, see Audio.
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 viaonConversationState). Sending new audio after this starts a new round and interrupts any ongoing playback.
close()
Close the Motion Server connection.DrivingServiceMode.backend methods
Available when drivingServiceMode is DrivingServiceMode.backend (the Backend Mode path).
yieldAudioData(audioData, end?)
Provide audio data when your backend owns the Motion Server connection.
Returns:
string | null — conversation ID for this audio round, or null if audio playback could not start.
yieldFramesData(motionDataPayloads, conversationId)
Provide motion data payloads when usingDrivingServiceMode.backend. The conversationId must match the one returned by the corresponding yieldAudioData() call.
Returns:
boolean — true when the final motion data payload for that conversation has been received, otherwise false.
Common methods
Available in bothDrivingServiceMode.direct and DrivingServiceMode.backend.
Types and Enums
Configuration
region selects the Spatius deployment region. It defaults to 'us-west'; supported values are 'us-west', 'ap-northeast', and 'cn-beijing'. See Regions for endpoint details and override options.
DrivingServiceMode
RenderQuality
FrameStarvationMode
audioIndependent keeps audio playing while motion data catches up. strictSync pauses audio when motion data runs out and resumes when new motion data arrives; use onPlaybackStall to observe those transitions.
AnimationType
LogLevel
ConnectionState
Reported viaonConnectionState. Only emitted when drivingServiceMode is DrivingServiceMode.direct.
ConversationState
Reported viaonConversationState.
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.LoadProgressInfo
AudioFormat
The SDK requires audio in mono PCM16 format.
Data size: 1 second at 16 kHz = 16,000 samples × 2 bytes = 32,000 bytes.
Converting MP3 to PCM16
Converting MP3 to PCM16
Error Handling
AvatarError
Error callback
ErrorCode
AvatarError.code is one of the SDK string enum values below.
Lifecycle Management
Avatar switching
Resource cleanup
dispose() automatically cleans up:
- WebSocket connections
- Audio playback data and animation resources
- Canvas elements and the render system
- Event listeners and callbacks
Fallback mechanism
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.
onConnectionStatereportsfailedwhen the connection times out.

