HeyGen Video 圖像轉影片
將首幀圖像製成帶有生成聲音的 5 至 15 秒視頻,最高支持 2K。
概覽
使用圖像轉影片端點配合受支援的模型。使用返回的任務 ID 來檢索其狀態,或提供 callback_url 以接收以下記錄的推送通知。
快速入門
- 建立 API 金鑰並將其設定為 RUNAPI_API_KEY。
- 選擇支援的模型,並發送主體符合該模型結構的 POST 請求。
- 儲存返回的任務 ID,然後輪詢直至達到終止狀態,或處理下方說明的回呼。
端點
- 基礎 URL
https://runapi.ai- API 版本
v1- 身份驗證
Authorization: Bearer YOUR_API_TOKEN
支援的模型
開啟模型頁面以查看當前定價、速率限制及商業用途詳情。
請求結構
欄位及允許的值取決於所選模型。提供後,callback_url 將接收以下記錄的 Task 交付內容。
heygen-video-17 個欄位
callback_urlstring用於非同步通知的 Webhook URL。
duration_secondsinteger生成視頻的時長(秒)。
允許值:5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
預設值: 5
first_frame_image_urlstring公開可存取的 HTTPS 首幀圖片 URL,最大 16 MB;影片沿用圖片的長寬比。
modelstring模型標識符。
output_resolutionstring生成視頻的解析度。
允許值:480p, 768p, 1080p, 2k
預設值: 768p
promptstring描述場景、對白與聲音的影片生成提示詞。
範圍:1 - 16000
seedinteger用於可重現生成的隨機種子。
範圍:0 - 4294967295
建立接受
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
},
"task_replayed": {
"type": "boolean"
}
},
"required": [
"id",
"status"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"id": "tsk_reference_demo",
"status": "processing"
}
輪詢處理中
GET /api/v1/heygen_video/image_to_video/:id
回應結構
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
}
},
"required": [
"id",
"status"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"id": "tsk_reference_demo",
"status": "processing"
}
輪詢已完成
GET /api/v1/heygen_video/image_to_video/:id
回應結構
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"completed"
],
"type": "string"
},
"usage": {
"properties": {
"cost": {
"type": "number"
}
},
"required": [
"cost"
],
"type": "object",
"unevaluatedProperties": false
},
"videos": {
"items": {
"properties": {
"url": {
"type": "string",
"x-runapi-generated-media": true
}
},
"required": [
"url"
],
"type": "object",
"unevaluatedProperties": false
},
"type": "array"
}
},
"required": [
"id",
"status",
"videos",
"usage"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"id": "tsk_reference_demo",
"status": "completed",
"usage": {
"cost": 0.05
},
"videos": [
{
"url": "https://file.runapi.ai/reference-video.mp4"
}
]
}
輪詢失敗
GET /api/v1/heygen_video/image_to_video/:id
回應結構
{
"properties": {
"error": {
"type": "string"
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Task processing failed.",
"id": "tsk_reference_demo",
"status": "failed"
}
客戶回呼:已完成
POST callback_url
回應結構
{
"properties": {
"id": {
"type": "string"
},
"status": {
"enum": [
"completed"
],
"type": "string"
},
"usage": {
"properties": {
"cost": {
"type": "number"
}
},
"required": [
"cost"
],
"type": "object",
"unevaluatedProperties": false
},
"videos": {
"items": {
"properties": {
"url": {
"type": "string",
"x-runapi-generated-media": true
}
},
"required": [
"url"
],
"type": "object",
"unevaluatedProperties": false
},
"type": "array"
}
},
"required": [
"id",
"status",
"videos",
"usage"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"id": "tsk_reference_demo",
"status": "completed",
"usage": {
"cost": 0.05
},
"videos": [
{
"url": "https://file.runapi.ai/reference-video.mp4"
}
]
}
客戶回呼:已失敗
POST callback_url
回應結構
{
"properties": {
"error": {
"oneOf": [
{
"type": "string"
},
{
"properties": {
"code": {
"type": "string"
},
"limit_cents": {
"type": "integer"
},
"message": {
"type": "string"
},
"reset_at": {
"format": "date-time",
"type": [
"string",
"null"
]
},
"used_cents": {
"type": "integer"
},
"window": {
"enum": [
"1h",
"1d",
"7d",
"daily",
"weekly",
"monthly",
"lifetime"
],
"type": "string"
}
},
"required": [
"code",
"message"
],
"type": "object",
"unevaluatedProperties": false
}
]
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": {
"code": "generation_failed",
"message": "Task processing failed."
},
"id": "tsk_reference_demo",
"status": "failed"
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Authentication required"
}
錯誤
GET /api/v1/heygen_video/image_to_video/:id
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Authentication required"
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"oneOf": [
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
},
{
"properties": {
"error": {
"description": "人類可讀的驗證摘要。",
"type": "string"
},
"errors": {
"additionalProperties": {
"items": {
"type": "string"
},
"type": "array"
},
"description": "以公開請求欄位為鍵的驗證訊息,每個欄位對應一組人類可讀的字串陣列。",
"type": "object"
}
},
"required": [
"error",
"errors"
],
"type": "object",
"unevaluatedProperties": false
}
]
}
回應範例
{
"error": "model must be one of: heygen-video-1"
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Insufficient balance"
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "API key credit limit exceeded"
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "The request uses features that are not supported for the selected model"
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Rate limit reached. Please retry later."
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Service under maintenance, please try again later"
}
錯誤
POST /api/v1/heygen_video/image_to_video
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "The request timed out"
}
錯誤
GET /api/v1/heygen_video/image_to_video/:id
回應結構
{
"properties": {
"error": {
"description": "人類可讀的錯誤訊息。",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
回應範例
{
"error": "Task with id 'tsk_reference_demo' not found"
}
已生成的程式碼範例
直接使用 cURL,或為您的語言安裝 SDK。每個範例均提交本參考中所示的已驗證請求。
安裝
pip install runapi-heygen-video
import os
from runapi.heygen_video import HeyGenVideoClient
client = HeyGenVideoClient(api_key=os.environ["RUNAPI_API_KEY"])
task = client.image_to_video.create(
model="heygen-video-1",
first_frame_image_url="https://cdn.runapi.ai/public/samples/image.jpg",
prompt="The subject turns toward the camera and says hello.",
output_resolution="768p"
)