使用 Wan 2.6 图生视频与参考视频(R2V)API 构建精确流水线
目标型号:
wan2.6(可选 Flash ID:wan2.6-flash)
推理接口:https://toapis.com/v1/videos/generations
相关阅读:OpenAI Sora 2 API 指南 · 阿里 Wan 3.0 视频 API 入门 · Wan 3.0 Prime 与 Wan 2.6 Flash 对比 · MiniMax H3 自动化 R2V 流水线 · Wan 2.6 参考 · Wan 2.6 Flash 参考 · wan2.6 型号指南 · wan2.6-flash 型号指南
1. TL;DR 与能力概览
- 先核对目录:规划稿有时把「Wan 2.6 R2V」写成公共型号
wan-2-6-r2v,或把整条流水线指向wan-2-6-flash。2026-11-23 核对官方 Wan 2.6 生成参考(HTTP 200),公共 ID 是wan2.6。官方 Flash 生成参考(HTTP 200)列出wan2.6-flash。文档路径/videos/wan2.6-r2v/generation返回 HTTP 404。/model-guide/wan2-6-r2v虽然 HTTP 200,但标题是 “Model Guide Not Found”,不是有效指南。当天toapis.com/sitemap.xml在这一家族只列出wan2-6和wan2-6-flash。 - 这里的 “R2V” 指什么:在
wan2.6上发送metadata.reference_urls(公开视频 URL)会进入参考视频(r2v)模式。官方页面写明,服务端随后路由到名为wan2.6-r2v的上游。你仍然发送model: "wan2.6"。图生视频使用image_urls(1 张图)。只发 prompt 则走文生视频。这三种模式实际上互斥,因为image_urls不能与metadata.reference_urls同时使用。 - 调用约定:向
POST /v1/videos/generations异步提交,然后轮询GET /v1/videos/generations/{id},直到completed或failed。普通任务也可以用GET /v1/tasks/{id}查询。官方示例使用https://toapis.com(中国大陆使用https://toapis.cn)。本系列较早文章有时使用https://api.toapis.com。请选定一个源站并保持一致。本文跟随官方示例。 - Flash 不是同一个 ID:
wan2.6-flash只支持图生视频和参考视频。不支持纯文本生成;只发 prompt 会返回错误。Flash 可以生成无声视频(audio: false),并按文档中的不同单价计费。非 Flash 的wan2.6默认始终包含音频。 - 需要丢弃的未核实说法:规划稿中的
motion_amplitude、$0.018或$0.030每秒单价,以及时延或 SLA 数字,都不是当前 ToAPIs 文档。请以账户目录中的实时报价为准。
2. 官方 Wan 2.6 ID、路由与参数规则
在 model 字段中使用公共型号名。不要替换成规划稿别名;也不要发送上游名 wan2.6-r2v,除非后续官方页面把它列为公共目录字符串——2026-11-23 的生成参考并未这样列。
| 目录 ID | 在本文中的角色 | 已文档化的任务 |
|---|---|---|
wan2.6 | 默认公共 ID | 文生视频(仅 prompt)、图生视频(image_urls)、参考视频 / R2V(metadata.reference_urls) |
wan2.6-flash | 单独的 Flash 公共 ID | 仅图生视频和参考视频;只发 prompt 会失败 |
wan3.0-video | 相关的后续 Wan ID;见 Wan 3.0 入门 | 另一套 All-in-One 参数(含首尾帧)。不要把 Wan 3.0 字段混进 Wan 2.6 请求 |
wan2.6(以及对应的 Flash)按你发送的媒体自动路由:
| 提供的参数 | 上游模式 |
|---|---|
metadata.reference_urls(视频 URL) | 参考视频(r2v);Flash 路由到 wan2.6-r2v-flash |
image_urls(1 张图) | 图生视频(i2v) |
仅 prompt | wan2.6 上文生视频(t2v);wan2.6-flash 上返回错误 |
wan2.6 已文档化的请求字段包括:prompt(文生视频必填;图生视频和参考视频可选,用于描述期望动作或风格)、image_urls(最多 1 个可公开访问的 http:// 或 https:// 图片 URL;不再支持 base64——请先使用上传图片接口)、aspect_ratio(16:9、9:16、1:1、4:3、3:4;图生视频模式不支持)、resolution(720p 或 1080p,默认 1080p;不支持 480p)、duration(5、10 或 15,默认 5)、negative_prompt、seed、prompt_extend(默认 true)、audio(非 Flash 型号默认始终包含音频;设为 true 可显式启用)、shot_type(single 或 multi,仅用于文生视频和参考视频)、watermark,以及 metadata.reference_urls(公开视频 URL;支持「若干」参考视频;不能与 image_urls 同时使用)。
Flash 参考页更窄:model 固定为 wan2.6-flash;必须提供 image_urls 或 metadata.reference_urls 之一;prompt 可选;文档还列出 resolution、duration、audio(默认 true;false 生成无声视频并按不同费率计费)、watermark 和 metadata.reference_urls。该页没有文档化 aspect_ratio、shot_type、negative_prompt、seed 或 prompt_extend。

图 1:已文档化的 wan2.6 或 wan2.6-flash 载荷提交到 POST /v1/videos/generations。image_urls 与 metadata.reference_urls 不能同时使用。轮询同一任务 ID,仅在 status 为 completed 后读取 result.data[0].url。
官方 wan2.6 分辨率与画幅尺寸表:
| 画幅 | 说明 | 720p 尺寸 | 1080p 尺寸 |
|---|---|---|---|
| 16:9 | 横屏(默认) | 1280×720 | 1920×1080 |
| 9:16 | 竖屏 | 720×1280 | 1080×1920 |
| 1:1 | 方形 | 960×960 | 1440×1440 |
| 4:3 | 横屏 | 1088×832 | 1632×1248 |
| 3:4 | 竖屏 | 832×1088 | 1248×1632 |
3. 生产实现:cURL 与 Python
以下示例跟随官方文档中的 https://toapis.com。若在中国大陆调用,请将源站替换为 https://toapis.cn。上线前请对照你账户对应的 API 参考,确认 id、result.data[0].url 和响应包络。
步骤 1:图生视频与参考视频的 cURL
wan2.6 图生视频(此模式不要发送 aspect_ratio):
curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "wan2.6",
"prompt": "The product rotates slowly under studio lighting, camera locked off",
"image_urls": ["https://example.com/product.jpg"],
"resolution": "1080p",
"duration": 5
}'
同一公共 ID 上的参考视频(R2V)。请持久化返回的 id:
curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "wan2.6",
"prompt": "The character waves and smiles at the camera",
"metadata": {
"reference_urls": ["https://cdn.example.com/ref-character.mp4"]
},
"shot_type": "single",
"aspect_ratio": "16:9",
"resolution": "1080p",
"duration": 5
}'
Flash 图生视频预览(无声,文档中的单价更低)使用另一个公共 ID:
curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "wan2.6-flash",
"prompt": "The person comes alive and smiles at the camera",
"image_urls": ["https://example.com/portrait.jpg"],
"resolution": "720p",
"duration": 5,
"audio": false
}'
步骤 2:Python 辅助函数与轮询器
import os
import time
import requests
API_KEY = os.environ["TOAPIS_API_KEY"]
BASE = "https://toapis.com"
ENDPOINT = f"{BASE}/v1/videos/generations"
HEADERS = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
}
DOCUMENTED_IDS = {"wan2.6", "wan2.6-flash"}
RESOLUTIONS = {"720p", "1080p"}
DURATIONS = {5, 10, 15}
ASPECTS = {"16:9", "9:16", "1:1", "4:3", "3:4"}
SHOT_TYPES = {"single", "multi"}
def dispatch_wan26(
prompt: str | None = None,
*,
model: str = "wan2.6",
image_urls: list[str] | None = None,
reference_urls: list[str] | None = None,
aspect_ratio: str | None = None,
resolution: str = "1080p",
duration: int = 5,
negative_prompt: str | None = None,
seed: int | None = None,
prompt_extend: bool | None = None,
audio: bool | None = None,
shot_type: str | None = None,
watermark: bool | None = None,
) -> str:
if model not in DOCUMENTED_IDS:
raise ValueError("Send wan2.6 or wan2.6-flash; wan-2-6-r2v is not a documented public ID")
if duration not in DURATIONS:
raise ValueError("duration must be 5, 10, or 15")
if resolution not in RESOLUTIONS:
raise ValueError("resolution must be 720p or 1080p")
if image_urls and reference_urls:
raise ValueError("image_urls cannot be combined with metadata.reference_urls")
if image_urls and len(image_urls) != 1:
raise ValueError("image_urls is documented as supporting only 1 image")
if model == "wan2.6-flash" and not image_urls and not reference_urls:
raise ValueError("wan2.6-flash requires image_urls or metadata.reference_urls")
if model == "wan2.6" and not prompt and not image_urls and not reference_urls:
raise ValueError("wan2.6 needs a prompt, an image, or reference video URLs")
if image_urls and aspect_ratio:
raise ValueError("aspect_ratio is not supported in image-to-video mode on wan2.6")
if aspect_ratio and aspect_ratio not in ASPECTS:
raise ValueError("unsupported aspect_ratio")
if shot_type and shot_type not in SHOT_TYPES:
raise ValueError("shot_type must be single or multi")
if image_urls and shot_type:
raise ValueError("shot_type applies to text-to-video and reference-video modes only")
payload: dict = {
"model": model,
"resolution": resolution,
"duration": duration,
}
if prompt:
payload["prompt"] = prompt
if image_urls:
payload["image_urls"] = image_urls
if reference_urls:
payload["metadata"] = {"reference_urls": reference_urls}
if aspect_ratio:
payload["aspect_ratio"] = aspect_ratio
if negative_prompt:
payload["negative_prompt"] = negative_prompt
if seed is not None:
payload["seed"] = seed
if prompt_extend is not None:
payload["prompt_extend"] = prompt_extend
if audio is not None:
payload["audio"] = audio
if shot_type:
payload["shot_type"] = shot_type
if watermark is not None:
payload["watermark"] = watermark
res = requests.post(ENDPOINT, headers=HEADERS, json=payload, timeout=30)
res.raise_for_status()
data = res.json()
task_id = data.get("id") or data.get("task_id")
if not task_id:
raise RuntimeError(f"Unexpected submission envelope: {data}")
return task_id
def poll_task(task_id: str, deadline_s: int = 900) -> str:
poll_url = f"{BASE}/v1/videos/generations/{task_id}"
interval = 10.0
start = time.time()
time.sleep(5)
while time.time() - start < deadline_s:
poll = requests.get(poll_url, headers=HEADERS, timeout=15)
if poll.status_code == 429:
retry_after = poll.headers.get("Retry-After")
time.sleep(float(retry_after) if retry_after else min(interval * 2, 120))
continue
poll.raise_for_status()
data = poll.json()
status = data.get("status")
if status == "completed":
return data["result"]["data"][0]["url"]
if status == "failed":
raise RuntimeError(f"Generation failed: {data.get('error')}")
time.sleep(interval)
interval = min(interval * 1.5, 30.0)
raise TimeoutError(f"Task {task_id} exceeded {deadline_s}s; check status before retrying")
if __name__ == "__main__":
task_id = dispatch_wan26(
"The character waves and smiles at the camera",
reference_urls=["https://cdn.example.com/ref-character.mp4"],
shot_type="single",
aspect_ratio="16:9",
resolution="1080p",
duration=5,
)
print("Task:", task_id)
print("Video:", poll_task(task_id))
请在 expires_at 之前下载文件;视频任务状态参考写明保留期为 30 天。如果在 wan2.6 上保持默认开启的 prompt_extend,官方页面称系统会自动优化并丰富提示词——但没有公布可测量的额外时延。
4. 错误处理与状态矩阵
下表只是诊断起点,并不保证与 ToAPIs 错误码一一对应。即使 HTTP 查询成功,仍需读取任务 status。请求错误与 status: failed 的原因见错误参考。
| HTTP 或任务状态 | 常见类别 | 建议操作 |
|---|---|---|
400 | 未知型号别名、同时传入 image_urls 与 metadata.reference_urls、Flash 只发 prompt,或在图生视频请求中使用 aspect_ratio | 发送 wan2.6 或 wan2.6-flash,去掉互斥的媒体组合,并只使用公开 URL |
401 | 缺少或无效的 API Key | 在 ToAPIs 控制台轮换密钥,并确认 Authorization: Bearer 请求头 |
429 | 速率或并发限制 | 若有 Retry-After 则遵守;加入抖动后退避;仅在安全时重试 |
5xx 或客户端超时 | 网关或上游短暂异常 | 先查询已有任务 ID,再决定是否重新提交 |
status: queued 或 in_progress | 不是错误 | 等待并继续轮询 |
status: failed | 生成未成功 | 读取 error.code 和 error.message(若有 error.reason 一并查看)。不要原样重试策略拒稿的载荷 |
5. 价格与 FinOps
官方 Wan 2.6 生成参考没有发布单价表。它写明按秒计费、不同分辨率价格不同,并请参见模型广场。官方 Flash 生成参考发布了 “Audio vs Silent Pricing / 有声与无声计价” 表,2026-11-23 再次核对如下:
| 模式 | 720p 单价 | 1080p 单价 |
|---|---|---|
有声(audio: true) | ¥0.3 / 秒 | ¥0.5 / 秒 |
无声(audio: false) | ¥0.15 / 秒 | ¥0.25 / 秒 |
2026-11-23 拉取的型号指南页显示,wan2.6 的价格参考为 12 credits / 秒,wan2.6-flash 为 6 credits / 秒。两页都写明最终计费以当前账户报价以及当前时长、分辨率规则为准。请把 credits 数字和 Flash 人民币表当作快照,而不是适用于所有模式的合同。不要自行把 credits 换算成货币,也不要沿用规划稿中的美元单价。
- 仅在任务是图生视频或参考视频时,才用 Flash 做原型。 纯文本需求不属于
wan2.6-flash。 - 只有在确实需要无声输出时,才在 Flash 上关闭音频。 官方表格中无声单价更低;非 Flash 的
wan2.6默认始终包含音频,其生成参考页没有对应的人民币单价表。 - 展示价格不是通道保证。 批量预估前,请在账户目录中确认 ID 与实时报价。
6. 常见问题
详见 frontmatter 中的 FAQ。简要结论:发送 wan2.6 或 wan2.6-flash,不要发送 wan-2-6-r2v;image_urls 与 metadata.reference_urls 不能混用;motion_amplitude 未文档化;duration 为 5、10 或 15 秒;始终沿生成状态路径轮询并持久化任务 ID。
7. 行动清单
- 发送
wan2.6或wan2.6-flash,不要使用wan-2-6-r2v或wan-2-6-flash等规划稿别名。 - 只选择一种模式:仅 prompt(
wan2.6)、1 个公开图片 URL,或公开参考视频 URL——同一请求中不要同时发送图片和参考视频。 - 先上传本地媒体,只传
http(s)URL;不要发送 base64。 - 在图生视频请求中省略
aspect_ratio和shot_type。 - 持久化任务
id,轮询GET /v1/videos/generations/{id},仅在completed后读取result.data[0].url。 - 以实时账户报价计价;把 2026-11-23 的 Flash 人民币表和 credits 快照仅作注明日期的参考。
- 在
expires_at之前下载视频(文档写明保留 30 天)。