# Magi 2 API Sand AI 的 Magi 2 视频生成模型完整 API 参考。 ## 模型版本 此 API 支持以下三个模型版本: | 模型 | ID | 说明 | |-------|----|-------------| | **Magi 2 Text to Video** | `magi-2-text-to-video` | 根据文本提示词生成视频 | | **Magi 2 Image to Video** | `magi-2-image-to-video` | 根据首帧或首尾帧生成视频 | | **Magi 2 Reference to Video** | `magi-2-reference-to-video` | 参考图像、视频和音频生成视频 | ## Magi 2 Text to Video ### 接口地址 ``` POST /api/v1/video/task ``` ### 请求参数 #### 必填参数 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `model_name` | string | 必须为 `"magi-2-text-to-video"` | | `prompt` | string | 描述场景、动作、镜头运用和声音,最多 5000 个字符 | | `duration` | integer | 输出视频的时长,以整秒为单位(4–30 秒),无默认值 | #### 可选参数 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `aspect_ratio` | string | 视频宽高比,可选 `"16:9"`、`"9:16"`、`"1:1"`、`"4:3"`、`"3:4"` 或 `"21:9"`,默认为 `"16:9"` | | `sound` | boolean | 是否生成音频。默认为 `true`,设为 `false` 可生成无声视频 | ### 请求示例 ```javascript const response = await fetch('https://api.flaq.ai/api/v1/video/task', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ model_name: 'magi-2-text-to-video', prompt: 'The camera glides toward a lighthouse at dusk as waves crash against the rocks', duration: 8, aspect_ratio: '16:9', sound: true }) }); const { data } = await response.json(); const taskId = data.task_id; ``` ## Magi 2 Image to Video ### 请求参数 #### 必填参数 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `model_name` | string | 必须为 `"magi-2-image-to-video"` | | `prompt` | string | 描述场景、动作、镜头运用和声音,最多 5000 个字符 | | `duration` | integer | 输出视频的时长,以整秒为单位(4–30 秒),无默认值 | | `image_url` | string | 首帧图像的公开 HTTPS URL。支持 PNG、JPEG、WebP 或 GIF,文件大小不得超过 20 MiB | #### 可选参数 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `image_end_url` | string | 尾帧图像的公开 HTTPS URL,必须同时提供 `image_url`。支持 PNG、JPEG、WebP 或 GIF,文件大小不得超过 20 MiB | | `aspect_ratio` | string | 视频宽高比,可选 `"16:9"`、`"9:16"`、`"1:1"`、`"4:3"`、`"3:4"` 或 `"21:9"`,默认为 `"16:9"` | | `sound` | boolean | 是否生成音频。默认为 `true`,设为 `false` 可生成无声视频 | ### 请求示例 ```javascript { model_name: 'magi-2-image-to-video', image_url: 'https://example.com/first-frame.jpg', image_end_url: 'https://example.com/last-frame.jpg', prompt: 'The camera slowly pulls back to reveal a waterfall and the forest around it', duration: 8, aspect_ratio: '16:9', sound: false } ``` ## Magi 2 Reference to Video ### 请求参数 #### 必填参数 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `model_name` | string | 必须为 `"magi-2-reference-to-video"` | | `prompt` | string | 描述场景、动作、镜头运用和声音,最多 5000 个字符。在提示词中使用 `<<>>`、`<<>>` 或 `<<>>` 引用特定素材 | | `duration` | integer | 输出视频的时长,以整秒为单位(4–30 秒),无默认值 | #### 参考素材 各类参考素材均为可选项,可在同一请求中组合使用。如果省略全部三个数组,模型将仅根据提示词生成视频。 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `images` | string[] | 最多提供 10 个参考图像的公开 HTTPS URL,按数组顺序引用。每张图像须小于 30 MB,格式为 PNG、JPEG、WebP 或 GIF | | `videos` | string[] | 最多提供 5 个 MP4 或 MOV 参考视频的公开 HTTPS URL,按数组顺序引用。每段视频时长须为 2–30 秒,大小不得超过 200 MB。视频总时长不得超过 30 秒 | | `audios` | string[] | 最多提供 5 个 WAV 或 MP3 参考音频的公开 HTTPS URL,按数组顺序引用。每段音频时长须为 2–30 秒,大小不得超过 15 MB。音频总时长不得超过 30 秒 | #### @ (AT) 引用占位符 @ (AT) 引用功能通过提示词中带编号的 `<<<...>>>` 占位符引用素材。每类素材都从 `1` 开始编号,顺序与对应数组一致。 | 占位符 | 引用的值 | |-------------|------------------| | `<<>>` | `images[0]` | | `<<>>` | `images[1]` | | `<<>>` | `videos[0]` | | `<<>>` | `audios[0]` | #### 可选参数 | 参数 | 类型 | 说明 | |-----------|------|-------------| | `aspect_ratio` | string | 视频宽高比,可选 `"16:9"`、`"9:16"`、`"1:1"`、`"4:3"`、`"3:4"` 或 `"21:9"`,默认为 `"16:9"` | | `sound` | boolean | 是否生成音频。默认为 `true`,设为 `false` 可生成无声视频 | ### 请求示例 ```javascript { model_name: 'magi-2-reference-to-video', prompt: 'Use the reference image for the subject, the reference video for the camera movement, and the reference audio for the ambience', duration: 8, aspect_ratio: '16:9', sound: true, images: ['https://example.com/subject-reference.jpg'], videos: ['https://example.com/camera-movement-reference.mp4'], audios: ['https://example.com/ambience-reference.mp3'] } ``` ### 使用 @ (AT) 引用素材生成视频的请求示例 ```javascript { model_name: 'magi-2-reference-to-video', prompt: 'Show the cyclist from <<>> on the trail in <<>>. Follow the camera movement in <<>> and use <<>> as a reference for the forest ambience', duration: 10, aspect_ratio: '16:9', sound: true, images: [ 'https://example.com/cyclist-reference.jpg', 'https://example.com/forest-trail-reference.png' ], videos: ['https://example.com/camera-movement-reference.mp4'], audios: ['https://example.com/forest-ambience-reference.mp3'] } ``` ## 响应格式 ### 初始响应 所有模型都会返回 `task_id`,供轮询使用: ```json { "code": 0, "message": "success", "data": { "task_id": "{task_id}", "response_url": "https://api.flaq.ai/api/v1/video/{task_id}", "task_status": "submitted" } } ``` ### 轮询响应 轮询 `GET /api/v1/video/{taskId}` 以检查任务状态: ```json { "code": 0, "message": "success", "data": { "task_id": "{task_id}", "response_url": "https://api.flaq.ai/api/v1/video/{task_id}", "task_status": "succeed", "task_status_msg": null, "task_result": { "videos": [ { "url": "https://example.com/generated-video.mp4" } ] } } } ``` ### 状态值 - `submitted`:任务已接受,等待处理 - `processing`:正在生成视频 - `succeed`:视频生成完成 - `failed`:视频生成失败 ## 最佳实践 1. **提示词**:描述场景、动作、镜头运用以及想听到的声音 2. **首尾帧图像**:使用图生视频时始终提供 `image_url`,即使提供了 `image_end_url` 也必须如此 3. **参考素材顺序**:按希望在 `prompt` 中引用素材的顺序排列 `images`、`videos` 和 `audios` 中的条目 4. **声音**:如需无声视频,将 `sound` 设为 `false`