# Magi 2 API Complete API reference for Magi 2 video generation models by Sand AI. ## Model Variants This API supports three model variants: | Model | ID | Description | |-------|----|-------------| | **Magi 2 Text to Video** | `magi-2-text-to-video` | Video generation from a text prompt | | **Magi 2 Image to Video** | `magi-2-image-to-video` | First-frame or first-and-last-frame video generation | | **Magi 2 Reference to Video** | `magi-2-reference-to-video` | Video generation guided by reference images, videos, and audio | ## Magi 2 Text to Video ### Endpoint ``` POST /api/v1/video/task ``` ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model_name` | string | Must be `"magi-2-text-to-video"` | | `prompt` | string | Describe the scene, action, camera work, and sound, up to 5000 characters | | `duration` | integer | Output video duration in whole seconds (4-30). No default value | #### Optional | Parameter | Type | Description | |-----------|------|-------------| | `aspect_ratio` | string | Video aspect ratio: `"16:9"`, `"9:16"`, `"1:1"`, `"4:3"`, `"3:4"`, or `"21:9"`. Defaults to `"16:9"` | | `sound` | boolean | Whether to generate audio. Defaults to `true`. Set to `false` for a silent video | ### Example Request ```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 ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model_name` | string | Must be `"magi-2-image-to-video"` | | `prompt` | string | Describe the scene, action, camera work, and sound, up to 5000 characters | | `duration` | integer | Output video duration in whole seconds (4-30). No default value | | `image_url` | string | Public HTTPS URL of the first-frame image. Use a PNG, JPEG, WebP, or GIF image no larger than 20 MiB | #### Optional | Parameter | Type | Description | |-----------|------|-------------| | `image_end_url` | string | Public HTTPS URL of the last-frame image. Requires `image_url`. Use a PNG, JPEG, WebP, or GIF image no larger than 20 MiB | | `aspect_ratio` | string | Video aspect ratio: `"16:9"`, `"9:16"`, `"1:1"`, `"4:3"`, `"3:4"`, or `"21:9"`. Defaults to `"16:9"` | | `sound` | boolean | Whether to generate audio. Defaults to `true`. Set to `false` for a silent video | ### Example Request ```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 ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model_name` | string | Must be `"magi-2-reference-to-video"` | | `prompt` | string | Describe the scene, action, camera work, and sound, up to 5000 characters. Use `<<>>`, `<<>>`, or `<<>>` to refer to specific media items in the prompt | | `duration` | integer | Output video duration in whole seconds (4-30). No default value | #### Reference Media All reference media are optional and can be combined in one request. If you omit all three arrays, the model generates video from the prompt alone. | Parameter | Type | Description | |-----------|------|-------------| | `images` | string[] | Up to 10 public HTTPS reference image URLs, referenced in array order. Each image must be smaller than 30 MB and in PNG, JPEG, WebP, or GIF format | | `videos` | string[] | Up to 5 public HTTPS reference video URLs in MP4 or MOV format, referenced in array order. Each clip must be 2-30 seconds and at most 200 MB. The combined video duration must not exceed 30 seconds | | `audios` | string[] | Up to 5 public HTTPS reference audio URLs in WAV or MP3 format, referenced in array order. Each clip must be 2-30 seconds and at most 15 MB. The combined audio duration must not exceed 30 seconds | #### @ (AT) Reference Placeholders The @ (AT) reference feature uses numbered `<<<...>>>` placeholders in the prompt. Numbering starts at `1` for each media type and follows the order of its array. | Placeholder | Referenced value | |-------------|------------------| | `<<>>` | `images[0]` | | `<<>>` | `images[1]` | | `<<>>` | `videos[0]` | | `<<>>` | `audios[0]` | #### Optional | Parameter | Type | Description | |-----------|------|-------------| | `aspect_ratio` | string | Video aspect ratio: `"16:9"`, `"9:16"`, `"1:1"`, `"4:3"`, `"3:4"`, or `"21:9"`. Defaults to `"16:9"` | | `sound` | boolean | Whether to generate audio. Defaults to `true`. Set to `false` for a silent video | ### Example Request ```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) Reference-to-Video Request Example ```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'] } ``` ## Response Format ### Initial Response All models return a `task_id` for polling: ```json { "code": 0, "message": "success", "data": { "task_id": "{task_id}", "response_url": "https://api.flaq.ai/api/v1/video/{task_id}", "task_status": "submitted" } } ``` ### Polling Response Poll `GET /api/v1/video/{taskId}` to check status: ```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" } ] } } } ``` ### Status Values - `submitted`: Task accepted and waiting to be processed - `processing`: Video generation in progress - `succeed`: Video generation completed - `failed`: Video generation failed ## Best Practices 1. **Prompt**: Describe the scene, action, camera work, and any sound you want to hear 2. **Frame Images**: Always supply `image_url` for Image-to-Video, including when you provide `image_end_url` 3. **Reference Ordering**: Keep `images`, `videos`, and `audios` in the order you want to reference them in `prompt` 4. **Sound**: Set `sound` to `false` when you want a silent video