H

Heygen Best Practices Engine

Battle-tested skill for best, practices, heygen, avatar. Includes structured workflows, validation checks, and reusable patterns for development.

SkillClipticsdevelopmentv1.0.0MIT
0 views0 copies

HeyGen API Best Practices Skill

A Claude Code skill for building AI avatar video applications with the HeyGen API — covering video generation, avatar management, template workflows, and real-time avatar streaming integration.

When to Use This Skill

Choose this skill when:

  • Creating AI avatar videos programmatically via the HeyGen API
  • Managing avatars, voices, and video templates
  • Building automated video generation pipelines
  • Integrating real-time avatar streaming into applications
  • Generating personalized video content at scale

Consider alternatives when:

  • You need general video editing (use FFmpeg or a video editor)
  • You need text-to-speech only without avatars (use a TTS API)
  • You need live video conferencing (use WebRTC tools)

Quick Start

# Set up HeyGen API access export HEYGEN_API_KEY="your-api-key" # Install HTTP client npm install axios
import axios from 'axios'; const heygen = axios.create({ baseURL: 'https://api.heygen.com/v2', headers: { 'X-Api-Key': process.env.HEYGEN_API_KEY } }); // Generate a video with a talking avatar const { data } = await heygen.post('/video/generate', { video_inputs: [{ character: { type: 'avatar', avatar_id: 'Angela-inTshirt-20220820', avatar_style: 'normal' }, voice: { type: 'text', input_text: 'Welcome to our product demo!', voice_id: 'en-US-JennyNeural' } }], dimension: { width: 1920, height: 1080 } }); const videoId = data.data.video_id;

Core Concepts

Video Generation Pipeline

StepAPI EndpointPurpose
1. List AvatarsGET /avatarsGet available avatar IDs
2. List VoicesGET /voicesGet available voice IDs
3. GeneratePOST /video/generateCreate video with avatar and script
4. Poll StatusGET /video/{id}Check generation progress
5. DownloadGET /video/{id}Get completed video URL

Template-Based Generation

// Create videos from templates for batch personalization const { data } = await heygen.post('/template/generate', { template_id: 'template-abc123', variables: { customer_name: { value: 'Sarah' }, product_name: { value: 'CloudSync Pro' }, discount_code: { value: 'WELCOME20' } } });

Status Polling

async function waitForVideo(videoId: string): Promise<string> { while (true) { const { data } = await heygen.get(`/video/${videoId}`); if (data.data.status === 'completed') return data.data.video_url; if (data.data.status === 'failed') throw new Error('Video generation failed'); await new Promise(r => setTimeout(r, 10000)); // Poll every 10 seconds } }

Configuration

ParameterTypeDefaultDescription
avatar_idstring—Avatar identifier from the avatars list
voice_idstring—Voice identifier from the voices list
dimension.widthnumber1920Video width in pixels
dimension.heightnumber1080Video height in pixels
avatar_stylestring"normal"Avatar style: normal, circle, closeup
speednumber1.0Speech speed multiplier (0.5-2.0)
backgroundobject—Custom background color or image URL
testbooleanfalseGenerate watermarked test video (free)

Best Practices

  1. Use templates for batch personalization — instead of building each video from scratch, create a template with variable placeholders and generate personalized versions by swapping variable values.

  2. Poll status with exponential backoff — video generation takes 1-5 minutes; start polling at 10 seconds, increase to 30 seconds after 2 minutes to reduce API calls.

  3. Use test mode during development — set test: true to generate watermarked preview videos for free; switch to production mode only for final outputs.

  4. Cache avatar and voice lists — the avatar and voice catalogs change infrequently; cache these responses for 24 hours to avoid unnecessary API calls.

  5. Handle generation failures gracefully — video generation can fail due to content moderation, invalid inputs, or service issues; always check the status and implement retry logic with a maximum attempt count.

Common Issues

Video generation takes too long — Longer scripts and higher resolutions increase generation time. For faster iteration, use 720p resolution and shorter scripts during development. Full HD is only needed for final production renders.

Avatar lip sync doesn't match audio — This usually happens with unusual words, abbreviations, or non-English text in English voices. Use phonetic spelling for proper nouns and test with short clips before generating full videos.

API rate limits hit during batch generation — The API has per-minute rate limits. Implement a queue with controlled concurrency (2-3 parallel requests) and add delays between batches to stay within limits.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates