# 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`