Skip to main content

What is Direct Mode for Web?

Direct Mode for Web is the simplest way to put a Spatius avatar in a browser app. @spatius/avatarkit connects directly to Motion Server, sends avatar speech audio, and renders motion locally — no agent worker or relay backend needed beyond a Session Token endpoint.

When to use

  • You have or generate avatar speech audio in the browser — your own TTS output, prerecorded clips, or agent audio fetched server-side.
  • You want the smallest backend footprint: a single Session Token endpoint.
  • You want the client to own rendering and don’t need backend-controlled audio or transport.

Run the demo

Web SDK quickstart

One quickstart with bundled sample audio plus optional realtime conversation.

Multi-framework reference

React, Vue, vanilla JavaScript, and Next.js reference clients.

Install

Build tool configuration

Required: The SDK uses WASM files that need special build configuration. Configure your build tool before initializing the SDK, or .wasm requests will fail.
Add the official plugin to vite.config.ts:
vite.config.ts
  • Dev server: serves .wasm files with the correct MIME type
  • Build: copies WASM files to dist/assets/
  • Cloudflare Pages: generates a _headers file
  • Vite options: configures optimizeDeps, assetsInclude, assetsInlineLimit
vite.config.ts
For deeper toolchain explanation, see Toolchain Setup.

Minimum integration

The smallest end-to-end flow with @spatius/avatarkit:
1

Initialize the SDK

2

Load the avatar

3

Mount the view

4

Initialize audio (inside a user gesture)

initializeAudioContext() must be called inside a user-gesture handler (a click, touchstart, or similar listener). Browsers reject AudioContext creation outside user gestures and the call fails silently.
5

Connect and send audio

For audio source and timing guidance, see Audio.
6

Cleanup

For full API signatures, types, audio format details, lifecycle management, error codes, browser compatibility, and common issues, see Web SDK Reference.

Next steps

Web SDK reference

Complete Web SDK API: AvatarSDK, AvatarManager, AvatarView, AvatarController, types, errors.

Browse all demos

Every runnable demo by platform and integration path.