视频 API 中的精确首帧控制:Base64 与图片 URL 对比
ToAPIs 上的首帧(图生视频)控制是一份 URL 合同,不是 Base64 请求体合同。2026-12-01 抓取的官方文档要求你先暂存一张可公开访问的 HTTP(S) 图片,再把该 URL 填入已文档化的字段。页面没有文档化 first_frame_base64、data-URI,或在 POST /v1/videos/generations 中内联 Base64。
本文保留排期标题中的对比,并如实给出结论:生产集成应先上传或托管首帧,再按目标模型的文档提交 image_with_roles 或 image_urls。这不是时延基准测试,也不会采用“预缩放节省约 2 秒”之类未经官方发布的数字。完成信号请见用 Webhooks 处理异步 AI 视频生成。更广的 ID 对比见2026 终极 AI 视频生成 API 基准。
1. TL;DR 与性能概览
- Base64 不是已文档化的生成请求字段。 Upload Image API 写明生成类 API 不再接受 Base64 图片数据,并给出一般性原因:Base64 编码会使载荷膨胀约 33%。Seedance 素材审核、Hailuo 2.3、Wan 2.6 / Flash、Wan 3.0 和 Kling 页面都要求公开 URL,并拒绝 Base64 或本地路径。
- 先暂存 URL,再提交。
POST https://toapis.com/v1/uploads/images(中国大陆:https://toapis.cn)接受最大 30 MB 的 JPEG、PNG、WebP 或 GIF,并返回data.url。你自己托管的公开或预签名 HTTP(S) 对象也可以,只要满足所调用模型页面的限制。 - 使用该 ID 的官方字段。 在
seedance-2-5、MiniMax-H3和wan3.0-video上优先使用image_with_roles且role: "first_frame"。MiniMax-Hailuo-2.3与wan2.6使用image_urls。不要在 Seedance 或 MiniMax-H3 上混用这两个字段。 - 按官方边界轮询。 已配置 Token 时,Webhooks 是主要完成信号。否则按官方示例轮询
GET /v1/videos/generations/{task_id}:先等待 5 秒,然后每 10 秒查询一次并加入抖动,遵守Retry-After,上限 600 秒。
2. 官方 ID、图片字段,以及当天文档写了什么
生成示例使用 https://toapis.com(中国大陆:https://toapis.cn)和模型 API Key:
POST https://toapis.com/v1/videos/generations
Authorization: Bearer <API_KEY>
下表中的公开模型名与请求字段来自 2026-12-01 抓取的官方页面。规划别名如 minimax-h3 或 wan-2-6-flash 不是文档中的 ID。
| 官方 ID | 首帧 / 图生视频字段 | 时长窗口 | 页面写明的图片约束 |
|---|---|---|---|
seedance-2-5 | 优先 image_with_roles(first_frame、last_frame、reference_image;最多 30 张)。兼容字段 image_urls 仍可用,但不要同时发送。首尾帧任务请使用 aspect_ratio: "adaptive"。 | 4–30 秒,或 -1 让模型自行决定 | 仅公开 HTTP(S) URL;不接受 Base64 和本地路径;图片 ≤ 30 MB;URL 不得包含凭据或超过 2048 字节 |
seedance-2-5-flash | 字段模式相同;最多 10 张图片 | 4–30 秒,或 -1 | 同样的 URL 与大小规则;输出仅为 480p 或 720p |
seedance-2 / seedance-2-fast / seedance-2-mini | 同样的 image_with_roles 角色;seedance-2-mini 最多 9 张参考图 | 4–15 秒(仅标准版与 fast 支持 0 或 -1 自动时长) | 同样的公开 URL 审核规则 |
MiniMax-H3 | 优先 image_with_roles。兼容 image_urls:1 张 → first_frame;2 张 → 首尾帧;3–9 张 → reference_image | MiniMax-H3、MiniMax-H3-Highspeed、MiniMax-H3-Lite 为 4–15 秒;Max / Max-Turbo 为 5–15 秒 | JPG、JPEG、PNG、WebP、HEIC、HEIF;≤ 30 MB;两边 256–5760 px;宽高比 0.4–2.5。MiniMax-H3 输出为 2K 或 768p |
MiniMax-Hailuo-2.3 / MiniMax-Hailuo-2.3-Fast | 仅 image_urls(一张起始帧)。Fast 必须提供图片(仅图生视频) | 6 或 10 秒;1080P 只允许 6 秒 | JPG、JPEG、PNG、WebP;小于 20 MB;短边 > 300 px;宽高比介于 2:5 与 5:2;不要传 Base64 |
wan2.6 / wan2.6-flash | 仅 image_urls,一张图片。Flash 必须提供 image_urls 或 metadata.reference_urls(不可同时使用) | 5、10 或 15 秒 | 公开的 http:// 或 https:// URL;不再支持 Base64;720p / 1080p |
wan3.0-video / wan3.0-video-prime | image_with_roles 的 first_frame / last_frame(后者必须同时有前者)。参考图是单独数组,不能与帧角色混用 | 2–30 秒,或 -1 | 公开 URL;不要在生成请求中传递本地路径或 Base64 |
在 Seedance、MiniMax-H3 和 Wan 3.0 上,帧模式与参考图模式互斥。使用 last_frame 时必须同时提供 first_frame。
Base64 的 4/3 体积开销属于一般编码常识,Upload Image 页面也把约 33% 的膨胀作为生成 API 取消内联数据的原因之一。官方页面没有发布“预缩放到 1920×1080 节省约 2 秒”或“Base64 使启动加快 1.2 秒”这类实验室结果,因此本文不采用规划稿中的这些数字。
3. 生产实现:上传、提交、有界轮询
下面的可运行路径用官方上传接口暂存本地文件,再向 seedance-2-5 提交首帧任务。如果你已经有自己托管的公开对象 URL,生成请求同样使用 image_with_roles。

图 1. 官方路径:先暂存公开 HTTP(S) URL,再提交。内联 Base64 不是已文档化的生成字段。
3.1 cURL:先上传,再提交首帧
export TOAPIS_API_KEY="YOUR_API_KEY"
export BASE_URL="https://toapis.com" # 中国大陆:https://toapis.cn
UPLOAD=$(curl --fail --request POST \
--url "$BASE_URL/v1/uploads/images" \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--form "file=@./product-hero.jpg")
IMAGE_URL=$(printf '%s' "$UPLOAD" | python3 -c "import json,sys; print(json.load(sys.stdin)['data']['url'])")
curl --fail --request POST \
--url "$BASE_URL/v1/videos/generations" \
--header "Authorization: Bearer $TOAPIS_API_KEY" \
--header "Content-Type: application/json" \
--data @- <<EOF
{
"model": "seedance-2-5",
"prompt": "The product sits on a sunlit marble counter. A slow dolly-in, soft shadows, no logo changes.",
"duration": 8,
"resolution": "1080p",
"aspect_ratio": "adaptive",
"generate_audio": true,
"image_with_roles": [
{"url": "$IMAGE_URL", "role": "first_frame"}
]
}
EOF
Hailuo 的首帧请求使用兼容数组,而不是角色字段:
{
"model": "MiniMax-Hailuo-2.3",
"prompt": "The product slowly rotates toward the camera [Push in]",
"image_urls": ["https://example.com/product-hero.jpg"],
"duration": 6,
"resolution": "1080P"
}
3.2 Python:上传、提交、官方轮询循环
import os
import random
import time
import requests
API_KEY = os.environ["TOAPIS_API_KEY"]
BASE_URL = os.environ.get("TOAPIS_BASE_URL", "https://toapis.com")
def upload_image(path: str) -> str:
with open(path, "rb") as fh:
resp = requests.post(
f"{BASE_URL}/v1/uploads/images",
headers={"Authorization": f"Bearer {API_KEY}"},
files={"file": fh},
timeout=60,
)
resp.raise_for_status()
body = resp.json()
if not body.get("success"):
raise RuntimeError(body)
return body["data"]["url"]
def submit_first_frame(image_url: str) -> str:
resp = requests.post(
f"{BASE_URL}/v1/videos/generations",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json={
"model": "seedance-2-5",
"prompt": (
"The product sits on a sunlit marble counter. "
"A slow dolly-in, soft shadows, no logo changes."
),
"duration": 8,
"resolution": "1080p",
"aspect_ratio": "adaptive",
"generate_audio": True,
"image_with_roles": [{"url": image_url, "role": "first_frame"}],
},
timeout=30,
)
resp.raise_for_status()
task = resp.json()
task_id = task.get("id") or task.get("task_id")
if not task_id:
raise RuntimeError(f"submit response missing id: {task}")
return task_id
def poll_video_task(task_id: str, max_wait: int = 600) -> dict:
"""官方 video-status 示例:先等待 5 秒,间隔 10 秒,上限 600 秒。"""
start = time.time()
interval = 10
time.sleep(5)
while time.time() - start < max_wait:
resp = requests.get(
f"{BASE_URL}/v1/videos/generations/{task_id}",
headers={"Authorization": f"Bearer {API_KEY}"},
timeout=30,
)
if resp.status_code == 429:
retry_after = int(resp.headers.get("Retry-After", interval))
time.sleep(retry_after + random.uniform(0, 1))
interval = min(interval * 2, 120)
continue
resp.raise_for_status()
data = resp.json()
status = data.get("status")
if status == "completed":
item = (data.get("result") or {}).get("data") or []
if not item or not item[0].get("url"):
raise RuntimeError(f"completed without result URL: {data}")
return {
"url": item[0]["url"],
"format": item[0].get("format"),
"expires_at": data.get("expires_at"),
}
if status == "failed":
err = data.get("error") or {}
raise RuntimeError(err.get("message") or data)
time.sleep(interval + random.uniform(0, 1))
raise TimeoutError(f"task {task_id} still running after {max_wait}s")
if __name__ == "__main__":
image_url = upload_image("product-hero.jpg")
task_id = submit_first_frame(image_url)
result = poll_video_task(task_id)
print(result["url"], "expires_at=", result["expires_at"])
普通图像和视频任务也可以用 GET /v1/tasks/{task_id} 查询。请在 expires_at(Unix 时间戳)之前下载 result.data[0].url。官方保留期为完成时间加 30 天。
如果已经配置了 Task Webhooks,可以把紧密轮询改为兜底,详见消除视频生成超时以及 Webhook 教程。
4. 错误处理与状态矩阵
| 信号 | 官方取值 | 应做的事 |
|---|---|---|
提交 HTTP 400,invalid_private_assets | Seedance 审核:带凭据的 URL、URL 长于 2048 字节、同一 URL 被用作不同媒体类型,或一次请求超过 64 个媒体引用 | 改用公开 URL、缩短长度,并且不要把同一个 URL 既当图片又当视频 |
| 提交或异步失败提到 Base64 / 本地路径 | 生成页面拒绝 Base64 和本地文件路径 | 先上传,或传入公开 HTTP(S) URL |
同时发送 image_urls 与 image_with_roles | Seedance 与 MiniMax-H3 警告角色会变得不明确 | 新集成只发送 image_with_roles |
混用 first_frame 与 reference_image | 在 Seedance、MiniMax-H3 和 Wan 3.0 上互斥 | 只选帧模式或参考模式,不要混用 |
轮询 queued / in_progress | 非终态。官方表格:queued 等待 5–10 秒,in_progress 等待 10–15 秒 | 继续 10 秒有界循环;遇到 429 时遵守 Retry-After |
轮询 completed | 读取 result.data[0].url(仅在主 URL 无法访问时才使用 fallback_url) | 在 expires_at 之前下载 |
轮询 failed | 查看 error.message | 不要把规划稿中的 succeeded 当作官方状态 |
Hailuo Fast 未提供 image_urls | Fast 仅支持图生视频 | 必须提供一张起始帧 URL |
Seedance 的素材审核可能让任务在首次使用某 URL 时在 queued 停留数分钟。审核拒绝或准备超时会以 failed 结束任务,且不收取视频生成费用。同一用户、同一通道重复使用同一 URL 可以复用审核结果。文件字节变化后,请使用新的 URL。
5. 定价与 FinOps ROI
2026-12-01,未认证的 GET /api/v1/pricing 返回 401,因此本快照使用公开 定价页(1 credit ≈ $0.005)作为估算。请在账户目录中核对,它不是锁定报价。
| 官方 ID | 公开页计费方式(2026-12-01) | 列出的单价 / 估算 |
|---|---|---|
seedance-2-5 | 任务完成后按 usage.total_tokens 结算;按秒数字仅是预算估算 | $2.90 / 100 万 total tokens(按 1 credit ≈ $0.005 约合 580 credits / 100 万 tokens) |
seedance-2-5-flash | 同样按 token 结算 | $4.30 / 100 万 total tokens |
MiniMax-H3 | 按秒 | $0.064 / 秒(约 12.8 credits / 秒);目录行对 5 秒默认值给出约 $0.32 的估算 |
MiniMax-Hailuo-2.3 | 按次 | $0.194 / 次(约 38.8 credits) |
MiniMax-Hailuo-2.3-Fast | 按次 | $0.136 / 次(约 27.2 credits) |
wan2.6 | 按秒 | $0.060 / 秒;5 秒目录估算 $0.30 |
wan2.6-flash | 按秒 | $0.015 / 秒;5 秒目录估算 $0.075 |
规划稿里所谓 Seedance「定价基线」$0.030–$0.038 / 秒并不是这份目录:seedance-2-5 按 token 结算,而不是已发布的按秒单价。官方页面也没有发布 99.95% SLA。
上传一次并复用 data.url,可以避免每次变体都重传相同字节,这是 Upload Image 页面给出的复用理由——本文并不把它写成测得的省钱结果。
6. 常见问题
前言中的 FAQ 已覆盖 Base64 支持、官方字段名、上传与自托管 URL、格式限制以及轮询。这里再补充两条操作说明:
- 预签名 URL。 官方 Seedance 审核要求公开 HTTP(S) URL,拒绝内嵌凭据,并按 URL 识别媒体。若使用预签名对象,请把 URL 控制在 2048 字节以内,确保在审核和生成期间仍然可访问,并在对象变更后签发新 URL。
- 商品流水线。 拿到首帧 URL 后,可以把同一资源路由到实际接受该时长与分辨率的 Seedance 和 MiniMax ID。组装方式见自动化电商视频广告流水线。
7. 行动清单
- 在当天的生成页面确认官方模型 ID(
seedance-2-5、MiniMax-H3、MiniMax-Hailuo-2.3、wan2.6或wan3.0-video——不要用规划别名)。 - 用
POST /v1/uploads/images或符合该模型体积与格式限制的公开 HTTP(S) URL 暂存首帧。不要在生成请求体中发送 Base64。 - 在已文档化的模型上使用带
first_frame的image_with_roles;Hailuo 2.3 与 Wan 2.6 使用image_urls。不要在 Seedance 或 MiniMax-H3 上混用这两个字段。 - Seedance 首尾帧任务把
aspect_ratio设为adaptive,这是生成页面的要求。 - 需要推送完成信号时配置 Task Webhooks;否则按官方 5–10 秒 / 10×60 的指导轮询,并加入抖动与
Retry-After。 - 在
expires_at之前下载result.data[0].url,并以账户目录而不是规划稿确认价格。
2026-12-01 抓取的官方来源:Upload Image、Seedance 2.5 生成、MiniMax H3 生成、Hailuo 2.3 生成、Wan 2.6 生成、Wan 3.0 生成,以及 Get Video Task Status。