Skip to main content

Repository

The Python SDK is available on GitHub: spatialwalk/avatar-sdk-python and PyPI.
pip install avatarkit

Requirements

  • api_key
  • app_id
  • avatar_id
  • Console endpoint URL (per region)
  • Ingress endpoint URL (per region)

Endpoints (by region)

Build your endpoint URLs using your selected region (see Regions):
  • Console endpoint URL: https://console.<region>.spatialwalk.cloud/v1/console
  • Ingress endpoint URL (v2): wss://api.<region>.spatialwalk.cloud/v2/driveningress

Quick start

import asyncio
from datetime import datetime, timedelta, timezone

from avatarkit import new_avatar_session


async def main():
    session = new_avatar_session(
        api_key="your-api-key",
        app_id="your-app-id",
        avatar_id="your-avatar-id",
        expire_at=datetime.now(timezone.utc) + timedelta(minutes=5),
        console_endpoint_url="https://console.us-west.spatialwalk.cloud/v1/console",
        ingress_endpoint_url="wss://api.us-west.spatialwalk.cloud/v2/driveningress",
        transport_frames=lambda frame, last: print(f"Received frame: {len(frame)} bytes, last={last}"),
        on_error=lambda err: print(f"Error: {err}"),
        on_close=lambda: print("Session closed"),
    )

    await session.init()
    connection_id = await session.start()
    print(f"Connected: {connection_id}")

    # Send audio
    audio_data = b"..."  # Your PCM audio data
    request_id = await session.send_audio(audio_data, end=True)
    print(f"Sent audio: {request_id}")

    await asyncio.sleep(10)

    await session.close()


if __name__ == "__main__":
    asyncio.run(main())

Egress Mode

For real-time applications, you can configure egress to stream avatar output directly to a real-time platform: LiveKit (rooms) or Agora (channels). See LiveKit Server (section 2) or Agora Server (section 2) for full configuration and code examples. Quick example with LiveKit:
from avatarkit import new_avatar_session, LiveKitEgressConfig

session = new_avatar_session(
    # ... other options ...
    livekit_egress=LiveKitEgressConfig(
        url="wss://your-livekit-server.com",
        api_key="livekit-api-key",
        api_secret="livekit-api-secret",
        room_name="your-room-name",
        publisher_id="avatar-publisher",
    ),
)
Quick example with Agora:
from avatarkit import new_avatar_session, AgoraEgressConfig

session = new_avatar_session(
    # ... other options ...
    agora_egress=AgoraEgressConfig(
        channel_name="your-channel-name",
        token="agora-token",
        uid=0,
    ),
)

Changelog

https://github.com/spatialwalk/avatar-sdk-python/releases