Quick start
From an empty account to a downloaded clip in three calls. The examples use a five-second text-to-video request, the cheapest useful test.
- 1
Get a key
Buy any credit pack (from $10), open Settings → API keys and create a key. It is shown once and starts with magi2api_. Keep it on your server, never in browser code.
- 2
Submit the job
POST your prompt to /videos. The reply comes back at once with HTTP 202, the job id and the credits taken (100 for five seconds).
- 3
Poll, then download
GET /videos/{id} every 10–15 seconds. When status is completed, download video_url; the link works for a day, so copy the file to your own storage.
# 1. Submit (returns 202 with the job id)
curl -X POST https://magi2api.app/api/v1/videos \
-H "Authorization: Bearer $MAGI2API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A lighthouse keeper climbs a spiral staircase at dusk, lantern swinging; wind and waves outside, his boots ringing on iron steps.",
"duration": 5,
"aspect_ratio": "16:9"
}'
# 2. Poll until "status" is "completed" or "failed"
curl https://magi2api.app/api/v1/videos/JOB_ID \
-H "Authorization: Bearer $MAGI2API_KEY"
# 3. Download the clip from "video_url"
curl -L -o clip.mp4 "VIDEO_URL"import os, time, requests
BASE = "https://magi2api.app/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['MAGI2API_KEY']}"}
job = requests.post(f"{BASE}/videos", headers=HEADERS, json={
"prompt": "A lighthouse keeper climbs a spiral staircase at dusk, lantern swinging; wind and waves outside, his boots ringing on iron steps.",
"duration": 5,
"aspect_ratio": "16:9",
}).json()
while job.get("status") in ("queued", "processing"):
time.sleep(15)
job = requests.get(f"{BASE}/videos/{job['id']}", headers=HEADERS).json()
if job.get("status") == "completed":
with open("clip.mp4", "wb") as f:
f.write(requests.get(job["video_url"]).content)
else:
print(job.get("error"))const BASE = "https://magi2api.app/api/v1";
const headers = {
Authorization: `Bearer ${process.env.MAGI2API_KEY}`,
"Content-Type": "application/json",
};
let job = await fetch(`${BASE}/videos`, {
method: "POST",
headers,
body: JSON.stringify({
prompt: "A lighthouse keeper climbs a spiral staircase at dusk, lantern swinging; wind and waves outside, his boots ringing on iron steps.",
duration: 5,
aspect_ratio: "16:9",
}),
}).then((r) => r.json());
while (job.status === "queued" || job.status === "processing") {
await new Promise((done) => setTimeout(done, 15_000));
job = await fetch(`${BASE}/videos/${job.id}`, { headers }).then((r) => r.json());
}
if (job.status === "completed") {
const clip = await fetch(job.video_url);
await (await import("node:fs/promises")).writeFile(
"clip.mp4",
Buffer.from(await clip.arrayBuffer())
);
} else {
console.error(job.error);
}Keys and access
Send the key in the Authorization header as a bearer token. An x-api-key header with the bare key is accepted too, for clients that cannot set Authorization.
A key belongs to one account and spends that account's credits. Create as many as you like (one per app or environment makes them easy to revoke) and delete a leaked one from the same settings page; it stops working on the next request.
Generating needs one completed credit pack purchase on the account. Signing up alone does not open the API, and new accounts start with no credits. Reading /credits works for any valid key.
Authorization: Bearer magi2api_xxxxxxxxxxxxxxxxPricing
One flat rate for every mode: 20 credits for each second you ask for, with sound included and no extra charge for reference files. A credit is worth 1 US cent, so the API costs $0.20 per second of video.
| Clip length | Credits | USD |
|---|---|---|
| 4 s | 80 | $0.80 |
| 5 s | 100 | $1.00 |
| 10 s | 200 | $2.00 |
| 15 s | 300 | $3.00 |
| 30 s | 600 | $6.00 |
| Credit pack | Credits | Seconds of video | 5 s clips |
|---|---|---|---|
| $10 | 1,000 | 50 | 10 |
| $25 | 2,500 | 125 | 25 |
| $50 | 5,000 | 250 | 50 |
| $100 | 10,000 | 500 | 100 |
- Credits are taken when the job is accepted, for the duration you requested.
- A job that fails gives its credits back automatically. Its status then shows credits_charged: 0 and error.refunded: true.
- A prompt that is refused, or that could not be checked because the checker was briefly down, is never charged.
- Packs are one-time purchases with no subscription. Credits from any pack work in the API and in the browser playground.
Buy packs on the pricing page while signed in. Your balance is visible in the dashboard and through GET /credits. Credit packs
Create a video
POST/api/v1/videos
Books one clip. Files are passed as public https links; the API downloads each one before the job is accepted, so a dead link fails the request instead of the render.
| Field | Type | Default | Notes |
|---|---|---|---|
| model | string | magi-2 | Only magi-2 is served. |
| prompt | string | "" | Up to 5,000 characters. Required for text and reference jobs (at least 5 characters), optional when image_url is sent. |
| duration | integer | 5 | Whole seconds, 4 to 30. Billed at 20 credits each. |
| aspect_ratio | string | 16:9 | 16:9, 9:16, 1:1, 4:3, 3:4, 21:9. Ignored for image-to-video, which keeps the shape of your image. |
| generate_audio | boolean | true | false for a silent clip. The price is the same either way. |
| image_url | string | — | First frame. Turns the job into image-to-video. |
| last_image_url | string | — | Final frame. Only together with image_url. |
| reference_images | string[] | — | Up to 9 images. Turns the job into reference-to-video. |
| reference_videos | string[] | — | Up to 3 clips. |
| reference_audios | string[] | — | Up to 3 audio files. |
Unknown fields are rejected with 400 invalid_request, so a typo in a field name does not silently fall back to a default.
{
"image_url": "https://example.com/frames/harbour-first.jpg",
"last_image_url": "https://example.com/frames/harbour-last.jpg",
"prompt": "The fishing boat slides out of the harbour as gulls lift off.",
"duration": 8
}{
"prompt": "The woman from @image_1 dances in the street from @image_2, moving like the dancer in @video_1, to the beat of @audio_1.",
"reference_images": [
"https://example.com/ref/dancer.png",
"https://example.com/ref/street.jpg"
],
"reference_videos": [
"https://example.com/ref/moves.mp4"
],
"reference_audios": [
"https://example.com/ref/beat.mp3"
],
"duration": 10,
"aspect_ratio": "9:16"
}{
"id": "f3a9c2e1-7b44-4d0e-9a51-2c6b8e0d4f17",
"object": "video",
"model": "magi-2",
"mode": "text-to-video",
"status": "queued",
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true,
"credits_charged": 100,
"created_at": "2026-11-25T18:04:12.000Z",
"status_url": "https://magi2api.app/api/v1/videos/f3a9c2e1-7b44-4d0e-9a51-2c6b8e0d4f17"
}Get a video
GET/api/v1/videos/{id}
Returns the job as it stands. Only the account that created a job can read it; any other key gets 404.
- queued
- Accepted and waiting for a render slot upstream.
- processing
- Rendering.
- completed
- Done. video_url is a signed link to the MP4, valid for 24 hours from this response; ask again for a fresh one.
- failed
- Not produced. error.message says why and error.refunded tells you the credits went back.
| Field | Meaning |
|---|---|
| id | Job id, as returned when you created it. |
| mode | text-to-video, image-to-video or reference-to-video, decided by which fields you sent. |
| status | queued, processing, completed or failed. |
| aspect_ratio | The ratio you asked for, or null for image-to-video (the image decides). |
| credits_charged | What the job costs you now: the full price while it runs or once it completes, 0 after a refund. |
| video_url | Signed MP4 link when completed, otherwise null. |
| video_url_expires_in | Seconds until video_url stops working. |
| error | null, or { message, refunded } for a failed job. |
| created_at / completed_at | ISO 8601 timestamps, UTC. |
{
"id": "f3a9c2e1-7b44-4d0e-9a51-2c6b8e0d4f17",
"object": "video",
"model": "magi-2",
"mode": "text-to-video",
"status": "completed",
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "1080p",
"credits_charged": 100,
"video_url": "https://magi2api.app/api/storage/shared/videos/...mp4?expires=...&signature=...",
"video_url_expires_in": 86400,
"error": null,
"created_at": "2026-11-25T18:04:12.000Z",
"completed_at": "2026-11-25T18:09:47.000Z"
}{
"id": "f3a9c2e1-7b44-4d0e-9a51-2c6b8e0d4f17",
"status": "failed",
"credits_charged": 0,
"video_url": null,
"error": {
"message": "The video could not be generated on the model side. Please try again.",
"refunded": true
}
}Most clips finish in about 15 to 20 minutes, longer at peak times. When the main inference route turns a job down, cannot start it within 30 minutes or fails it, the job moves once to a backup route, which usually takes another 3 to 10 minutes. A job that still has no clip is given up and refunded.
Check your balance
GET/api/v1/credits
The credit balance of the account the key belongs to, and the current API rate. Useful as a cheap check that a key works before you send a paid job.
{
"object": "credits",
"balance": 900,
"magi_2_credits_per_second": 20
}Input modes
There is one endpoint for all three modes. The fields you send decide which one runs, and the mode comes back in the response.
Text to video
prompt
Describe the scene, the action, the camera and what should be heard. Lines of dialogue written into the prompt come out spoken, with matching lip movement. aspect_ratio applies.
Image to video
image_url, optional last_image_url, optional prompt
The clip opens on your image and, with last_image_url, ends on the second one. The frame shape follows the image: aspect_ratio is not applied, so crop the image to the ratio you want before you send it.
Reference to video
prompt plus reference_images / reference_videos / reference_audios
Up to 12 files in total (9 images, 3 clips, 3 audio). Point at them in the prompt by kind and position: @image_1, @video_1, @audio_1 (the @Image1 form works too). Cannot be combined with image_url.
| Field kind | Accepted formats |
|---|---|
| Images | JPEG, PNG, WebP |
| Video | MP4, MOV, WebM |
| Audio | MP3, WAV, M4A, AAC, OGG |
Each file at most 25 MB, served over https with a correct Content-Type header. A link that answers with an HTML page (a sharing page instead of the file itself) is rejected as unsupported_file.
Errors
Every error has the same shape: an HTTP status and a JSON body with a stable code and a sentence you can show a user. Branch on code, not on message.
{
"error": {
"code": "too_many_active_jobs",
"message": "An account can have 2 videos queued or rendering at once. Wait for one to finish, then send this request again."
}
}| HTTP | code | What happened | What to do |
|---|---|---|---|
| 400 | invalid_json / invalid_request | The body is not JSON, a field is missing, out of range or unknown. | Fix the field named in the message. |
| 400 | prompt_rejected | The prompt asks for content Magi 2 does not make. | Rewrite the prompt. Nothing was charged. |
| 400 | file_unreachable | A link could not be downloaded (timeout, 4xx/5xx). | Check the link is public and direct. |
| 400 | unsupported_file / file_too_large | Wrong file type for that field, empty, or over 25 MB. | Convert or shrink the file. |
| 401 | missing_api_key / invalid_api_key | No key, or a key that is wrong, expired or deleted. | Send a current key. |
| 402 | insufficient_credits | The balance is below the price of the clip. | Top up, or ask for fewer seconds. |
| 403 | purchase_required | The account has not bought a credit pack yet. | Buy any pack, then retry with the same key. |
| 403 | account_suspended | The account has been suspended. | Contact support@magi2api.app. |
| 404 | not_found | No job with that id on this account. | Check the id and the key. |
| 405 | method_not_allowed | Wrong HTTP method, for example GET /videos. | Use the method in the Allow header. |
| 429 | too_many_active_jobs | 2 videos are already queued or rendering on the account. | Wait for one to finish, then resend. |
| 503 | moderation_unavailable | The prompt check could not run just now. | Retry in a minute. Nothing was charged. |
| 500 | internal_error | Something failed on our side. | Retry; if it repeats, email us the time and request. |
A job that was accepted and later fails does not return an error code from POST: it shows status failed on GET /videos/{id}, with the reason in error.message and the credits back on the balance.
Limits
- 2 videos queued or rendering per account at once, counting playground jobs too. The next POST gets 429 until one finishes.
- Clip length: whole seconds from 4 to 30. Output is always 1080p at 25 fps.
- Reference files: 12 per request at most (9 images, 3 clips, 3 audio), 25 MB each.
- No per-key request quota on polling or balance checks; poll every 10–15 seconds, there is nothing to gain from polling faster.
- Result links expire after 24 hours. The clip itself stays in your account history, where you can also download it.
- There are no webhooks: completion is read by polling GET /videos/{id}.
Magi 2 API FAQ
Is this the official Sand.ai API?
No. Magi2API is an independent service: it runs Sand.ai’s MAGI-2 through third-party inference providers and sells access by the second. Sand.ai has not published a public API or price of its own.
Is there a free tier or trial?
No. Accounts start at zero credits and the API opens with the first pack; the smallest is $10 for 1,000 credits, enough for 50 seconds of video. A failed job costs nothing, so you only pay for clips you receive.
How much does a Magi 2 API call cost?
20 credits ($0.20) per second requested, the same for every mode, with sound included: $1.00 for a five-second clip and $6.00 for the full 30 seconds.
How long does one video take?
Usually 15 to 20 minutes from POST to completed, depending on the clip length and how busy the upstream queue is. Plan for longer at peak times and poll rather than holding a request open.
Can I set the aspect ratio for image-to-video?
No. When image_url is sent the clip takes the shape of the image, and aspect_ratio is ignored (the response shows aspect_ratio: null). Crop the image first.
Do you send a webhook when the video is ready?
No. Poll GET /videos/{id}; status changes to completed or failed, and a completed job carries the download link.
Where do I find my API key?
Signed in, open Settings → API keys. A key is shown in full only once, when it is created; if you lose it, delete it and create another.
Ready for your first clip?
Buy a pack, create a key and send the five-second example above: 100 credits, refunded if it fails.