Using Agent Framework with Heygen Managed LiveKit Credentials
Beta
This guide explains how to use HeyGen with managed LiveKit credentials. In this flow, your agent's backend orchestrates the session. It calls the HeyGen API, which automatically generates and returns two distinct tokens: a client token and an agent token.
- The agent token is used by your backend agent to connect to the LiveKit room.
- The client token is passed from your agent to your front-end application, allowing a user to join the same room.
Overview
HeyGen's managed LiveKit service simplifies your integration by handling all token generation automatically. The API provides the necessary tokens to join a room, including a dedicated token for your agent. This eliminates the need for you to write and maintain your own LiveKit token generation code, saving significant development time. 🚀
Workflow
In this model, your agent's backend manages the entire session creation process.
- The process begins on your backend when your agent decides to start an avatar session (e.g., in response to a client connecting to it).
- Your agent's backend calls the
/v1/streaming.new
endpoint without providing thelivekit_settings
parameter. - The HeyGen API responds directly to your backend with the session details, including:
url
– The LiveKit server URL.access_token
– The client token.livekit_agent_token
– The agent token.
- Your agent's backend then orchestrates the connections:
- It uses the
url
andlivekit_agent_token
to connect itself to the LiveKit room. - It passes the
url
andaccess_token
(the client token) down to the front-end client.
- It uses the
- The client uses the credentials it received from the agent to connect to the LiveKit room, where it can interact with the agent and the HeyGen avatar.
When to Use
You should use this managed flow if you want the simplest setup, where HeyGen handles all LiveKit configuration and token generation for you. This is the recommended path for most developers building interactive avatar experiences.
Updated about 2 hours ago