curl --request POST \
--url https://api.apimart.ai/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": true,
"nsfw_check": true
}'
import requests
payload = {
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": True,
"nsfw_check": True
}
response = requests.post(
"https://api.apimart.ai/v1/videos/generations",
headers={"Authorization": "Bearer <token>"},
json=payload,
timeout=60,
)
response.raise_for_status()
print(response.json())
const payload = {
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": true,
"nsfw_check": true
};
const response = await fetch("https://api.apimart.ai/v1/videos/generations", {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_example_magi2"
}
]
}
MAGI-2
MAGI-2 视频生成
支持文生视频、首尾帧图生视频和图片、视频、音频参考生成。输出固定 1080p,时长 4–30 秒,默认生成声音。
POST
/
v1
/
videos
/
generations
curl --request POST \
--url https://api.apimart.ai/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": true,
"nsfw_check": true
}'
import requests
payload = {
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": True,
"nsfw_check": True
}
response = requests.post(
"https://api.apimart.ai/v1/videos/generations",
headers={"Authorization": "Bearer <token>"},
json=payload,
timeout=60,
)
response.raise_for_status()
print(response.json())
const payload = {
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": true,
"nsfw_check": true
};
const response = await fetch("https://api.apimart.ai/v1/videos/generations", {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_example_magi2"
}
]
}
curl --request POST \
--url https://api.apimart.ai/v1/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": true,
"nsfw_check": true
}'
import requests
payload = {
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": True,
"nsfw_check": True
}
response = requests.post(
"https://api.apimart.ai/v1/videos/generations",
headers={"Authorization": "Bearer <token>"},
json=payload,
timeout=60,
)
response.raise_for_status()
print(response.json())
const payload = {
"model": "magi-2",
"prompt": "雨夜街道上一只红色纸船顺着水沟漂流,微距镜头,雨声淅沥",
"duration": 5,
"aspect_ratio": "9:16",
"generate_audio": true,
"nsfw_check": true
};
const response = await fetch("https://api.apimart.ai/v1/videos/generations", {
method: "POST",
headers: {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_example_magi2"
}
]
}
POST /v1/videos/generations 提交任务,成功后从 data[0].task_id 获取任务 ID,再调用任务查询接口获取结果。
生成方式
| 方式 | 如何提交 |
|---|---|
| 文生视频 | 提供 prompt,不传图片、视频或音频素材。 |
| 图生视频 | 使用 image_urls 传首帧和可选尾帧,或使用独立的首尾帧字段。 |
| 参考生视频 | 传 video_urls、audio_urls 或 role: "reference_image" 的图片会自动进入参考模式。只有 image_urls 时,显式传 omni_reference_task_type: "reference" 才会将其作为参考图。 |
reference 的行为一致;进入参考模式后,所有图片都按参考图处理,image_urls 与 image_with_roles 中 role: "reference_image" 的图片合计最多 10 张。
参考生成示例统一显式传 omni_reference_task_type: "reference"。在提示词中说明每份素材的用途;参考素材用于引导生成,不会直接拼接参考视频或原样保留参考音频。
请求参数
是否在提交视频任务前执行内容审核。
true:使用omni-moderation-latest审核提示词和输入图片false或不传:不发起审核请求,不增加审核成本与延迟(默认)
文生视频与参考生视频支持
16:9(默认)、9:16、1:1、4:3、3:4、21:9。图生视频支持前五种比例,不支持 21:9;省略或传 auto 时跟随首帧比例。跟随比例不会改变固定 1080p 的输出规格。每项均为公网 HTTP(S) 图片 URL。只有按图生视频处理时才最多 2 张:第 1 张为首帧,第 2 张为可选尾帧。图生条件是仅传图片、未传参考视频或音频、未指定
reference,且未使用 reference_image 角色。进入参考模式后,本数组全部作为参考图,与 image_with_roles 中 reference_image 图片合计最多 10 张;自动参考与显式 reference 使用同一上限。每项包含
url 和 role。url 为公网 HTTP(S) 图片 URL;role 支持 first_frame、last_frame、reference_image。图生模式的首帧和尾帧各最多 1 张。reference_image 会触发参考模式,其图片与 image_urls 中的图片合计最多 10 张。素材要求
所有素材必须是公网可直接访问的 HTTP(S) 直链。需要登录、带防盗链或无法下载的地址可能导致任务失败。本地文件可先通过图片上传、视频上传或音频上传获取 URL。请求示例
首帧与尾帧
{
"model": "magi-2",
"prompt": "女孩慢慢转身,平滑过渡到尾帧的姿态,柔光",
"image_urls": [
"https://example.com/start.jpg",
"https://example.com/end.jpg"
],
"duration": 5
}
aspect_ratio 时跟随首帧比例。也可用 first_frame_image 与 last_frame_image 代替示例中的 image_urls。
仅图片参考
{
"model": "magi-2",
"prompt": "让两张参考图中的角色在同一座花园里相遇,保持各自的外观特征",
"image_urls": [
"https://example.com/reference-1.jpg"
],
"image_with_roles": [
{
"url": "https://example.com/reference-2.jpg",
"role": "reference_image"
}
],
"omni_reference_task_type": "reference",
"aspect_ratio": "16:9",
"duration": 5
}
图片、视频与音频混合参考
{
"model": "magi-2",
"prompt": "参考视频的运镜、参考图里女孩的样貌和参考音频的音乐风格,生成她在日落海边散步的画面",
"image_urls": [
"https://example.com/girl.jpg"
],
"video_urls": [
"https://example.com/camera.mp4"
],
"audio_urls": [
"https://example.com/bgm.mp3"
],
"omni_reference_task_type": "reference",
"aspect_ratio": "16:9",
"duration": 8
}
查询任务与结果
通过任务查询接口轮询至completed 或 failed。生成通常需要几分钟,服务繁忙时可能更久;不要把某个固定等待时间当作任务已经失败。停止查询不会取消任务。
curl --request GET \
--url 'https://api.apimart.ai/v1/tasks/task_example_magi2' \
--header 'Authorization: Bearer <token>'
| 字段 | 说明 |
|---|---|
data.status | pending / processing 表示处理中;completed 表示成功;failed 表示失败。 |
data.progress | 进度,范围 0–100。 |
data.result.videos[0].url | 成片下载地址,已转存至平台存储;完整结构见任务查询文档。 |
data.error.message | 任务失败时的错误说明。 |
不支持的功能
以下内容会在提交时返回 HTTP 400:mode、negative_prompt、watermark: true、camera_control、multi_shot / multi_prompt、element_list、video_list、voice_list、audio_setting、中间帧 keyframe、omni_reference_task_type: "edit" / "extend"、单独的 video_url,以及 1080p 以外的 resolution。本模型不提供视频编辑或续写。
常见错误
提交失败时读取error.message。任务已创建后失败时,读取任务查询结果中的 data.error.message。
| 错误信息或场景 | 处理方式 |
|---|---|
duration must be between 4 and 30 whole seconds | 使用 4–30 的整数秒;省略时默认为 5。 |
duration (5) and seconds (6) are aliases and must match | 两个时长字段保持相同,或只传一个。 |
requires prompt | 三种生成方式都必须填写提示词。 |
image_urls takes at most 2 images | 图生最多传首尾帧两张;仅图片参考时显式传 reference。 |
image-to-video only supports aspect_ratio | 图生移除 21:9;省略比例或传 auto 可跟随首帧。 |
accepts at most 10 reference images / 5 videos / 5 audios | 参考图片最多 10 张、视频最多 5 段、音频最多 5 段。 |
has no video edit / extend / does not support keyframes | 移除编辑、续写和中间帧参数;参考视频使用 video_urls。 |
always outputs 1080p | 只传 1080p,或省略 resolution。 |
audio (true) and generate_audio (false) are aliases and must match | 两个声音开关保持一致,或只传一个。 |
Could not download the input... | 检查素材 URL 是否公开且可直接下载,再重新提交。 |