关于 ai-video-gen
ai-video-gen 是通过 HeyGen API 从文本提示生成视频的技能,面向需要创建文本转视频或图像转视频内容的用户。它支持多种视频生成提供方、画幅比例和参考图像。
主要功能
- 01文本提示生成视频
- 02支持多种生成提供方
- 03可配置画幅比例
- 04支持参考图像与尾帧引导
- 05轮询任务状态并获取视频链接
适用场景
- 01根据文字描述制作视频
- 02将产品照片转换为动态视频
- 03生成适合社交媒体的竖屏视频
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ heygen-com/ skills --skill ai-video-gen安装后在 Claude Code 中输入/ai-video-gen确认已加载。
详细介绍
视频生成(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": "A drone shot flying over a coastal city at sunset"}}'
默认工作流
- 使用
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 | Y | 必须为 "GenerateVideoNode" |
input.prompt | string | Y | 要生成的视频的文本描述 |
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": "A drone shot flying over a coastal city at golden hour, cinematic lighting",
"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(`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");
}
使用示例
简单的文本转视频
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"
}
}'
图像转视频
{
"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"
}
}
适用于社交媒体的竖屏格式
{
"workflow_type": "GenerateVideoNode",
"input": {
"prompt": "A trendy coffee shop interior, camera slowly panning across the counter",
"aspect_ratio": "9:16",
"provider": "veo_3_1"
}
}
使用 LTX 快速生成
{
"workflow_type": "GenerateVideoNode",
"input": {
"prompt": "Abstract colorful shapes morphing and flowing",
"provider": "ltx_distilled"
}
}
最佳实践
- 在提示词中提供详细描述——包括镜头运动、光线、风格和情绪等细节
- 默认使用 VEO 3.1以获得最高质量;注重速度时使用
ltx_distilled或veo3_fast - 使用参考图像进行图像转视频生成——非常适合为产品照片或静态图像添加动画
- 视频生成是最慢的工作流——预留最多 5 分钟时间,每隔 10 秒轮询一次
- 宽高比很重要——社交媒体快拍/短视频使用
9:16,横向视频使用16:9,方形视频使用1:1 - 输出包含
asset_id——可用它在其他 HeyGen 工作流中引用生成的视频 - 输出 URL 是临时的——请及时下载或保存生成的视频
评论
支持 Markdown