MAGI-2

MAGI-2 生成 4–30 秒的 1080p 视频,可选原生音频,支持三种模式:

mode作用
text_to_video仅根据提示词生成视频
image_to_video以首帧图片生成视频,可选指定尾帧
reference_to_video以最多 10 张参考图、5 段参考视频和 5 段参考音频为引导生成视频

输出为 1080p MP4(H.264,25 fps;generate_audio 为 true 时带 AAC 音频)。

模型

模型名称说明
magi-2.0文本、图片或多模态参考生成 1080p 视频,4–30 秒

定价

费用 = duration × 每秒 20.8 积分。模式、画面比例、音频和参考素材都不影响价格。

分辨率积分/秒5 秒10 秒15 秒30 秒
1080p20.8104208312624
  • 计费秒数即请求中的 duration(4–30 的整数,默认 5)。
  • 积分在创建任务时预扣,任务失败会全额退还。
  • 参数不合法时创建任务直接返回 400 错误,不扣积分。素材无法读取等问题会以任务失败的形式返回,同样全额退还。
  • 以上为账户倍率前价格。

创建任务

POST https://api.aivideoapi.ai/v1/videos/generations

请求体

字段类型必填说明
modelstring是magi-2.0
inputobject是生成参数
callback_urlstring否接收任务完成/失败通知的 URL

Input 参数

字段类型必填说明
modestring是text_to_video、image_to_video 或 reference_to_video
promptstring是最长 8000 字符,建议使用英文。可以用 @Image1、@Video1、@Audio1 指代素材,每种类型按各自列表顺序从 1 开始编号。
resolutionstring否仅支持 1080p(默认)。
aspect_ratiostring否21:9、16:9(默认)、4:3、1:1、3:4 或 9:16,不支持 auto。image_to_video 请使用与首帧一致的比例。
durationinteger否输出时长(秒),4–30,默认 5。即计费时长。
generate_audioboolean否是否生成原生音频,默认 true,不影响价格。
seedinteger否0–4294967295,用于复现结果。
image_urlsstring[]视模式而定image_to_video:必填,1–2 张(第 1 张为首帧,可选第 2 张为尾帧)。reference_to_video:最多 10 张参考图。text_to_video 不可传。
video_urlsstring[]否仅 reference_to_video:最多 5 段参考视频,每段 2–30 秒,总时长不超过 30 秒。
audio_urlsstring[]否仅 reference_to_video:最多 5 段参考音频,单段和总时长均不超过 30 秒。

各模式的素材规则:

  • text_to_video:不要传 image_urls、video_urls 或 audio_urls。
  • image_to_video:传 1–2 个 image_urls,不可传 video_urls 和 audio_urls。
  • reference_to_video:image_urls、video_urls、audio_urls 至少传一项,可以只传音频。

所有素材必须是公网可直接下载的 HTTP(S) 链接,每个链接最长 4096 字符(不支持 base64 / data URL),并在任务结束前保持可访问。

示例

文生视频

curl -X POST https://api.aivideoapi.ai/v1/videos/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "magi-2.0",
    "callback_url": "https://your-server.com/webhook",
    "input": {
      "mode": "text_to_video",
      "prompt": "A paper boat drifts down a rain-soaked city street at dusk, neon reflections rippling on the water, slow tracking shot",
      "aspect_ratio": "16:9",
      "duration": 10,
      "generate_audio": true
    }
  }'

图生视频(首尾帧)

curl -X POST https://api.aivideoapi.ai/v1/videos/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "magi-2.0",
    "input": {
      "mode": "image_to_video",
      "prompt": "The camera pulls back as the lighthouse beam sweeps across the stormy sea",
      "image_urls": [
        "https://example.com/first-frame.png",
        "https://example.com/last-frame.png"
      ],
      "aspect_ratio": "16:9",
      "duration": 5
    }
  }'

参考生视频

curl -X POST https://api.aivideoapi.ai/v1/videos/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "magi-2.0",
    "input": {
      "mode": "reference_to_video",
      "prompt": "@Image1 dances on a rooftop at sunset, following the moves in @Video1, in time with @Audio1",
      "image_urls": ["https://example.com/character.png"],
      "video_urls": ["https://example.com/dance.mp4"],
      "audio_urls": ["https://example.com/music.mp3"],
      "aspect_ratio": "9:16",
      "duration": 15,
      "seed": 42
    }
  }'

响应

{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "8b6a5162-5c91-4a42-8e80-4c8ef5486f24"
  }
}

查询任务

curl https://api.aivideoapi.ai/v1/tasks/{taskId} \
  -H "Authorization: Bearer sk-your-api-key"

状态变化:pending -> processing -> completed 或 failed。生成通常需要约 13–20 分钟,排队时会更久。建议优先使用 callback_url,或每 15 秒以上轮询一次。

  • 成功时视频地址在 output.urls[0],链接有效期 24 小时,请及时下载保存。
  • 任务失败时,预扣的积分会全额退还。
  • 该模型的任务提交后不支持取消。

回调 (Callback)

创建任务时传入 callback_url,系统会在任务完成或失败时自动向你的 URL 发送 POST 请求。请求头与重试策略详见回调说明。

任务完成时回调

{
  "id": "8b6a5162-5c91-4a42-8e80-4c8ef5486f24",
  "status": "completed",
  "model": "magi-2.0",
  "created_at": 1795700000,
  "completed_at": 1795700960,
  "output": {
    "urls": [
      "https://file.aivideoapi.ai/videos/2026/11/26/abc.mp4"
    ]
  }
}

任务失败时回调

{
  "id": "57c8772c-f834-46f3-9b7d-81f92e104050",
  "status": "failed",
  "model": "magi-2.0",
  "created_at": 1795700000,
  "error": {
    "code": "upstream_error",
    "message": "A reference image, video or audio file could not be read. Ensure every URL is public, directly downloadable and in a supported format."
  }
}

常见失败原因:提示词或素材不符合内容政策、素材无法读取、参考视频或音频时长不符合要求,以及一般性的生成失败。失败的任务会全额退还积分。

重要说明

  • 收到回调后请尽快返回 2xx 状态码(建议 3 秒内)。返回非 2xx 或超时(10 秒)将触发重试,最多 3 次(间隔分别为 3 分钟、10 分钟)。
  • 业务侧应根据 X-Task-Id 做幂等处理,避免同一任务重复入库。
  • 任务最终状态以 GET /v1/tasks/{taskId} 查询为准;如果 3 次回调都失败,仍可主动轮询兜底。

常见错误码

请求失败时,API 返回 JSON 格式的错误响应:

{
  "error": {
    "code": "insufficient_credits",
    "message": "Your credit balance is too low. Please top up.",
    "type": "billing_error"
  }
}

错误码一览

HTTP 状态码错误码类型说明
400invalid_requestinvalid_request_error缺少必填参数或参数无效
401invalid_api_keyauthentication_errorAPI Key 无效、已禁用或已删除
402insufficient_creditsbilling_error积分余额不足,请充值
403ip_not_allowedpermission_error请求 IP 不在 Key 的白名单中
404model_not_foundinvalid_request_error模型不存在或已停用
404task_not_foundinvalid_request_error任务 ID 不存在
429rate_limit_exceededrate_limit_error请求过于频繁,请降低频率
429spend_limit_exceededbilling_error达到 Key 的消费限额(每小时/每天/总量)
500internal_errorapi_error服务器内部错误
503upstream_errorupstream_error上游 AI 服务返回错误

常见场景

invalid_request (400)

缺少必填字段或参数格式错误时返回。

{
  "error": {
    "code": "invalid_request",
    "message": "'model' is required.",
    "type": "invalid_request_error"
  }
}

insufficient_credits (402)

积分不足。可通过 GET /v1/credits 查询余额,前往 Dashboard > Billing 充值。

invalid_api_key (401)

可能原因:

  • Key 不以 sk- 开头
  • Key 已被禁用或删除
  • 用户账户已被封禁

upstream_error (503)

上游 AI 服务返回错误,可能原因:

  • 输入内容包含敏感或违规信息
  • 上游服务暂时不可用
  • 请求参数不被上游支持

因上游错误导致任务失败时,预扣积分会自动退还。