Skip to Content
WikiAPI 文档视频生成

视频生成

根据文字、图片或参考视频生成视频。视频生成是异步接口:先创建任务,再轮询任务状态,完成后获取视频地址。

端点

创建任务:

POST https://gateway.mytokengate.com/v1/videos

查询任务:

GET https://gateway.mytokengate.com/v1/videos/{task_id}

认证

所有请求需要在 Authorization 头中包含 Bearer token:

Authorization: Bearer YOUR_API_KEY

支持的模型

平台提供四个系列的视频模型。协议是统一的:换模型只改 model 字段,素材放进 content,参数放进 parameters,其余写法完全一致。

模型形态支持分辨率
seedance-2.0文生视频 / 图生视频 / 视频生视频720p、1080p
seedance-2.0-fast文生视频 / 图生视频720p
seedance-2.0-mini文生视频 / 图生视频720p
wan-2-7-t2v文生视频720p、1080p
wan-2-7-i2v图生视频720p、1080p
happyhorse-1.1-t2v文生视频720p、1080p
happyhorse-1.1-i2v图生视频720p、1080p
happyhorse-1.1-r2v参考图生视频720p、1080p
happyhorse-1.0-video-edit视频编辑720p、1080p
kling-o3-standard文生视频720p
kling-o3-standard-reference参考图生视频720p
kling-o3-standard-v2v视频生视频720p
kling-o3-standard-video-edit视频编辑720p
kling-o3-pro-i2v图生视频1080p
kling-o3-pro-v2v视频生视频1080p
kling-o3-pro-video-edit视频编辑1080p

Kling 的 standard 档出 720p、pro 档出 1080p,分辨率由模型档位决定。向不支持 1080p 的模型请求 1080p 会失败,预授权的费用会自动释放。

各系列的完整请求示例见各系列请求示例

创建任务

请求示例

curl --request POST \ --url https://gateway.mytokengate.com/v1/videos \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "seedance-2.0", "prompt": "A hummingbird hovering near a red flower, ultra slow motion, macro", "parameters": { "duration": 5, "resolution": "1080p", "ratio": "16:9" } }'

请求参数

参数类型必填说明
modelstring模型名称,如 seedance-2.0
promptstring是*文字提示词,等价于 content 中的一个文字块。若与 content 同时传入,以 content 为准
contentarray是*内容块数组:文字块(承载提示词)、图片块(image_url)或视频块(video_url)。图片、视频、源素材的唯一入口。详见图生视频视频生视频
parametersobject生成参数(见下表)。未知键会原样透传给上游

* promptcontent 至少提供其一。

parameters 可用键:

类型说明
durationinteger视频时长(秒),默认 5
resolutionstring720p1080p(1080p 单价更高,是否支持取决于模型)
ratiostring画面宽高比:16:99:161:1,默认 16:9
generate_audioboolean是否生成配音
watermarkboolean是否添加水印

响应

{ "id": "b1f9c3a2e4d7", "object": "video", "created_at": 1753420000, "status": "processing", "model": "seedance-2.0" }

返回的 id 是网关生成的任务 ID(不透明字符串),原样用于后续查询任务状态。

查询任务

用创建任务返回的 id 轮询任务状态。建议每 5 秒查询一次;任务超过 15 分钟未完成会被判定为失败并自动释放预授权。

请求示例

curl --request GET \ --url 'https://gateway.mytokengate.com/v1/videos/b1f9c3a2e4d7' \ --header 'Authorization: Bearer <token>'

响应(处理中)

{ "id": "b1f9c3a2e4d7", "object": "video", "status": "processing", "model": "seedance-2.0" }

响应(已完成)

{ "id": "b1f9c3a2e4d7", "object": "video", "status": "completed", "model": "seedance-2.0", "output": { "video_url": "https://.../video.mp4" }, "usage": { "completionTokens": 245025, "totalTokens": 245025 } }

响应字段

字段说明
status任务状态:pending(排队中)、processing(处理中)、completed(完成)、failed(失败)
output.video_url生成的视频地址,任务完成后返回,可直接下载
output.duration_seconds视频实际时长(秒)。部分模型返回,可能缺省;时长请以创建时传入的 duration 为准
usage.completionTokens输出 token 数,用于计费
usage.totalTokens总 token 数;视频按输出计费,当前与 completionTokens 相同
error失败时的错误信息,含 messagetypecode

生成完成后返回的视频下载地址为 MyTokenGate 地址。该地址约保留 7 天,建议生成后尽快下载留存,过期后需要重新生成。

图生视频

图生视频用 content 数组代替 prompt,数组内包含一个文字块和一个图片块。图片通过公网 HTTPS 地址提供,role 指定图片用途(如 first_frame 首帧、reference_image 参考图)。

{ "model": "seedance-2.0", "content": [ { "type": "text", "text": "The camera slowly zooms in, petals drifting in the wind" }, { "type": "image_url", "image_url": { "url": "https://example.com/first-frame.jpg" }, "role": "first_frame" } ], "parameters": { "duration": 5, "resolution": "720p" } }

输出分辨率会与图片宽高比匹配,建议使用 16:9、9:16 或 1:1 的图片。

视频生视频

视频生视频在文字提示的基础上,额外提供一段参考视频,模型据此重新演绎或转换风格,保留原有的运动与节奏。参考视频通过公网 HTTPS 地址提供,role 设为 reference_video

{ "model": "seedance-2.0", "content": [ { "type": "text", "text": "Restyle into a dreamy watercolor animation, keep the motion and timing" }, { "type": "video_url", "video_url": { "url": "https://example.com/reference.mp4" }, "role": "reference_video" } ], "parameters": { "duration": 5, "resolution": "720p" } }

参考视频需为公网可直接下载的常见格式(如 MP4),时长建议与目标输出接近。由于包含视频输入,视频生视频的 token 用量通常高于同分辨率的文生视频。支持的模型有 seedance-2.0kling-o3-standard-v2vkling-o3-pro-v2v

视频编辑 / 源视频改写(video-edit / v2v)

部分模型(happyhorse-1.0-video-editkling-o3-standard-video-editkling-o3-pro-video-edit)以一段源视频为输入进行改写或重演。源视频通过 content 中的一个 video_url 块提供,role 设为 reference_video,与提供其他视频输入的方式完全一致。

你不需要选择上游字段。不同目标模型的源素材字段差异由网关屏蔽,视频会被自动路由到正确的上游字段。

{ "model": "happyhorse-1.0-video-edit", "content": [ { "type": "text", "text": "Restyle into a dreamy watercolor animation, keep the motion" }, { "type": "video_url", "video_url": { "url": "https://example.com/source.mp4" }, "role": "reference_video" } ], "parameters": { "resolution": "720p" } }

创建与查询流程、响应结构与其他视频任务一致。源视频改写包含视频输入,token 用量通常约为同分辨率纯生成的两倍,请以任务完成时的 usage.completionTokens 为准。

各系列请求示例

下面按系列各给一个代表形态的完整请求体。同一系列内切换模型只需替换 model,请求结构不变;跨系列也是同一套契约,差异只在该模型支持哪些形态和分辨率。

Seedance 2.0 — 文生视频

{ "model": "seedance-2.0", "prompt": "Aerial shot of ocean waves crashing on a rocky shore at sunset, cinematic", "parameters": { "duration": 5, "resolution": "1080p", "ratio": "16:9" } }

seedance-2.0 同时支持图生视频和视频生视频,把 prompt 换成带图片块或视频块的 content 即可。seedance-2.0-fastseedance-2.0-mini 只出 720p,把 resolution 改成 720p

Wan 2.7 — 图生视频

{ "model": "wan-2-7-i2v", "content": [ { "type": "text", "text": "Slow cinematic camera push, natural subject motion, preserve composition, no text, no logo" }, { "type": "image_url", "image_url": { "url": "https://example.com/first-frame.jpg" }, "role": "first_frame" } ], "parameters": { "duration": 5, "resolution": "1080p", "ratio": "16:9" } }

文生视频用 wan-2-7-t2v,去掉图片块、只留文字块即可(或直接用顶层 prompt)。

HappyHorse 1.1 — 参考图生视频

参考图生视频给模型多张图,让主体和风格在生成过程中保持一致。第一张图的 role 必须是 first_frame,其余用 reference_image

{ "model": "happyhorse-1.1-r2v", "content": [ { "type": "text", "text": "Keep the subject and style consistent across the scene, smooth motion, cinematic, no text" }, { "type": "image_url", "image_url": { "url": "https://example.com/first-frame.jpg" }, "role": "first_frame" }, { "type": "image_url", "image_url": { "url": "https://example.com/reference-1.jpg" }, "role": "reference_image" }, { "type": "image_url", "image_url": { "url": "https://example.com/reference-2.jpg" }, "role": "reference_image" } ], "parameters": { "duration": 5, "resolution": "1080p", "ratio": "16:9" } }

role 只接受 first_framereference_imagereference_videoreference_audiolast_frame。写成其他值会被上游拒绝,常见报错是提示缺少提示词或首帧图。

同系列的 happyhorse-1.1-t2vhappyhorse-1.1-i2v 分别对应文生视频和图生视频,happyhorse-1.0-video-edit 用于视频编辑,写法见上文的「视频编辑 / 源视频改写」一节。

Kling O3 — 视频生视频

{ "model": "kling-o3-standard-v2v", "content": [ { "type": "text", "text": "Restyle into a dreamy watercolor animation, keep motion and timing, no text, no logo" }, { "type": "video_url", "video_url": { "url": "https://example.com/source.mp4" }, "role": "reference_video" } ], "parameters": { "duration": 5, "resolution": "720p", "ratio": "16:9" } }

换成 kling-o3-pro-v2v 可出 1080p。视频编辑用 kling-o3-standard-video-editkling-o3-pro-video-edit,请求体结构相同。文生视频用 kling-o3-standard,图生视频用 kling-o3-pro-i2v,参考图生视频用 kling-o3-standard-reference

完整示例(Python)

import time import requests BASE_URL = "https://gateway.mytokengate.com/v1" API_KEY = "YOUR_API_KEY" HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"} # 1. 创建任务 create = requests.post( f"{BASE_URL}/videos", headers=HEADERS, json={ "model": "seedance-2.0", "prompt": "Aerial shot of ocean waves crashing on a rocky shore at sunset", "parameters": { "duration": 5, "resolution": "1080p", "ratio": "16:9", }, }, ).json() task_id = create["id"] print("task:", task_id) # 2. 轮询结果 while True: status = requests.get( f"{BASE_URL}/videos/{task_id}", headers=HEADERS, ).json() if status["status"] == "completed": print("video:", status["output"]["video_url"]) break if status["status"] == "failed": print("failed:", status.get("error")) break time.sleep(5)

计费说明

视频按输出 token 计费,任务完成时按实际 usage.completionTokens 结算。token 用量随分辨率、时长和输入类型变化(1080p、含参考视频的用量更高),1080p 分辨率单价也更高。余额不足会在生成前被拒绝;任务失败时预授权的费用会自动释放,不产生扣费。各模型单价见计费说明

错误码

状态码说明
400请求参数无效
401API Key 无效或缺失
404模型不存在或任务不存在
429触发限流
503/504服务暂时不可用
Last updated on