ai-video-gen

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Video Generation (HeyGen API)

视频生成(HeyGen API)

Generate AI videos from text prompts. Supports multiple providers (VEO 3.1, Kling, Sora, Runway, Seedance), configurable aspect ratios, and optional reference images for image-to-video generation.
通过文本提示词生成AI视频。支持多个提供商(VEO 3.1、Kling、Sora、Runway、Seedance)、可配置的宽高比,以及用于图生视频的可选参考图片。

Authentication

认证

All requests require the
X-Api-Key
header. Set the
HEYGEN_API_KEY
environment variable.
bash
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"workflow_type": "GenerateVideoNode", "input": {"prompt": "A drone shot flying over a coastal city at sunset"}}'
所有请求都需要携带
X-Api-Key
请求头。请设置
HEYGEN_API_KEY
环境变量。
bash
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"workflow_type": "GenerateVideoNode", "input": {"prompt": "A drone shot flying over a coastal city at sunset"}}'

Default Workflow

默认工作流

  1. Call
    POST /v1/workflows/executions
    with
    workflow_type: "GenerateVideoNode"
    and your prompt
  2. Receive a
    execution_id
    in the response
  3. Poll
    GET /v1/workflows/executions/{id}
    every 10 seconds until status is
    completed
  4. Use the returned
    video_url
    from the output
  1. 调用
    POST /v1/workflows/executions
    ,携带
    workflow_type: "GenerateVideoNode"
    和你的提示词
  2. 在响应中获取
    execution_id
  3. 每10秒轮询一次
    GET /v1/workflows/executions/{id}
    ,直到状态变为
    completed
  4. 使用返回结果中的
    video_url

Execute Video Generation

执行视频生成

Endpoint

端点

POST https://api.heygen.com/v1/workflows/executions
POST https://api.heygen.com/v1/workflows/executions

Request Fields

请求字段

FieldTypeReqDescription
workflow_type
stringYMust be
"GenerateVideoNode"
input.prompt
stringYText description of the video to generate
input.provider
stringVideo generation provider (default:
"veo_3_1"
). See Providers below.
input.aspect_ratio
stringAspect ratio (default:
"16:9"
). Common values:
"16:9"
,
"9:16"
,
"1:1"
input.reference_image_url
stringReference image URL for image-to-video generation
input.tail_image_url
stringTail image URL for last-frame guidance
input.config
objectProvider-specific configuration overrides
字段类型必填描述
workflow_type
string必须为
"GenerateVideoNode"
input.prompt
string要生成的视频的文本描述
input.provider
string视频生成提供商(默认值:
"veo_3_1"
)。详见下方提供商列表。
input.aspect_ratio
string宽高比(默认值:
"16:9"
)。常用值:
"16:9"
"9:16"
"1:1"
input.reference_image_url
string用于图生视频的参考图片URL
input.tail_image_url
string用于最后一帧引导的尾部图片URL
input.config
object提供商特定的配置覆盖参数

Providers

提供商

ProviderValueDescription
VEO 3.1
"veo_3_1"
Google VEO 3.1 (default, highest quality)
VEO 3.1 Fast
"veo_3_1_fast"
Faster VEO 3.1 variant
VEO 3
"veo3"
Google VEO 3
VEO 3 Fast
"veo3_fast"
Faster VEO 3 variant
VEO 2
"veo2"
Google VEO 2
Kling Pro
"kling_pro"
Kling Pro model
Kling V2
"kling_v2"
Kling V2 model
Sora V2
"sora_v2"
OpenAI Sora V2
Sora V2 Pro
"sora_v2_pro"
OpenAI Sora V2 Pro
Runway Gen-4
"runway_gen4"
Runway Gen-4
Seedance Lite
"seedance_lite"
Seedance Lite
Seedance Pro
"seedance_pro"
Seedance Pro
LTX Distilled
"ltx_distilled"
LTX Distilled (fastest)
提供商描述
VEO 3.1
"veo_3_1"
Google VEO 3.1(默认,质量最高)
VEO 3.1 Fast
"veo_3_1_fast"
更快的VEO 3.1变体
VEO 3
"veo3"
Google VEO 3
VEO 3 Fast
"veo3_fast"
更快的VEO 3变体
VEO 2
"veo2"
Google VEO 2
Kling Pro
"kling_pro"
Kling Pro模型
Kling V2
"kling_v2"
Kling V2模型
Sora V2
"sora_v2"
OpenAI Sora V2
Sora V2 Pro
"sora_v2_pro"
OpenAI Sora V2 Pro
Runway Gen-4
"runway_gen4"
Runway Gen-4
Seedance Lite
"seedance_lite"
Seedance Lite
Seedance Pro
"seedance_pro"
Seedance Pro
LTX Distilled
"ltx_distilled"
LTX Distilled(速度最快)

curl

curl示例

bash
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_type": "GenerateVideoNode",
    "input": {
      "prompt": "A drone shot flying over a coastal city at golden hour, cinematic lighting",
      "provider": "veo_3_1",
      "aspect_ratio": "16:9"
    }
  }'
bash
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_type": "GenerateVideoNode",
    "input": {
      "prompt": "A drone shot flying over a coastal city at golden hour, cinematic lighting",
      "provider": "veo_3_1",
      "aspect_ratio": "16:9"
    }
  }'

TypeScript

TypeScript示例

typescript
interface GenerateVideoInput {
  prompt: string;
  provider?: string;
  aspect_ratio?: string;
  reference_image_url?: string;
  tail_image_url?: string;
  config?: Record<string, any>;
}

interface ExecuteResponse {
  data: {
    execution_id: string;
    status: "submitted";
  };
}

async function generateVideo(input: GenerateVideoInput): Promise<string> {
  const response = await fetch("https://api.heygen.com/v1/workflows/executions", {
    method: "POST",
    headers: {
      "X-Api-Key": process.env.HEYGEN_API_KEY!,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      workflow_type: "GenerateVideoNode",
      input,
    }),
  });

  const json: ExecuteResponse = await response.json();
  return json.data.execution_id;
}
typescript
interface GenerateVideoInput {
  prompt: string;
  provider?: string;
  aspect_ratio?: string;
  reference_image_url?: string;
  tail_image_url?: string;
  config?: Record<string, any>;
}

interface ExecuteResponse {
  data: {
    execution_id: string;
    status: "submitted";
  };
}

async function generateVideo(input: GenerateVideoInput): Promise<string> {
  const response = await fetch("https://api.heygen.com/v1/workflows/executions", {
    method: "POST",
    headers: {
      "X-Api-Key": process.env.HEYGEN_API_KEY!,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      workflow_type: "GenerateVideoNode",
      input,
    }),
  });

  const json: ExecuteResponse = await response.json();
  return json.data.execution_id;
}

Python

Python示例

python
import requests
import os

def generate_video(
    prompt: str,
    provider: str = "veo_3_1",
    aspect_ratio: str = "16:9",
    reference_image_url: str | None = None,
    tail_image_url: str | None = None,
) -> str:
    payload = {
        "workflow_type": "GenerateVideoNode",
        "input": {
            "prompt": prompt,
            "provider": provider,
            "aspect_ratio": aspect_ratio,
        },
    }

    if reference_image_url:
        payload["input"]["reference_image_url"] = reference_image_url
    if tail_image_url:
        payload["input"]["tail_image_url"] = tail_image_url

    response = requests.post(
        "https://api.heygen.com/v1/workflows/executions",
        headers={
            "X-Api-Key": os.environ["HEYGEN_API_KEY"],
            "Content-Type": "application/json",
        },
        json=payload,
    )

    data = response.json()
    return data["data"]["execution_id"]
python
import requests
import os

def generate_video(
    prompt: str,
    provider: str = "veo_3_1",
    aspect_ratio: str = "16:9",
    reference_image_url: str | None = None,
    tail_image_url: str | None = None,
) -> str:
    payload = {
        "workflow_type": "GenerateVideoNode",
        "input": {
            "prompt": prompt,
            "provider": provider,
            "aspect_ratio": aspect_ratio,
        },
    }

    if reference_image_url:
        payload["input"]["reference_image_url"] = reference_image_url
    if tail_image_url:
        payload["input"]["tail_image_url"] = tail_image_url

    response = requests.post(
        "https://api.heygen.com/v1/workflows/executions",
        headers={
            "X-Api-Key": os.environ["HEYGEN_API_KEY"],
            "Content-Type": "application/json",
        },
        json=payload,
    )

    data = response.json()
    return data["data"]["execution_id"]

Response Format

响应格式

json
{
  "data": {
    "execution_id": "node-gw-v1d2e3o4",
    "status": "submitted"
  }
}
json
{
  "data": {
    "execution_id": "node-gw-v1d2e3o4",
    "status": "submitted"
  }
}

Check Status

检查状态

Endpoint

端点

GET https://api.heygen.com/v1/workflows/executions/{execution_id}
GET https://api.heygen.com/v1/workflows/executions/{execution_id}

curl

curl示例

bash
curl -X GET "https://api.heygen.com/v1/workflows/executions/node-gw-v1d2e3o4" \
  -H "X-Api-Key: $HEYGEN_API_KEY"
bash
curl -X GET "https://api.heygen.com/v1/workflows/executions/node-gw-v1d2e3o4" \
  -H "X-Api-Key: $HEYGEN_API_KEY"

Response Format (Completed)

完成状态下的响应格式

json
{
  "data": {
    "execution_id": "node-gw-v1d2e3o4",
    "status": "completed",
    "output": {
      "video": {
        "video_url": "https://resource.heygen.ai/generated/video.mp4",
        "video_id": "abc123"
      },
      "asset_id": "asset-xyz789"
    }
  }
}
json
{
  "data": {
    "execution_id": "node-gw-v1d2e3o4",
    "status": "completed",
    "output": {
      "video": {
        "video_url": "https://resource.heygen.ai/generated/video.mp4",
        "video_id": "abc123"
      },
      "asset_id": "asset-xyz789"
    }
  }
}

Polling for Completion

轮询等待完成

typescript
async function generateVideoAndWait(
  input: GenerateVideoInput,
  maxWaitMs = 600000,
  pollIntervalMs = 10000
): Promise<{ video_url: string; video_id: string; asset_id: string }> {
  const executionId = await generateVideo(input);
  console.log(`Submitted video generation: ${executionId}`);

  const startTime = Date.now();
  while (Date.now() - startTime < maxWaitMs) {
    const response = await fetch(
      `https://api.heygen.com/v1/workflows/executions/${executionId}`,
      { headers: { "X-Api-Key": process.env.HEYGEN_API_KEY! } }
    );
    const { data } = await response.json();

    switch (data.status) {
      case "completed":
        return {
          video_url: data.output.video.video_url,
          video_id: data.output.video.video_id,
          asset_id: data.output.asset_id,
        };
      case "failed":
        throw new Error(data.error?.message || "Video generation failed");
      case "not_found":
        throw new Error("Workflow not found");
      default:
        await new Promise((r) => setTimeout(r, pollIntervalMs));
    }
  }

  throw new Error("Video generation timed out");
}
typescript
async function generateVideoAndWait(
  input: GenerateVideoInput,
  maxWaitMs = 600000,
  pollIntervalMs = 10000
): Promise<{ video_url: string; video_id: string; asset_id: string }> {
  const executionId = await generateVideo(input);
  console.log(`Submitted video generation: ${executionId}`);

  const startTime = Date.now();
  while (Date.now() - startTime < maxWaitMs) {
    const response = await fetch(
      `https://api.heygen.com/v1/workflows/executions/${executionId}`,
      { headers: { "X-Api-Key": process.env.HEYGEN_API_KEY! } }
    );
    const { data } = await response.json();

    switch (data.status) {
      case "completed":
        return {
          video_url: data.output.video.video_url,
          video_id: data.output.video.video_id,
          asset_id: data.output.asset_id,
        };
      case "failed":
        throw new Error(data.error?.message || "Video generation failed");
      case "not_found":
        throw new Error("Workflow not found");
      default:
        await new Promise((r) => setTimeout(r, pollIntervalMs));
    }
  }

  throw new Error("Video generation timed out");
}

Usage Examples

使用示例

Simple Text-to-Video

简单文本转视频

bash
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_type": "GenerateVideoNode",
    "input": {
      "prompt": "A person walking through a sunlit park, shallow depth of field"
    }
  }'
bash
curl -X POST "https://api.heygen.com/v1/workflows/executions" \
  -H "X-Api-Key: $HEYGEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "workflow_type": "GenerateVideoNode",
    "input": {
      "prompt": "A person walking through a sunlit park, shallow depth of field"
    }
  }'

Image-to-Video

图生视频

json
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "Animate this product photo with a slow zoom and soft particle effects",
    "reference_image_url": "https://example.com/product-photo.png",
    "provider": "kling_pro"
  }
}
json
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "Animate this product photo with a slow zoom and soft particle effects",
    "reference_image_url": "https://example.com/product-photo.png",
    "provider": "kling_pro"
  }
}

Vertical Format for Social Media

社交媒体竖版格式

json
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "A trendy coffee shop interior, camera slowly panning across the counter",
    "aspect_ratio": "9:16",
    "provider": "veo_3_1"
  }
}
json
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "A trendy coffee shop interior, camera slowly panning across the counter",
    "aspect_ratio": "9:16",
    "provider": "veo_3_1"
  }
}

Fast Generation with LTX

使用LTX快速生成

json
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "Abstract colorful shapes morphing and flowing",
    "provider": "ltx_distilled"
  }
}
json
{
  "workflow_type": "GenerateVideoNode",
  "input": {
    "prompt": "Abstract colorful shapes morphing and flowing",
    "provider": "ltx_distilled"
  }
}

Best Practices

最佳实践

  1. Be descriptive in prompts — include camera movement, lighting, style, and mood details
  2. Default to VEO 3.1 for highest quality; use
    ltx_distilled
    or
    veo3_fast
    when speed matters
  3. Use reference images for image-to-video generation — great for animating product photos or still images
  4. Video generation is the slowest workflow — allow up to 5 minutes, poll every 10 seconds
  5. Aspect ratio matters — use
    9:16
    for social media stories/reels,
    16:9
    for landscape,
    1:1
    for square
  6. Output includes
    asset_id
    — use this to reference the generated video in other HeyGen workflows
  7. Output URLs are temporary — download or save generated videos promptly
  1. 提示词要详细 — 包含镜头运动、光线、风格和氛围细节
  2. 默认使用VEO 3.1以获得最高质量;当注重速度时,使用
    ltx_distilled
    veo3_fast
  3. 使用参考图片进行图生视频 — 非常适合为产品照片或静态图片添加动画
  4. 视频生成是最慢的工作流 — 允许最长5分钟的等待时间,每10秒轮询一次
  5. 宽高比很重要 — 社交媒体故事/短视频使用
    9:16
    ,横屏使用
    16:9
    ,方形使用
    1:1
  6. 输出包含
    asset_id
    — 使用该ID在其他HeyGen工作流中引用生成的视频
  7. 输出URL是临时的 — 请及时下载或保存生成的视频