LoopToken
视频生成

Wan 视频系列

LoopToken Wan 视频模型的完整异步生成 API 接入说明

Wan 视频生成使用统一的异步任务 API。本文列出的模型名、字段和枚举值均区分大小写。实际可用状态和价格以模型列表为准。

适用模型

模型稳定用途
wan2.7-t2v文生视频,可附加自定义音频 URL
wan2.7-i2v首帧图生视频、首尾帧视频、带音频的首帧生成、视频续写
wan2.7-r2v参考图片生成、参考视频生成、参考图片附加参考声音
wan2.6-t2v文生视频;稳定示例使用像素级 size

模型能力矩阵

“不在稳定兼容范围”表示当前没有足够证据将该能力作为长期可依赖的接口契约。

能力wan2.7-t2vwan2.7-i2vwan2.7-r2vwan2.6-t2v
文生视频支持不在稳定兼容范围不在稳定兼容范围支持
首帧不在稳定兼容范围first_frame不在稳定兼容范围不在稳定兼容范围
尾帧不在稳定兼容范围last_frame,依赖首帧或续写视频不在稳定兼容范围不在稳定兼容范围
参考图片不在稳定兼容范围不在稳定兼容范围reference_image不在稳定兼容范围
参考视频不在稳定兼容范围不在稳定兼容范围reference_video不在稳定兼容范围
参考音频input.audio_urldriving_audioreference_voice不在稳定兼容范围
视频续写/编辑不在稳定兼容范围first_clip,可加尾帧不在稳定兼容范围不在稳定兼容范围
自动生成音频不在稳定兼容范围不在稳定兼容范围不在稳定兼容范围不在稳定兼容范围
分辨率720P、1080P720P、1080P720P、1080P已验证 960*960
宽高比5 种枚举跟随首帧或续写素材5 种枚举size 决定
时长2-15 秒,默认 52-15 秒,默认 5无参考视频 2-15 秒;含参考视频 2-10 秒;默认 5已验证 2 秒
智能时长不支持稳定承诺不支持稳定承诺不支持稳定承诺不支持稳定承诺
prompt_extend支持,默认 true支持,默认 true支持,默认 true不在稳定兼容范围
多镜头在 prompt 中描述;不支持 shot_type不在稳定兼容范围在 prompt 中描述;不支持 shot_type不在稳定兼容范围
watermark支持,默认 false支持,默认 false支持,默认 false不在稳定兼容范围
seed0-21474836470-21474836470-2147483647不在稳定兼容范围
callback_url可选可选可选可选
模型专属字段audio_urlmediamediareference_voicesize

调用流程

  1. POST https://api.vibelab.me/v1/videos/generations 提交 JSON 请求。
  2. 接口受理后返回 HTTP 202 和平台 task_id202 只表示任务已创建,不表示所有生成参数已经完成最终校验。
  3. 每 5-10 秒请求 GET https://api.vibelab.me/v1/tasks/{task_id};连续轮询建议逐步退避,最长不超过 30 秒一次。
  4. pending 表示排队中,running 表示生成中;继续轮询。
  5. succeededfailed 是终态。成功后读取 video_url,失败时读取 error
  6. video_url 是临时地址。必须以响应中的 expires_at 为准并及时转存,不要假定固定有效时长。

请求头

Header必填说明
AuthorizationBearer $LOOPTOKEN_API_KEYLoopToken API Key;不要写入客户端公开代码
Content-Typeapplication/json请求体必须为 JSON

无需传递其他 Header。响应中的 X-Request-Id 可用于问题排查,但不是请求必填项。

请求参数

顶层与输入字段

字段路径类型必填默认值支持模型枚举/范围与说明
modelstring全部必须使用上方四个精确模型名之一
inputobject全部模型输入对象
input.promptstringt2v、r2v 是;i2v 否全部2.7 系列最多 5000 字符;2.6 请保持简洁
input.negative_promptstring2.7 全部t2v、r2v 最多 500 字符;i2v 未承诺具体上限
input.audio_urlstringwan2.7-t2v可由服务端直接下载的公网音频 URL;Base64、格式、大小和时长限制不在稳定兼容范围
input.mediaarrayi2v、r2v 是wan2.7-i2vwan2.7-r2v只使用下文列出的对象和组合
callback_urlstring全部公网 HTTPS URL,域名必须可解析;私网、回环和本地地址会被拒绝。回调投递不应替代任务轮询

生成参数

字段路径类型必填默认值支持模型枚举/范围、依赖与冲突
parameters.durationinteger2.7 为 5全部2.7 t2v/i2v:2-15;r2v:含参考视频 2-10,否则 2-15;2.6 稳定范围只确认 2。必须传连续整数
parameters.resolutionstring1080P2.7 全部720P1080P;不得与 2.6 的 size 混用
parameters.sizestring2.6 建议显式传无稳定默认值wan2.6-t2v宽*高;稳定范围已验证 960*960。不得用于 2.7
parameters.ratiostring16:9wan2.7-t2vwan2.7-r2v16:99:161:14:33:4;i2v 比例由素材决定
parameters.prompt_extendbooleantrue2.7 全部是否智能扩写 prompt
parameters.shot_typestring无稳定支持模型t2v/r2v 2.7 明确不支持;多镜头直接写进 prompt
parameters.watermarkbooleanfalse2.7 全部是否添加生成内容水印
parameters.seedinteger随机2.7 全部0-2147483647;同一 seed 不保证逐像素一致

请求体读取上限为 10 MiB,这不是 URL 所指向素材的文件大小限制。参数越界、未知素材组合或不支持字段可能在提交阶段报错,也可能在任务创建后异步失败。

素材对象

所有 URL 都必须允许服务端直接下载,不得依赖登录态、Cookie、临时页面或局域网。下表中的 Wan 稳定素材对象不使用 role 字段,该字段缺省且不要传递。未列出的 Base64 视频和音频输入不在稳定兼容范围。

素材对象字段URL/Base64格式、大小、时长与分辨率数量和组合规则
首帧图片type: "first_frame"url公网 URL;图片 data URIMIME 必须与实际图片一致;具体格式、大小和像素上下限不作稳定承诺i2v;采用首帧、首帧加尾帧、首帧加参考音频等下列最小组合;其他数量不在稳定兼容范围
尾帧图片type: "last_frame"url公网 URL;图片 data URI同首帧不能单独使用;用于 first_frame + last_frame [+ driving_audio]first_clip + last_frame
普通参考图片type: "reference_image"url,可选 reference_voice图片支持公网 URL/data URI;声音仅 URL具体格式、大小和像素限制不作稳定承诺仅 r2v;与参考视频可混合。图片按出现顺序分别编号为“图1”“图2”
参考视频type: "reference_video"url仅承诺公网 URLBase64、具体 MIME、格式、大小、素材时长和分辨率不作稳定承诺仅 r2v;视频按出现顺序分别编号为“视频1”“视频2”;存在任一视频时输出最长 10 秒
参考音频type: "driving_audio"url仅承诺公网 URLBase64、格式、大小、时长不作稳定承诺仅 i2v;采用 first_frame + driving_audiofirst_frame + last_frame + driving_audio 的最小组合,其他数量不在稳定兼容范围
视频续写素材type: "first_clip"url仅承诺公网 URLBase64、格式、大小、时长和分辨率不作稳定承诺仅 i2v;采用单独续写或 first_clip + last_frame 的最小组合,其他数量不在稳定兼容范围
参考声音reference_image.reference_voice仅承诺公网 URLBase64、格式、大小、时长不作稳定承诺仅作为 r2v 的 reference_image 对象字段使用

未给出稳定上限的素材类型,不应通过批量堆叠试探数量。生产请求应使用完成目标所需的最少素材,并仅采用表中组合。

尺寸、比例和时长

wan2.7-t2vwan2.7-r2v

分辨率16:99:161:14:33:4
720P1280x720720x1280960x9601088x832832x1088
1080P(默认)1920x10801080x19201440x14401648x12481248x1648

wan2.7-t2v 支持 2-15 秒连续整数。wan2.7-r2v 不含参考视频时支持 2-15 秒,含参考视频时支持 2-10 秒。两者默认都是 5 秒、16:9,不支持将“智能时长”作为稳定参数。

wan2.7-i2v

支持 720P1080P(默认),时长为 2-15 秒连续整数,默认 5 秒。输出比例由首帧或续写素材确定,不传 ratio;具体像素随素材比例确定。

wan2.6-t2v

稳定验证范围为 parameters.size: "960*960"duration: 2,对应 720p、1:1。其他像素枚举、默认尺寸、完整时长范围和智能时长不在稳定兼容范围,生产请求建议显式传入上述值。

参数优先级

模型尺寸确定规则
wan2.7-t2vwan2.7-r2vresolution 选择档位,ratio 选择比例;两者共同确定像素
wan2.7-i2vresolution 选择档位,比例由首帧或续写素材决定
wan2.6-t2vsize 同时确定像素、档位和比例

完整请求示例

各稳定模式的 JSON 请求体

纯文生视频:

{
  "model": "wan2.7-t2v",
  "input": { "prompt": "清晨的湖面泛起微波,固定镜头,写实光线" },
  "parameters": { "resolution": "720P", "ratio": "1:1", "duration": 2 }
}

文生视频并附加自定义音频:

{
  "model": "wan2.7-t2v",
  "input": {
    "prompt": "清晨的湖面泛起微波,画面节奏与音乐自然同步",
    "audio_url": "https://www.w3schools.com/html/horse.mp3"
  },
  "parameters": { "resolution": "720P", "ratio": "16:9", "duration": 5 }
}

2.6 文生视频:

{
  "model": "wan2.6-t2v",
  "input": { "prompt": "极简静态场景,固定镜头" },
  "parameters": { "size": "960*960", "duration": 2 }
}

首帧与 Base64 图片:

{
  "model": "wan2.7-i2v",
  "input": {
    "prompt": "人物缓慢转身,镜头平稳推进",
    "media": [
      { "type": "first_frame", "url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ..." }
    ]
  },
  "parameters": { "resolution": "720P", "duration": 5 }
}

首尾帧生成:

{
  "model": "wan2.7-i2v",
  "input": {
    "prompt": "人物缓慢转身,最终停在目标画面",
    "media": [
      { "type": "first_frame", "url": "https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=1024&q=80" },
      { "type": "last_frame", "url": "https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=1024&q=80" }
    ]
  },
  "parameters": { "resolution": "720P", "duration": 5 }
}

带音频的首帧生成:

{
  "model": "wan2.7-i2v",
  "input": {
    "prompt": "人物按照音频自然说话",
    "media": [
      { "type": "first_frame", "url": "https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=1024&q=80" },
      { "type": "driving_audio", "url": "https://www.w3schools.com/html/horse.mp3" }
    ]
  },
  "parameters": { "resolution": "720P", "duration": 5 }
}

视频续写并指定尾帧:

{
  "model": "wan2.7-i2v",
  "input": {
    "prompt": "延续原有运镜,最终停在目标画面",
    "media": [
      { "type": "first_clip", "url": "https://www.w3schools.com/html/mov_bbb.mp4" },
      { "type": "last_frame", "url": "https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=1024&q=80" }
    ]
  },
  "parameters": { "resolution": "720P", "duration": 5 }
}

参考图片并附加参考声音:

{
  "model": "wan2.7-r2v",
  "input": {
    "prompt": "图1中的人物在舞台中央自然演讲",
    "media": [
      {
        "type": "reference_image",
        "url": "https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=1024&q=80",
        "reference_voice": "https://www.w3schools.com/html/horse.mp3"
      }
    ]
  },
  "parameters": { "resolution": "720P", "ratio": "16:9", "duration": 5 }
}

仅参考视频:

{
  "model": "wan2.7-r2v",
  "input": {
    "prompt": "延续视频1中的人物动作与镜头节奏",
    "media": [
      { "type": "reference_video", "url": "https://www.w3schools.com/html/mov_bbb.mp4" }
    ]
  },
  "parameters": { "resolution": "720P", "ratio": "16:9", "duration": 5 }
}

参考视频与参考图片混合:

{
  "model": "wan2.7-r2v",
  "input": {
    "prompt": "视频1中的人物拿起图1中的道具,保持原有动作风格",
    "media": [
      { "type": "reference_video", "url": "https://www.w3schools.com/html/mov_bbb.mp4" },
      { "type": "reference_image", "url": "https://images.unsplash.com/photo-1518717758536-85ae29035b6d?auto=format&fit=crop&w=1024&q=80" }
    ]
  },
  "parameters": { "resolution": "720P", "ratio": "16:9", "duration": 5 }
}

cURL:提交并查询

TASK_ID=$(curl -sS https://api.vibelab.me/v1/videos/generations \
  -H "Authorization: Bearer $LOOPTOKEN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "wan2.7-t2v",
    "input": {"prompt": "清晨的湖面泛起微波,固定镜头"},
    "parameters": {"resolution": "720P", "ratio": "1:1", "duration": 2}
  }' | jq -r '.task_id')

curl -sS "https://api.vibelab.me/v1/tasks/$TASK_ID" \
  -H "Authorization: Bearer $LOOPTOKEN_API_KEY"

Python:提交并轮询

import os
import time
import requests

base_url = "https://api.vibelab.me"
headers = {
    "Authorization": f"Bearer {os.environ['LOOPTOKEN_API_KEY']}",
    "Content-Type": "application/json",
}
body = {
    "model": "wan2.7-t2v",
    "input": {"prompt": "清晨的湖面泛起微波,固定镜头"},
    "parameters": {"resolution": "720P", "ratio": "1:1", "duration": 2},
}

response = requests.post(f"{base_url}/v1/videos/generations", headers=headers, json=body)
response.raise_for_status()
task_id = response.json()["task_id"]

while True:
    task = requests.get(f"{base_url}/v1/tasks/{task_id}", headers=headers)
    task.raise_for_status()
    result = task.json()
    if result["status"] in {"succeeded", "failed"}:
        print(result)
        break
    time.sleep(8)

Node.js:提交并轮询

const baseUrl = 'https://api.vibelab.me';
const headers = {
  Authorization: `Bearer ${process.env.LOOPTOKEN_API_KEY}`,
  'Content-Type': 'application/json',
};

const submitted = await fetch(`${baseUrl}/v1/videos/generations`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    model: 'wan2.7-t2v',
    input: { prompt: '清晨的湖面泛起微波,固定镜头' },
    parameters: { resolution: '720P', ratio: '1:1', duration: 2 },
  }),
});
if (!submitted.ok) throw new Error(await submitted.text());
const { task_id: taskId } = await submitted.json();

while (true) {
  const response = await fetch(`${baseUrl}/v1/tasks/${taskId}`, { headers });
  if (!response.ok) throw new Error(await response.text());
  const task = await response.json();
  if (task.status === 'succeeded' || task.status === 'failed') {
    console.log(task);
    break;
  }
  await new Promise((resolve) => setTimeout(resolve, 8000));
}

提交响应

成功提交固定返回 HTTP 202,对象正好包含以下六个字段:

字段类型说明
task_idstringLoopToken 任务 ID;后续查询使用此值
modelstring请求使用的公开模型名
statusstring提交时为 pending
created_atintegerUnix 秒时间戳
durationinteger提交阶段用于任务估算的时长
resolutionstring提交阶段识别的计费档位,如 720p
{
  "task_id": "vt_example123",
  "model": "wan2.7-t2v",
  "status": "pending",
  "created_at": 1783828800,
  "duration": 2,
  "resolution": "720p"
}

任务查询

字段说明

字段类型出现条件说明
task_idstring始终平台任务 ID
modelstring始终公开模型名
statusstring始终pendingrunningsucceededfailed
created_atinteger始终Unix 秒
completed_atinteger终态且有完成时间Unix 秒
durationinteger始终终态可能由实际 usage 更新
resolutionstring始终720p1080p;终态可能由实际 usage 更新
ratiostring终态 usage 提供时实际输出比例
usageobject终态有统计时仅可能包含 durationSRratio
credits_chargednumber完成结算后本任务最终实际扣除的 credits
video_urlstring成功且 URL 有效临时视频下载地址
expires_atintegervideo_urlURL 失效的 Unix 秒时间戳
error.codestring失败upstream_errortimeout
error.messagestring失败当前稳定消息为 video generation failed

排队中:

{
  "task_id": "vt_example123",
  "model": "wan2.7-t2v",
  "status": "pending",
  "created_at": 1783828800,
  "duration": 2,
  "resolution": "720p"
}

处理中:

{
  "task_id": "vt_example123",
  "model": "wan2.7-t2v",
  "status": "running",
  "created_at": 1783828800,
  "duration": 2,
  "resolution": "720p"
}

成功:

{
  "task_id": "vt_example123",
  "model": "wan2.7-t2v",
  "status": "succeeded",
  "created_at": 1783828800,
  "completed_at": 1783828920,
  "duration": 2,
  "resolution": "720p",
  "ratio": "1:1",
  "usage": { "duration": 2, "SR": 720, "ratio": "1:1" },
  "credits_charged": 12,
  "video_url": "https://example.com/generated/video.mp4?signature=replace-me",
  "expires_at": 1784088120
}

失败:

{
  "task_id": "vt_example123",
  "model": "wan2.7-t2v",
  "status": "failed",
  "created_at": 1783828800,
  "completed_at": 1783828860,
  "duration": 2,
  "resolution": "720p",
  "error": {
    "code": "upstream_error",
    "message": "video generation failed"
  }
}

错误处理

即时错误通常使用 { "error": { "code": "...", "message": "..." } }。生成参数和素材问题不保证在提交阶段发现,也可能表现为异步 failed

HTTP/结果error.code触发条件处理建议
400invalid_request_errorJSON、字段类型或 callback_url 地址非法修正 JSON;回调使用可解析的公网 HTTPS 地址
402insufficient_credits余额不足以预扣充值,或降低时长/分辨率后重试
404model_not_found模型名不存在或不可用从模型列表复制精确名称
404task_not_found任务不存在,或任务不属于当前 API Key 账户检查 task_id 和鉴权账户
503以响应为准(不作为稳定兼容字段)模型暂不可用按可重试服务错误处理,指数退避后重试;不要高频重复提交
502upstream_error提交生成任务失败保留请求 ID,退避后有限次数重试
202 后 failedupstream_error请求参数不被模型接受、素材 URL 无法访问、素材格式/数量/组合错误、不支持的模型参数或生成失败对照本页矩阵检查模型、字段、URL 可访问性和素材组合;修正后新建任务
202 后 failedtimeout生成任务超时稍后新建任务;持续发生时联系支持并提供 task_id

素材 URL、格式、数量和参数名目前没有稳定的一对一细分公开错误码。不要依赖具体失败文案编写业务逻辑,应按 HTTP 状态、error.code 和任务状态分支处理。

计费

  • Wan 视频按实际生成时长和 720p/1080p 分辨率档位计费,分辨率越高、时长越长,费用越高。
  • 提交时按可解析的请求参数预估并预扣;生成完成后按实际 usage.durationusage.SR 重新结算,多退少补。
  • credits_charged 是完成结算后该任务最终实际扣除的 credits,业务账单应以此字段为准。
  • 同步提交失败会释放预扣;异步生成失败会退款,失败任务不最终收取生成费用。
  • 单价可能调整,不在本文固化,始终以模型列表展示的当前价格为准。

信息安全

  • API Key 只保存在服务端环境变量或密钥管理服务中,不要提交到代码仓库、日志或前端页面。
  • 不要向终端用户暴露任务调试信息;对外只传递业务所需的状态和结果。
  • 素材 URL 应使用最小权限、短期有效的下载地址,并避免在查询参数中放置长期密钥。
  • 示例中的公开图片、视频和音频仅用于展示请求形状。生产接入必须替换为你有权处理、允许服务端直接下载的自有素材;vt_example123、生成结果地址和截断 Base64 均为占位内容。
  • 视频生成成功后按 expires_at 及时转存,并按照业务的数据保留策略删除不再需要的素材和结果。

本页内容