MAGI-2
Generate a 1080p video with sound from a prompt, first and last frames, or reference images, videos and audio, billed by the output length.
MAGI-2 (product magi) generates a 1080p video from a prompt, a first frame (optionally with a last frame), or reference images, videos and audio, with sound by default. Rendering is slow: a 4-second video takes about 13–17 minutes, a 30-second one up to about 20 minutes. Try short durations first and get the result by webhook. Each mode has its own page with its parameters, price and request examples:
mode | What it does | Docs |
|---|---|---|
text_to_video | Text to video: generated from a prompt alone. | Text to Video |
image_to_video | First and last frame: from a first frame, optionally with a last frame. | First and Last Frame |
reference_to_video | Reference to video: a new video from reference images, videos and audio. | Reference to Video |
Create a task
https://api.nanoapi.ai/v1/tasksUse the shared create endpoint with model: "magi-2.0" and one of the modes above. Parameters every mode takes (required parameters have no defaults; image_urls, video_urls and audio_urls depend on the mode, see its page):
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | magi-2.0 |
mode | string | Yes | text_to_video, image_to_video or reference_to_video. |
prompt | string | Yes | What the video shows, at most 8000 characters. Best written in English. Refer to the files as @Image1, @Video1, @Audio1, see Referring to files. |
resolution | string | Yes | 1080p, the only resolution (send it anyway). |
aspect_ratio | string | Yes | 21:9, 16:9, 4:3, 1:1, 3:4 or 9:16, in every mode (auto isn't accepted). In image_to_video, pick the ratio of the first frame. |
duration | integer | Yes | Output length in seconds, 4–30. Billed per second, see Pricing. |
generate_audio | boolean | No | Whether the output has sound, default true. Doesn't affect the price. |
webhook_url | string | No | Notified when the task succeeds or fails. See Webhooks. |
video_url isn't accepted, and image_to_video can't be combined with reference videos or audio.
Get the result
A 4-second video takes about 13–17 minutes, a 30-second one up to about 20 minutes. Get the result through the webhook if you sent webhook_url (recommended), or poll GET /v1/tasks/{task_id} at most once every 15 seconds until status is succeeded or failed (several tasks at once: ids in List tasks). Leave enough time: a task that's still running after 15 minutes hasn't failed.
Fields specific to MAGI-2 (all fields: The task object):
| Field | MAGI-2 |
|---|---|
outputs[0].url | The generated video, an MP4 (H.264, 25 fps; 1920×1080 at 16:9, 1080×1920 at 9:16, 1248×1664 at 3:4), with AAC sound when generate_audio is true (the default). About 0.24 seconds longer than duration. Kept for 15 days after the task finishes. |
outputs[0].preview_url | A silent, compressed copy 600 pixels wide for previews, see Outputs. |
billing.billed_seconds | The duration. |
input | The parameters you sent; the files and generate_audio only if you sent them. |
Media
Pass public http(s) URLs that download directly: at most 4096 characters, not localhost or a private, loopback or reserved address, and valid until the task finishes (including signed URLs that expire). There's no upload endpoint.
| Parameter | What it is | Modes |
|---|---|---|
image_urls | Images: a first and last frame (up to 2), or reference images (up to 10). | image_to_video, reference_to_video |
video_urls | Reference videos, up to 5. | reference_to_video |
audio_urls | Reference audio, up to 5. | reference_to_video |
Which ones a mode requires is on its page. The files must meet these requirements:
| Requirement | Otherwise the task fails with |
|---|---|
| Every file can be downloaded and read (not corrupt, a supported format) | invalid_media |
| Each reference video 2–30 seconds | video_too_short / video_too_long |
| The reference videos together at most 30 seconds | video_too_long |
| Each reference audio file, and all of them together, at most 30 seconds | invalid_media |
MAGI-2 reads every file only when the video is generated, after the cost has been frozen: none of the above is checked when the task is created. If a file can't be used, the frozen amount is returned in full.
Referring to files in the prompt
In prompt | Refers to |
|---|---|
@Image1, @Image2, … | The images in image_urls, in order. |
@Video1, @Video2, … | The videos in video_urls, in order. |
@Audio1, @Audio2, … | The audio files in audio_urls, in order. |
Each kind is numbered on its own, starting from 1. Say in words what each file is for, for example "The person from @Image1, copying the movements in @Video1".
Pricing
cost = duration × price per second (1080p)Loading the current prices…
Billed seconds are the duration you ask for (4–30), even though the output runs about 0.24 seconds longer. There's one price per second: the mode, aspect ratio, sound in the output (generate_audio) and reference files don't change it.
The cost follows from the request alone, so you can show it before submitting. Current prices: GET /v1/products (the prices row of magi; look the product up by id, not by its position in the list). The task's billing.frozen is the amount that counts; freezing and charging: Billing.
Errors
Request errors
A request that fails returns an HTTP error, and no task is created:
{
"code": 400,
"message": "Input should be '21:9', '16:9', '4:3', '1:1', '3:4' or '9:16' for magi-2.0",
"error": {
"type": "invalid_request",
"param": "aspect_ratio",
"details": null
},
"request_id": "rq_01jb8z9x2c4v6b8n0m1q3w5e7r"
}| HTTP status | error.type | Description |
|---|---|---|
| 400 | invalid_request | A required parameter is missing, a value breaks the rules in the parameter tables on this page or the mode pages (for example auto as aspect_ratio, image_urls in text_to_video, no reference file in reference_to_video, a duration outside 4–30), or a parameter isn't accepted; param names it |
| 401 | invalid_api_key | The API key is invalid, deleted or has been reset |
| 402 | insufficient_balance | Your available balance is 0 |
| 402 | spend_limit_exceeded | One of the API key's spend limits is used up |
| 403 | account_suspended | Your account has been suspended |
| 409 | idempotency_key_reused | The Idempotency-Key was already used with a different request body |
| 429 | rate_limited | Too many requests |
| 500 | internal_error | A server error; the task may have been created |
details and how to handle each error: Create a task → Errors.
Task failures
A created task can still fail: its status turns failed and the reason is in error, with no HTTP status. A failed task is never charged; anything frozen is returned in full.
{
"status": "failed",
"error": {
"type": "video_too_long",
"message": "The video duration must be at most 30 seconds."
}
}error.type | Description |
|---|---|
invalid_media | An image, video or audio file can't be downloaded or read (corrupt or an unsupported format), or a reference audio file is longer than 30 seconds or the reference audio together is |
video_too_long | A reference video is longer than 30 seconds, or the reference videos together are |
video_too_short | A reference video is shorter than 2 seconds |
content_policy | The prompt or a file breaks the content policy (adult content, a protected likeness or copyrighted material) |
insufficient_balance | Your available balance can't cover this task |
spend_limit_exceeded | This task would go over one of the API key's spend limits |
generation_failed | Generation failed |
queue_timeout | Not started within 30 minutes of being queued |
internal_error | An internal error |
Branch on error.type; message is an English explanation you can show your users, and may change. When each reason can happen, whether anything was frozen, and the message texts: Failure reasons.