🚀 快速安装
复制以下命令并运行,立即安装此 Skill:
npx skills add https://skills.sh/heygen-com/skills/ai-video-gen
💡 提示:需要 Node.js 和 NPM
视频生成 (HeyGen API)
根据文本提示生成 AI 视频。支持多种提供商(VEO 3.1、Kling、Sora、Runway、Seedance),可配置宽高比,并支持可选的参考图像用于图像到视频的生成。
身份验证
所有请求都需要 X-Api-Key 请求头。设置 HEYGEN_API_KEY 环境变量。
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": "无人机拍摄日落时分的沿海城市"}}'
默认工作流程
- 使用
workflow_type: "GenerateVideoNode"和你的提示词调用POST /v1/workflows/executions - 在响应中获取
execution_id - 每 10 秒轮询
GET /v1/workflows/executions/{id},直到状态变为completed - 从输出中获取返回的
video_url
执行视频生成
端点
POST https://api.heygen.com/v1/workflows/executions
请求字段
| 字段 | 类型 | 必需 | 描述 |
|---|---|---|---|
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 | 提供商特定的配置覆盖 |
提供商
| 提供商 | 值 | 描述 |
|---|---|---|
| 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 -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": "无人机拍摄日落黄金时刻的沿海城市,电影级照明",
"provider": "veo_3_1",
"aspect_ratio": "16:9"
}
}'
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
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"]
响应格式
{
"data": {
"execution_id": "node-gw-v1d2e3o4",
"status": "submitted"
}
}
检查状态
端点
GET https://api.heygen.com/v1/workflows/executions/{execution_id}
curl
curl -X GET "https://api.heygen.com/v1/workflows/executions/node-gw-v1d2e3o4" \
-H "X-Api-Key: $HEYGEN_API_KEY"
响应格式(完成)
{
"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"
}
}
}
轮询完成
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(`已提交视频生成:${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 || "视频生成失败");
case "not_found":
throw new Error("工作流未找到");
default:
await new Promise((r) => setTimeout(r, pollIntervalMs));
}
}
throw new Error("视频生成超时");
}
使用示例
简单文本生成视频
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": "一个人在阳光明媚的公园里行走,浅景深"
}
}'
图像生成视频
{
"workflow_type": "GenerateVideoNode",
"input": {
"prompt": "让这张产品照片动起来,缓慢推近并添加柔和粒子效果",
"reference_image_url": "https://example.com/product-photo.png",
"provider": "kling_pro"
}
}
社交媒体竖版格式
{
"workflow_type": "GenerateVideoNode",
"input": {
"prompt": "时尚咖啡店室内,镜头缓慢划过吧台",
"aspect_ratio": "9:16",
"provider": "veo_3_1"
}
}
使用 LTX 快速生成
{
"workflow_type": "GenerateVideoNode",
"input": {
"prompt": "抽象彩色形状流动变形",
"provider": "ltx_distilled"
}
}
最佳实践
- 提示词要描述详细 — 包含相机运动、光线、风格和氛围细节
- 默认使用 VEO 3.1 以获得最高质量;当速度重要时使用
ltx_distilled或veo3_fast - 使用参考图像 进行图像到视频生成 — 非常适合动画化产品照片或静态图像
- 视频生成是最慢的工作流 — 最多允许 5 分钟,每 10 秒轮询一次
- 宽高比很重要 — 社交媒体故事/短视频使用
9:16,横屏使用16:9,正方形使用1:1 - 输出包含
asset_id— 在 HeyGen 的其他工作流中使用此 ID 引用生成的视频 - 输出 URL 是临时的 — 及时下载或保存生成的视频
📄 原始文档
完整文档(英文):
https://skills.sh/heygen-com/skills/ai-video-gen
💡 提示:点击上方链接查看 skills.sh 原始英文文档,方便对照翻译。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)