Skip to content

feat: Add HeyGen AI video generation tool for PraisonAI agents #1180

Description

@MervinPraison

Description

Add a HeyGen video generation tool so PraisonAI agents can create AI avatar videos programmatically. HeyGen is the leading AI video platform for generating photorealistic talking-head avatar videos from text scripts.

Use Cases

  • Content automation: Agents generate marketing/explainer videos from text
  • Multi-agent pipelines: Research agent → Script agent → HeyGen video agent
  • Personalized outreach: Agents create personalized video messages at scale

HeyGen API Reference

Endpoints Required

Action Method Endpoint
List Avatars GET https://api.heygen.com/v2/avatars
List Voices GET https://api.heygen.com/v2/voices
Generate Video POST https://api.heygen.com/v2/video/generate
Check Status GET https://api.heygen.com/v1/video_status.get?video_id={id}

Auth

Header: x-api-key: <HEYGEN_API_KEY>

Generate Video Request Body

{
  "title": "My Video",
  "video_inputs": [
    {
      "character": {
        "type": "avatar",
        "avatar_id": "YOUR_AVATAR_ID"
      },
      "voice": {
        "type": "text_to_speech",
        "voice_id": "YOUR_VOICE_ID",
        "input_text": "Hello, this is generated by HeyGen API."
      }
    }
  ],
  "dimension": { "width": 1920, "height": 1080 }
}

Key Details

  • Async: Returns video_id immediately, poll status endpoint until completed
  • Avatar IV: Latest model — use use_avatar_iv_model: true for photorealistic quality
  • Credits: ~1 credit/min standard, ~6 credits/min Avatar IV
  • Limits: 5000 chars per script, 1-50 scenes per video
  • Webhook: Optional callback_url for completion notification

Implementation Requirements

Tool Functions (using @tool decorator pattern)

from praisonaiagents import Agent, tool

@tool
def heygen_list_avatars() -> list:
    """List available HeyGen avatars with their IDs."""

@tool
def heygen_list_voices() -> list:
    """List available HeyGen voices with their IDs."""

@tool
def heygen_generate_video(
    script: str,
    avatar_id: str = "default",
    voice_id: str = "default",
    title: str = "Generated Video",
    width: int = 1920,
    height: int = 1080
) -> dict:
    """Generate an AI avatar video from a text script using HeyGen."""

@tool
def heygen_video_status(video_id: str) -> dict:
    """Check the status of a HeyGen video generation and return download URL when ready."""

Agent Usage Example

from praisonaiagents import Agent
from praisonai_tools import heygen_generate_video, heygen_list_avatars, heygen_list_voices, heygen_video_status

agent = Agent(
    name="Video Creator",
    instructions="You create professional AI avatar videos using HeyGen.",
    tools=[heygen_list_avatars, heygen_list_voices, heygen_generate_video, heygen_video_status]
)

result = agent.start("Create a 30-second explainer video about PraisonAI multi-agent framework")
print(result)

Reference Pattern

Follow the existing LumaLabsTool pattern in praisonai_tools/tools/lumalabs_tool.py:

  • Lazy imports (import requests inside functions)
  • Environment variable: HEYGEN_API_KEY
  • All parameters as function arguments (agent-discoverable)
  • Proper error handling with descriptive messages
  • Both class-based (HeyGenTool) and functional (@tool) interfaces

Location

  • Tool implementation: praisonai_tools/tools/heygen_tool.py
  • Export from: praisonai_tools/__init__.py

Environment Variables

  • HEYGEN_API_KEY — Required, from HeyGen dashboard Settings > API

Acceptance Criteria

  • heygen_list_avatars() returns available avatars
  • heygen_list_voices() returns available voices
  • heygen_generate_video(script, avatar_id, voice_id) creates a video and returns video_id
  • heygen_video_status(video_id) returns status and download URL when complete
  • Agent can autonomously: list avatars → pick one → generate video → poll until ready → return URL
  • Follows lazy import pattern (no module-level import requests)
  • All options exposed as function parameters (not env vars)
  • Works with @tool decorator for simple usage

Metadata

Metadata

Assignees

No one assigned

    Labels

    claudeAuto-trigger Claude analysisenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions