MAGI-2 视频生成
通过文本、首尾帧图片或图片/视频/音频多模态参考生成 1080p 同步有声 MP4 视频,时长 4-30 秒
国内用户请注意: 中国大陆用户请使用 https://toapis.cn 作为接口地址(Base URL),并将文档示例中的 https://toapis.com 替换为 https://toapis.cn。国内站查询与回调返回的媒体文件地址将自动使用国内文件域名。
- 平台模型名:
magi-2(全站统一模型名,通过顶层video_generation_mode区分三种模式) - 输出规格:
1080pMP4 视频,默认同步生成对白、音效与环境声,时长4-30秒任意整数秒 - 计费方式:按成功输出视频秒数计费;三种模式计费规则一致,关闭音频(
generate_audio: false)不改变计费口径,参考素材不单独计输入费用,任务失败不扣费 - 开放范围:支持国际站(
https://toapis.com)与国内站(https://toapis.cn) - 异步任务接口:提交后返回统一的
generation.task,通过GET /v1/videos/generations/{task_id}或GET /v1/tasks/{task_id}查询状态与结果
本模型采用严格的顶层扁平 JSON 参数白名单:所有模式(含图生视频)prompt 均必填非空;不根据素材自动推断模式;不接受嵌套包装对象(如 input、options、config、metadata)、旧参数别名、未知参数、Base64/Data URI 或 multipart 文件上传。
输入模式
video_generation_mode |
模式说明 | 素材要求 | aspect_ratio |
|---|---|---|---|
text_to_video(默认) |
文生视频 | 不得传入 image_urls、last_frame_url、video_urls、audio_urls |
可选,6 种比例,默认 16:9 |
first_frame_image_to_video |
首尾帧图生视频 | image_urls 必填且恰好 1 张作为首帧;last_frame_url 可选;不得传入 video_urls 或 audio_urls |
可选,6 种比例;省略时自动跟随首帧 |
reference_to_video |
多模态参考生视频 | image_urls(1-10 张)、video_urls(1-5 段)、audio_urls(1-5 段)至少传入一组且可混合;不得传入 last_frame_url |
可选,6 种比例,默认 16:9 |
认证
所有接口均需要使用 Bearer Token 认证。
Authorization: Bearer <token>请求参数
平台视频生成模型名称,固定为 magi-2。三种模式统一使用同一模型名。
视频生成模式。缺省为 text_to_video。
text_to_video:文生视频,不能携带任何媒体字段first_frame_image_to_video:首帧(可选尾帧)图生视频reference_to_video:图片/视频/音频多模态参考生视频
携带媒体输入时必须显式指定对应模式,平台不会按 image_urls 自动猜模式。
视频内容描述,去首尾空白后 1-8000 个 Unicode 字符。所有模式(含图生视频)均必填非空。 建议清晰描述主体、动作、镜头运动、对白(可用引号标注)、音效与环境声。
输出视频时长(秒),支持 4-30 之间的任意整数,默认 5。按成功输出秒数计费。
输出视频画面比例,可选值:21:9、16:9、4:3、1:1、3:4、9:16。
text_to_video与reference_to_video:默认16:9first_frame_image_to_video:可选;省略时输出画面比例自动跟随首帧图片
输出视频分辨率。仅支持 1080p,传入其他分辨率值将被拒绝。
是否生成同步原生音频(对白、音效、环境声),默认 true。设为 false 可生成静音视频,计费规则不变。
可选随机种子,取值范围 0-2147483647(含端点)。省略时使用随机种子;显式传入 0 会被原样保留;不接受负数。
公网可访问的 HTTP(S) 图片 URL 数组(支持 JPG / PNG / WEBP)。本地图片请先通过 上传图片 获取 URL。
text_to_video:禁止传入first_frame_image_to_video:必填且恰好1张,作为首帧图片reference_to_video:可选,1-10张,作为主体/风格参考图(不会解释为首帧)
不传入时请省略该字段,传入空数组 [] 或 null 将返回 400 错误。
单张尾帧图片公网 HTTP(S) URL(JPG / PNG / WEBP),用于指定视频结束画面。
仅可在 first_frame_image_to_video 模式下与 image_urls 同时使用;text_to_video 与 reference_to_video 模式禁止传入。
参考视频公网 HTTP(S) URL 数组(支持 MP4 / MOV),1-5 段。本地视频请先通过 上传视频 获取 URL。
- 仅适用于
reference_to_video,text_to_video与first_frame_image_to_video模式禁止传入 - 每段参考视频建议
2-30秒且参考视频总时长<= 30秒(提交接口校验 URL 与数量上限,媒体时长在生成阶段校验)
参考音频公网 HTTP(S) URL 数组(支持 MP3 / WAV),1-5 段。本地音频请先通过 上传音频 获取 URL。
- 仅适用于
reference_to_video,text_to_video与first_frame_image_to_video模式禁止传入 - 每段参考音频建议
2-30秒且参考音频总时长<= 30秒(提交接口校验 URL 与数量上限,媒体时长在生成阶段校验)
可选的业务标识(如订单号或业务流水号),提交后可通过同一状态查询接口按该值查询任务。
可选的 ToAPIs 任务完成回调地址(也兼容 callback_url 字段)。由平台托管并按 HMAC-SHA256 签名投递,详见 任务 Webhook。
素材规则与校验边界
- 所有媒体输入仅接受公网可访问的
http://或https://URL,拒绝内网/回环地址、带内嵌凭据的 URL、Data URI、Base64 或 multipart 文件上传。 reference_to_video模式下image_urls、video_urls、audio_urls至少提供一组非空数组,三类参考可自由组合,互不互斥。- 可选媒体数组不使用时请直接省略,不得传空数组
[]或null。 - 以下参数或组合将返回 HTTP
400显式拒绝:嵌套包装对象(input、options、config、metadata)、旧别名(seconds、size、ratio、audio、audio_setting、image、images、reference_images)、stream、n、fps、watermark、return_last_frame、negative_prompt、非法seed/duration/resolution/aspect_ratio以及跨模式冲突字段。
计费说明
| 计费项 | 口径说明 |
|---|---|
| 计费方式 | 按成功输出视频秒数计费(per_second,4-30 整数秒) |
| 模式范围 | text_to_video、first_frame_image_to_video、reference_to_video 三种模式采用相同计费规则 |
| 音轨与参考素材 | generate_audio: false(静音)不改变计费口径;参考图片/视频/音频不单独计输入费用 |
| 失败与结算 | 任务失败不扣费(退还预占额度);最终结算以终态响应中的 billing(status: "settled" / "refunded")和 usage(charge_type: "per_second"、output_seconds)为准 |
提交响应仅返回任务句柄,不含最终费用。实际可用性与账户计费细节以所在站点控制台及任务终态 billing / usage 为准。
请求示例
文生视频(含显式 seed: 0)
{
"model": "magi-2",
"video_generation_mode": "text_to_video",
"prompt": "A small boat crosses a quiet lake at sunrise, with gentle water sounds and distant birds.",
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true,
"seed": 0
}首尾帧图生视频(静音,不传 aspect_ratio)
{
"model": "magi-2",
"video_generation_mode": "first_frame_image_to_video",
"prompt": "The camera slowly pushes toward the subject and transitions smoothly into the ending composition.",
"image_urls": [
"https://example.com/first-frame.jpg"
],
"last_frame_url": "https://example.com/last-frame.jpg",
"duration": 5,
"resolution": "1080p",
"generate_audio": false
}多模态参考生视频(图片 + 视频 + 音频组合)
{
"model": "magi-2",
"video_generation_mode": "reference_to_video",
"prompt": "Keep the subject from the reference image, follow the camera movement from the reference video, and match the mood of the reference audio.",
"image_urls": [
"https://example.com/reference-subject.jpg"
],
"video_urls": [
"https://example.com/reference-motion.mp4"
],
"audio_urls": [
"https://example.com/reference-ambience.wav"
],
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true
}响应
ToAPIs 平台任务 ID,用于后续查询任务状态。
对象类型,固定为 generation.task。
本次请求使用的平台模型名,固定为 magi-2。
任务状态:queued、in_progress、completed 或 failed。
任务进度百分比,取值 0-100。
任务创建时间,Unix 秒级时间戳。
提交后请轮询 获取视频任务状态(GET /v1/videos/generations/{task_id},兼容 GET /v1/tasks/{task_id})或配置 任务 Webhook。任务完成后,生成的 MP4 视频地址位于 result.data[0].url。建议轮询间隔至少 5-10 秒并加入随机抖动,遇到 HTTP 429 时遵循 Retry-After。
请求示例
curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"video_generation_mode": "text_to_video",
"prompt": "A small boat crosses a quiet lake at sunrise, with gentle water sounds.",
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true,
"seed": 0
}'curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"video_generation_mode": "first_frame_image_to_video",
"prompt": "The camera slowly pushes in and transitions smoothly to the ending frame.",
"image_urls": [
"https://example.com/first-frame.jpg"
],
"last_frame_url": "https://example.com/last-frame.jpg",
"duration": 5,
"resolution": "1080p",
"generate_audio": false
}'curl --request POST \
--url https://toapis.com/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"video_generation_mode": "reference_to_video",
"prompt": "Keep the subject from the reference image, use the camera motion from the video, and match the ambience from the audio.",
"image_urls": [
"https://example.com/reference-subject.jpg"
],
"video_urls": [
"https://example.com/reference-motion.mp4"
],
"audio_urls": [
"https://example.com/reference-ambience.wav"
],
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true
}'import requests
response = requests.post(
"https://toapis.com/v1/videos/generations",
headers={
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
},
json={
"model": "magi-2",
"video_generation_mode": "reference_to_video",
"prompt": "Keep the subject from the reference image and show it moving in a sunlit garden.",
"image_urls": ["https://example.com/reference-subject.jpg"],
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": True,
},
)
print(response.json())const response = await fetch("https://toapis.com/v1/videos/generations", {
method: "POST",
headers: {
Authorization: "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "magi-2",
video_generation_mode: "text_to_video",
prompt: "A small boat crosses a quiet lake at sunrise, with gentle water sounds.",
duration: 5,
aspect_ratio: "16:9",
resolution: "1080p",
generate_audio: true
})
});
console.log(await response.json());响应示例
{
"id": "tsk_vid_01M840FXWTM23BKN1JR68C5XEM",
"object": "generation.task",
"model": "magi-2",
"status": "queued",
"progress": 0,
"created_at": 1795575600
}