Bring your own LiveKit agent
You already run a LiveKit Agents agent, with its own speech-to-text, LLM and voice. The Lookalike plugin gives it a face. It starts an external session: Lookalike's avatar joins your room as its own participant, animates a face to your agent's voice, and publishes the video and audio on behalf of your agent.
This is different from a managed session, where Lookalike creates the room and runs the agent for you. Here the room, the agent and its voice are yours.
What you need
- An API key. See Authentication. The plugin reads it from
LOOKALIKE_API_KEY. - Accepted avatar terms. Someone in your organization must accept the current version of the avatar terms on the Avatar sessions page of the Console. Until then a start is refused with
403(terms_not_accepted). - Your own LiveKit project and agent. You need the project's URL, API key and API secret. The URL must be a public
wss://address: the avatar joins your room from outside your network. - A balance, or included minutes left. See Billing.
- A face. An identity of yours with a ready avatar, or a photo.
- Python 3.11 or newer and
livekit-agents1.7.1 or newer, below 2, withlivekit-plugins-lookalike0.4.0 or newer. A TypeScript plugin with the same options is in the same repository.
Install
The plugin is in a private beta. Access comes with an invitation from the Lookalike team, and the invitation includes the install command. To ask for access, write to help@lookalike.com.
Add the face to your agent
Create an AvatarSession and start it before your agent session. The plugin reads these environment variables:
| Variable | Used for |
|---|---|
LIVEKIT_URL | The URL of your LiveKit project. An https:// URL is sent as wss://. |
LIVEKIT_API_KEY and LIVEKIT_API_SECRET | Signing the avatar's room token in your process. They are never sent to Lookalike. |
LOOKALIKE_API_KEY | Your Lookalike API key. |
LOOKALIKE_API_URL | Optional. Overrides the API address, https://api.lookalike.com by default. |
from livekit.agents import Agent, AgentSession, JobContext
from livekit.plugins import lookalike
async def entrypoint(ctx: JobContext) -> None:
await ctx.connect()
session = AgentSession(stt=..., llm=..., tts=...)
def on_avatar_error(error: lookalike.RendererError) -> None:
# Without its face the agent cannot be heard: its audio waits for the avatar's video
ctx.shutdown(reason=f"avatar_error:{error.code}")
avatar = lookalike.AvatarSession(identity_id="id_3f9a2b7c4d1e8a05f6b3", on_error=on_avatar_error)
await avatar.start(session, room=ctx.room)
await session.start(agent=Agent(instructions="You are a friendly assistant."), room=ctx.room)
The face is exactly one of identity_id, avatar_image_url (an https URL Lookalike fetches once) or avatar_image (a JPEG, PNG or WEBP you upload). A photo becomes one of your avatars; the same image is the same avatar.
start() mints a 15-minute token for the avatar participant, starts the session with POST /v1/sessions and returns its id. It does not wait for the avatar: your agent's audio is held until the avatar shows video, so the agent never speaks without its face.
After a quiet period the avatar can take a few minutes to appear while its renderer starts. If it has not joined after five and a half minutes, the plugin ends the session and calls on_error with start_timeout.
Errors
- A refused start raises LiveKit's
APIStatusError. Itsbodyis{"code", "message"}:insufficient_balance(402),terms_not_accepted(403),identity_not_ready(409),invalid_livekit_urlorinvalid_livekit_token(422),concurrency_limit(429) oravatar_unavailable(503). An unreachable API raisesAPIConnectionError. - A failure after the start ends the session and calls
on_erroronce with alookalike.RendererError. Itscodeis one of the session's error codes, such asstart_timeout,room_connect_failed,avatar_load_failed,agent_absent,billing_unavailableorrenderer_error, or a billing stop:insufficient_balance,allowance_exhaustedorspending_cap_reached. - Configuration problems raise
lookalike.LookalikeException: no API key, not exactly one face, missing LiveKit credentials, or a room that is not connected.
Limits
- 10 open sessions per organization. The next start is refused with
429(concurrency_limit). - 2 hours per session unless you pass a shorter
max_duration_seconds. The avatar then leaves and the session ends without an error. - One face per room. Start a new session for each room.
Billing
An external session is billed per second of delivered video at 120 credits a minute, after your plan's included seconds; see Billing and credits. Once video was delivered a session is billed at least 30 seconds. Starting one needs enough for those 30 seconds. If the balance runs out during a session, the avatar leaves and on_error gets insufficient_balance.
Ending a session
The session ends as soon as your agent session closes, for example when the user leaves. await avatar.aclose() ends it yourself (POST /v1/sessions/{id}/end) and removes the avatar from your room; inside a LiveKit job it also runs when the job shuts down. It is safe to call twice. The avatar leaves within about 15 seconds, and the seconds delivered until then are billed.