Skip to main content
The Go SDK creates Spatius avatar sessions from backend services. It requests a short-lived session token from the Console API, opens the ingress WebSocket, sends audio, and returns motion data payloads through callbacks.

Install

Repository: spatius-ai/spatius-sdk-go

Quick start

Region configuration

The SDK defaults to us-west when no region is provided, or when WithRegion receives an empty or whitespace-only value. See Regions for the current region list. To set a region:

Session lifecycle

  1. Create a session with NewAvatarSession.
  2. Call Init(ctx) to exchange the API key and expiry time for a session token.
  3. Call Start(ctx) to open the ingress WebSocket and configure the avatar session.
  4. Call SendAudio(audio, end) for each audio chunk.
  5. Call Interrupt() when playback should stop.
  6. Call Close() when the session is done.
SendAudio returns the request ID associated with the audio. The callback passed to WithTransportFrames receives motion data payloads and a last flag. For audio source and timing guidance, see Audio.

Audio format

PCM 16-bit little-endian is the default input format:
The SDK also supports Ogg Opus sessions:
Passing nil to WithOggOpusEncoder enables the default encoder config.

Authentication mode

By default, WebSocket authentication is sent in headers:
For web-style query authentication, enable:

LiveKit egress

Use LiveKit egress when Spatius should publish avatar output directly into a LiveKit room:
Prefer APIToken for new integrations. APIKey and APISecret remain available for older setups.

Options

Core options:
  • WithAPIKey(apiKey string) - Console API key.
  • WithAppID(appID string) - application ID.
  • WithAvatarID(avatarID string) - avatar ID.
  • WithExpireAt(expireAt time.Time) - session token expiry.
  • WithRegion(region string) - region used to select the Spatius region. Empty or whitespace-only values fall back to us-west.
  • WithConsoleEndpointURL(endpointURL string) - explicit Console API URL.
  • WithIngressEndpointURL(endpointURL string) - explicit ingress WebSocket URL.
Audio options:
  • WithSampleRate(sampleRate int) - input sample rate in Hz.
  • WithBitrate(bitrate int) - target bitrate for encoded sessions.
  • WithAudioFormat(audioFormat AudioFormat) - AudioFormatPCMS16LE or AudioFormatOggOpus.
  • WithOggOpusEncoder(config *OggOpusEncoderConfig) - enable client-side PCM to Ogg Opus encoding.
Callbacks:
  • WithTransportFrames(func([]byte, bool)) - receives motion data payloads.
  • WithOnEncodedAudio(func(string, []byte)) - receives internally encoded audio by request ID.
  • WithOnError(func(error)) - receives async session errors.
  • WithOnClose(func()) - runs when the session closes.
Egress options:
  • WithLiveKitEgress(config *LiveKitEgressConfig) - stream output to LiveKit.
  • WithAgoraEgress(config *AgoraEgressConfig) - stream output to Agora.

Changelog

See GitHub releases.