[ PROMPT_NODE_24868 ]
Heygen Best Practices 模板
[ SKILL_DOCUMENTATION ]
# 视频模板
HeyGen 模板允许您创建带有变量占位符的可重用视频结构,从而实现大规模的个性化视频生成。
## 列出模板
### curl
bash
curl -X GET "https://api.heygen.com/v2/templates"
-H "X-Api-Key: $HEYGEN_API_KEY"
### TypeScript
typescript
interface Template {
template_id: string;
name: string;
thumbnail_url: string;
variables: TemplateVariable[];
}
interface TemplateVariable {
name: string;
type: "text" | "image" | "audio";
properties?: {
max_length?: number;
default_value?: string;
};
}
interface TemplatesResponse {
error: null | string;
data: {
templates: Template[];
};
}
async function listTemplates(): Promise {
const response = await fetch("https://api.heygen.com/v2/templates", {
headers: { "X-Api-Key": process.env.HEYGEN_API_KEY! },
});
const json: TemplatesResponse = await response.json();
if (json.error) {
throw new Error(json.error);
}
return json.data.templates;
}
### Python
python
import requests
import os
def list_templates() -> list:
response = requests.get(
"https://api.heygen.com/v2/templates",
headers={"X-Api-Key": os.environ["HEYGEN_API_KEY"]}
)
data = response.json()
if data.get("error"):
raise Exception(data["error"])
return data["data"]["templates"]
## 响应格式
{
"error": null,
"data": {
"templates": [
{
"template_id": "template_abc123",
"name": "Product Announcement",
"thumbnail_url": "https://files.heygen.ai/...",
"variables": [
{
"name": "product_name",
"type": "text",
"properties": {
"max_length": 50
}
},
{
"name": "presenter_script",
"type": "text",
"properties": {
"max_length": 500
}
},
{
"name": "product_image",
"type": "image"
}
]
}
]
}
}
## 获取模板详情
### curl
bash
curl -X GET "https://api.heygen.com/v2/template/{template_id}"
-H "X-Api-Key: $HEYGEN_API_KEY"
### TypeScript
typescript
async function getTemplate(templateId: string): Promise {
const response = await fetch(
`https://api.heygen.com/v2/template/${templateId}`,
{ headers: { "X-Api-Key": process.env.HEYGEN_API_KEY! } }