Skip to content

API Reference parrot.integrations.liveavatar.client

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.liveavatar.client

View source

LiveAvatar HTTP client and session lifecycle (FEAT-242 Phase A — Module 1).

Ports the LiveAvatar starter liveavatar_client.py (httpx/websockets) to aiohttp per project standards.

Responsibilities:

  • create_session_token: create a LITE session (optionally with livekit_config so the avatar joins our LiveKit Cloud room).
  • create_full_session_token: create a FULL mode session (FEAT-248).
  • start_session: start the created session (Bearer auth).
  • stop_session: stop/close the session (idempotent).
  • keep_alive: periodic HTTP keep-alive (< 5 min interval).
  • list_avatars: list available avatars (FEAT-248).
  • list_voices: list available voices (FEAT-248).
  • get_session_transcript: retrieve session transcript (FEAT-248).

Auth headers:

  • X-API-KEY: cfg.api_key on create / stop / keep-alive.
  • Authorization: Bearer <handle.session_token> on start_session.

Keep-alive strategy: HTTP /v1/sessions/{id}/keep-alive is used here (not the WS variant). # TODO P7 — if WS keep_alive is chosen in the future, move this call to AvatarWebSocket (TASK-003).

Alias AvatarSessionHandle

Re-exported from parrot.integrations.liveavatar.models.AvatarSessionHandle.

Alias FullModeConfig

Re-exported from parrot.integrations.liveavatar.models.FullModeConfig.

Alias FullModeSessionHandle

Re-exported from parrot.integrations.liveavatar.models.FullModeSessionHandle.

Class LiveAvatarClient

Async HTTP client for the LiveAvatar LITE API.

Manages session token creation, session start/stop, and periodic keep-alive. All auth is handled internally; callers receive an opaque :class:~parrot.integrations.liveavatar.models.AvatarSessionHandle.

Usage (preferred — guarantees stop on exit)::

async with LiveAvatarClient(cfg) as client:
    handle = await client.create_session_token(cfg)
    await client.start_session(handle)
    ...  # speak
Parameter Type Default Description
cfg LiveAvatarConfig LiveAvatar configuration (read from env by the caller).
session Optional[aiohttp.ClientSession] None Optional external aiohttp.ClientSession to reuse. When None (default) the client creates and owns one.

Method LiveAvatarClient.aopen

Open the owned aiohttp session (idempotent).

Used by callers that need to keep the client alive beyond a single async with block — e.g. the avatar /start endpoint, which hands the live client to a per-session store so /stop can tear it down later. Unlike __aexit__, aclose does NOT call stop_session, so ownership of the LiveAvatar session is transferred to the caller.

aopen() -> 'LiveAvatarClient'

Returns: 'LiveAvatarClient' — self (for fluent use).

Method LiveAvatarClient.aclose

Cancel the keep-alive loop and close the owned aiohttp session.

Awaits the keep-alive task's cancellation so no ping can fire against a closing session (avoids "Future exception was never retrieved"). Does NOT call stop_session — callers that opened the client via aopen must stop the LiveAvatar session explicitly.

aclose() -> None

Method LiveAvatarClient.create_session_token

Create a LiveAvatar LITE session token.

Calls POST /v1/sessions on the LiveAvatar API, optionally embedding livekit_config so the avatar joins our LiveKit Cloud room.

create_session_token(cfg: LiveAvatarConfig, *, livekit_config: Optional[Dict[str, Any]] = None) -> AvatarSessionHandle

Parameter Type Default Description
cfg LiveAvatarConfig LiveAvatar configuration (api_key, avatar_id, …).
livekit_config Optional[Dict[str, Any]] None Optional LiveKit room config dict to pass to the API so the avatar joins our room (BYO transport).

Returns: AvatarSessionHandle — class:AvatarSessionHandle populated with the API response.

Raises:

  • aiohttp.ClientResponseError — On non-2xx responses.

Method LiveAvatarClient.create_full_session_token

Create a LiveAvatar FULL mode session token (restricted — no LLM, no context).

Sends mode: "FULL" with avatar_persona (voice_id, language), interactivity_type, video_settings, and max_session_duration. Critically: llm_configuration_id and context_id are OMITTED so the avatar never auto-responds via its built-in LLM (Q1 confirmed by spike).

create_full_session_token(cfg: FullModeConfig) -> FullModeSessionHandle

Parameter Type Default Description
cfg FullModeConfig FULL mode configuration (voice_id, language, interactivity_type, plus all base LiveAvatarConfig fields).

Returns: FullModeSessionHandle — class:FullModeSessionHandle populated with session_id and session_token from the API. livekit_url and livekit_client_token are populated later by :meth:start_session.

Raises:

  • aiohttp.ClientResponseError — On non-2xx responses.

Method LiveAvatarClient.start_session

Start a previously created session.

Uses Authorization: Bearer <session_token> auth.

For :class:FullModeSessionHandle, the /start response carries livekit_url and livekit_client_token (not ws_url) — both are populated on the handle so the caller can return them to the browser.

start_session(handle: AvatarSessionHandle) -> Dict[str, Any]

Parameter Type Default Description
handle AvatarSessionHandle The session handle returned by :meth:create_session_token or :meth:create_full_session_token.

Returns: Dict[str, Any] — The raw API response dict.

Raises:

  • aiohttp.ClientResponseError — On non-2xx responses.

Method LiveAvatarClient.stop_session

Stop (close) an active session.

Idempotent: safe to call multiple times or after the session has already closed.

stop_session(handle: AvatarSessionHandle) -> None

Parameter Type Default Description
handle AvatarSessionHandle The session handle to stop.

Method LiveAvatarClient.keep_alive

Send a single HTTP keep-alive ping for the session.

Calls POST /v1/sessions/keep-alive with Bearer session_token auth, sending the session_id (UUID) in the body per KeepSessionAliveSchema.

TODO P7 — switch to WS session.keep_alive here if the WS

variant is chosen as the canonical keep-alive transport.

keep_alive(handle: AvatarSessionHandle) -> None

Parameter Type Default Description
handle AvatarSessionHandle The active session handle.

Raises:

  • aiohttp.ClientResponseError — On a fatal 4xx (the session is no longer keep-alive-able — expired/ended/invalid). The caller (the keep-alive loop) uses this to stop pinging a dead session. Transient errors (network / 5xx) are logged and swallowed.

Method LiveAvatarClient.list_avatars

List available avatars (stock + user-uploaded).

Calls GET /v1/avatars with X-API-KEY auth.

list_avatars(cfg: LiveAvatarConfig) -> List[Dict[str, Any]]

Parameter Type Default Description
cfg LiveAvatarConfig LiveAvatar configuration (provides api_key and base_url).

Returns: List[Dict[str, Any]] — List of avatar dicts from the LiveAvatar API.

Raises:

  • aiohttp.ClientResponseError — On non-2xx responses.

Method LiveAvatarClient.list_voices

List available voices.

Calls GET /v1/voices with X-API-KEY auth.

list_voices(cfg: LiveAvatarConfig) -> List[Dict[str, Any]]

Parameter Type Default Description
cfg LiveAvatarConfig LiveAvatar configuration (provides api_key and base_url).

Returns: List[Dict[str, Any]] — List of voice dicts from the LiveAvatar API.

Raises:

  • aiohttp.ClientResponseError — On non-2xx responses.

Method LiveAvatarClient.get_session_transcript

Retrieve the server-side transcript for a completed session.

Calls GET /v1/sessions/{session_id}/transcript with X-API-KEY auth.

get_session_transcript(cfg: LiveAvatarConfig, session_id: str) -> Dict[str, Any]

Parameter Type Default Description
cfg LiveAvatarConfig LiveAvatar configuration (provides api_key and base_url).
session_id str LiveAvatar session ID (liveavatar_session_id on the handle).

Returns: Dict[str, Any] — Transcript dict from the LiveAvatar API.

Raises:

  • aiohttp.ClientResponseError — On non-2xx responses.

Alias LiveAvatarConfig

Re-exported from parrot.integrations.liveavatar.models.LiveAvatarConfig.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally