跳到主要內容
API 參考
API 參考

HeyGen Video 文字轉影片

根據文字生成帶有聲音的 5 至 15 秒影片,可選擇用參考影象、影片或音訊引導。

01

概覽

使用文字轉影片端點搭配支援的模型。使用回傳的 Task ID 擷取其狀態,或提供 callback_url 以接收下方說明的回呼通知。

快速入門

  1. 建立 API 金鑰並將其設定為 RUNAPI_API_KEY。
  2. 選擇支援的模型,並傳送本文符合該模型結構描述的 POST 請求。
  3. 儲存返回的任務 ID,然後輪詢直到終止狀態,或處理下方說明的回呼。

端點

POST /api/v1/heygen_video/text_to_video
基礎 URL
https://runapi.ai
API 版本
v1
身分驗證
Authorization: Bearer YOUR_API_TOKEN
02

支援的模型

開啟模型頁面以查看目前的定價、速率限制及商業用途詳情。

03

請求綱要

JSON 請求內文

欄位及允許值取決於所選模型。若提供 callback_url,其將接收下方記錄的 Task 交付內容。

heygen-video-110 個欄位
aspect_ratiostring
選填

生成影片的長寬比;adaptive 會跟隨第一張參考圖片或影片,僅在 480p 或 768p 且附帶參考媒體時可用。

允許的值: adaptive, 21:9, 16:9, 4:3, 1:1, 3:4, 9:16
callback_urlstring
選填

用於非同步通知的 Webhook URL。

duration_secondsinteger
選填

產生影片的時長(秒)。

允許的值: 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 預設值: 5
modelstring
必填

模型 slug。

output_resolutionstring
選填

生成影片的解析度;1080p 與 2k 僅支援 16:9 與 9:16。

允許的值: 480p, 768p, 1080p, 2k 預設值: 768p
promptstring
必填

描述場景、對白與聲音的影片生成提示詞。

範圍: 1 - 16000
reference_audio_urlsarray
選填

公開可存取的 HTTPS 參考音訊 URL,每個最大 32 MB;需要同時提供參考圖片或影片。

項目數上限: 3
reference_image_urlsarray
選填

公開可存取的 HTTPS 參考圖片 URL,每張最大 16 MB;圖片、影片與音訊合計最多 12 個參考檔案。

項目數上限: 9
reference_video_urlsarray
選填

公開可存取的 HTTPS 參考影片 URL,長寬比介於 1:4 與 4:1 之間,每個最大 32 MB;每段影片僅使用前 5 秒。

項目數上限: 3
seedinteger
選填

用於可重現生成的隨機種子。

範圍: 0 - 4294967295

條件規則

當所有列出的條件均符合時,這些需求即適用。

  1. 當 reference_audio_urls present
    必填
    不接受
  2. 當 reference_image_urls absent, reference_video_urls absent
    必填
    不接受
  3. 當 output_resolution = 1080p
    必填
    不接受
  4. 當 output_resolution = 2k
    必填
    不接受
04

建立接受記錄

HTTP 202

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "processing"
      ],
      "type": "string"
    },
    "task_replayed": {
      "type": "boolean"
    }
  },
  "required": [
    "id",
    "status"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "id": "tsk_reference_demo",
  "status": "processing"
}
05

輪詢處理中

HTTP 200

GET /api/v1/heygen_video/text_to_video/:id

回應綱要
JSON
{
  "properties": {
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "processing"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "id": "tsk_reference_demo",
  "status": "processing"
}
06

輪詢已完成

HTTP 200

GET /api/v1/heygen_video/text_to_video/:id

回應綱要
JSON
{
  "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
}

回應範例

JSON
{
  "id": "tsk_reference_demo",
  "status": "completed",
  "usage": {
    "cost": 0.05
  },
  "videos": [
    {
      "url": "https://file.runapi.ai/reference-video.mp4"
    }
  ]
}
07

輪詢失敗

HTTP 200

GET /api/v1/heygen_video/text_to_video/:id

回應綱要
JSON
{
  "properties": {
    "error": {
      "type": "string"
    },
    "id": {
      "type": "string"
    },
    "status": {
      "enum": [
        "failed"
      ],
      "type": "string"
    }
  },
  "required": [
    "id",
    "status",
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Task processing failed.",
  "id": "tsk_reference_demo",
  "status": "failed"
}
08

客戶回呼:已完成

HTTP 200

POST callback_url

回應綱要
JSON
{
  "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
}

回應範例

JSON
{
  "id": "tsk_reference_demo",
  "status": "completed",
  "usage": {
    "cost": 0.05
  },
  "videos": [
    {
      "url": "https://file.runapi.ai/reference-video.mp4"
    }
  ]
}
09

客戶回呼:失敗

HTTP 200

POST callback_url

回應綱要
JSON
{
  "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
}

回應範例

JSON
{
  "error": {
    "code": "generation_failed",
    "message": "Task processing failed."
  },
  "id": "tsk_reference_demo",
  "status": "failed"
}
10

錯誤

HTTP 401

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Authentication required"
}
11

錯誤

HTTP 401

GET /api/v1/heygen_video/text_to_video/:id

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Authentication required"
}
12

錯誤

HTTP 400

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "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
    }
  ]
}

回應範例

JSON
{
  "error": "model must be one of: heygen-video-1"
}
13

錯誤

HTTP 402

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Insufficient balance"
}
14

錯誤

HTTP 429

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "API key credit limit exceeded"
}
15

錯誤

HTTP 409

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "The request uses features that are not supported for the selected model"
}
16

錯誤

HTTP 429

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Rate limit reached. Please retry later."
}
17

錯誤

HTTP 503

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Service under maintenance, please try again later"
}
18

錯誤

HTTP 504

POST /api/v1/heygen_video/text_to_video

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "The request timed out"
}
19

錯誤

HTTP 404

GET /api/v1/heygen_video/text_to_video/:id

回應綱要
JSON
{
  "properties": {
    "error": {
      "description": "人類可讀的錯誤訊息。",
      "type": "string"
    }
  },
  "required": [
    "error"
  ],
  "type": "object",
  "unevaluatedProperties": false
}

回應範例

JSON
{
  "error": "Task with id 'tsk_reference_demo' not found"
}
20

產生的程式碼範例

直接使用 cURL,或為您的程式語言安裝 SDK。每個範例均會提交本參考中所示的已驗證請求。

安裝

Shell
pip install runapi-heygen-video
PYTHON
import os
from runapi.heygen_video import HeyGenVideoClient

client = HeyGenVideoClient(api_key=os.environ["RUNAPI_API_KEY"])
task = client.text_to_video.create(
  model="heygen-video-1",
  prompt="A plant supervisor in a plain grey coat stands beside a conveyor line and speaks to camera.",
  aspect_ratio="16:9",
  output_resolution="768p"
)