> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# HeyGen Video Avatar

> HeyGenVideoService drives HeyGen LiveAvatar interactive video avatars from your Pipecat agent's speech output.

## Overview

`HeyGenVideoService` integrates with HeyGen [LiveAvatar](https://www.liveavatar.com/) to create interactive AI-powered video avatars that respond naturally in real-time conversations. The service handles bidirectional audio/video streaming, avatar animations, voice activity detection, and conversation interruptions to deliver engaging conversational AI experiences with lifelike visual presence.

> [card] [HeyGen Video API Reference](https://reference-server.pipecat.ai/en/latest/api/pipecat.services.heygen.video.html)
>
> Pipecat's API methods for HeyGen video integration

> [card] [Example Implementation](https://github.com/pipecat-ai/pipecat/blob/main/examples/video-avatar/video-avatar-heygen-video-service.py)
>
> Complete example with interactive avatar

> [card] [HeyGen Documentation](https://docs.liveavatar.com/)
>
> Official HeyGen API documentation and guides

> [card] [HeyGen Platform](https://www.liveavatar.com/)
>
> Access interactive avatars and API keys

## Installation

To use HeyGen services, install the required dependency:

```bash theme={null}
uv add "pipecat-ai[heygen]"
```

## Prerequisites

### HeyGen Account Setup

Before using HeyGen video services, you need:

1. **HeyGen Account**: Sign up at [HeyGen Platform](https://app.liveavatar.com/signin)
2. **API Key**: Generate an API key from your account dashboard
3. **Avatar Selection**: Choose from available interactive avatars
4. **Streaming Setup**: Configure real-time avatar streaming capabilities

### Required Environment Variables

* `HEYGEN_LIVE_AVATAR_API_KEY`: Your HeyGen LiveAvatar API key for authentication

## Configuration

**api\_key** `str` *required*

HeyGen API key for authentication.

**session** `aiohttp.ClientSession` *required*

HTTP client session for API requests.

**session\_request** `LiveAvatarNewSessionRequest | NewSessionRequest` (default: None)

Configuration for the HeyGen session. When `None`, a default public avatar for
the service type is used. Use `LiveAvatarNewSessionRequest` with
`ServiceType.LIVE_AVATAR` and `NewSessionRequest` with
`ServiceType.INTERACTIVE_AVATAR`; when `service_type` is set, a request that
doesn't match it is ignored. See [LiveAvatar video
settings](#liveavatar-video-settings) for encoding and quality options.

**service\_type** `ServiceType` (default: None)

Service type for the avatar session: `ServiceType.LIVE_AVATAR` or
`ServiceType.INTERACTIVE_AVATAR`. `None` uses
`ServiceType.INTERACTIVE_AVATAR`, so set `ServiceType.LIVE_AVATAR` to use a
LiveAvatar API key.

**settings** `HeyGenVideoService.Settings` (default: None)

Runtime-configurable settings. HeyGen has no model-level settings, so this is
primarily used for the `extra` dict. See [Service
Settings](https://docs.pipecat.ai/pipecat/fundamentals/service-settings.md) for details.

### LiveAvatar Video Settings

`LiveAvatarNewSessionRequest.video_settings` controls the encoding and quality
of the avatar video stream. If you omit `video_settings`, Pipecat requests H264
encoding with high quality.

**video\_settings.encoding** `VideoEncoding` *required*

Video codec for the avatar stream. Use `VideoEncoding.H264` for new sessions.
`VideoEncoding.VP8` remains available temporarily but is deprecated by
LiveAvatar.

**video\_settings.quality** `VideoQuality` (default: VideoQuality.high)

Rendering quality for the avatar stream. Options are `low`, `medium`, `high`,
and `very_high`.

**max\_session\_duration** `int` (default: None)

Maximum session duration in seconds. The ceiling is set by the LiveAvatar
subscription tier, which also supplies the default when this is unset.

> [!WARNING]
>
> LiveAvatar has deprecated VP8. Applications that explicitly select
> `VideoEncoding.VP8` should migrate to `VideoEncoding.H264`.

## Usage

### Basic Setup

```python theme={null}
import os

import aiohttp
from pipecat.services.heygen.client import ServiceType
from pipecat.services.heygen.video import HeyGenVideoService

async with aiohttp.ClientSession() as session:
    heygen = HeyGenVideoService(
        api_key=os.getenv("HEYGEN_LIVE_AVATAR_API_KEY"),
        service_type=ServiceType.LIVE_AVATAR,
        session=session,
    )
```

### With Custom Session Request

```python theme={null}
from pipecat.services.heygen.api_liveavatar import (
    LiveAvatarNewSessionRequest,
    VideoEncoding,
    VideoSettings,
)

heygen = HeyGenVideoService(
    api_key=os.getenv("HEYGEN_LIVE_AVATAR_API_KEY"),
    service_type=ServiceType.LIVE_AVATAR,
    session=session,
    session_request=LiveAvatarNewSessionRequest(
        avatar_id="your_avatar_id",
        video_settings=VideoSettings(
            encoding=VideoEncoding.H264,
        ),
    ),
)
```

## Notes

* **Bidirectional streaming**: The service manages both sending audio to HeyGen and receiving avatar video/audio back through WebRTC.
* **Interruption handling**: When a user starts speaking, the service interrupts the avatar's current speech, cancels ongoing audio tasks, and activates the avatar's listening animation.
* **Metrics support**: The service supports TTFB metrics tracking using `TTSStartedFrame` and `BotStartedSpeakingFrame` signals.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.