MAGI-2 API Reference (Sand.ai MAGI-2)
MAGI-2 API is an independent REST API platform for Sand.ai's MAGI-2 model. Call POST /v1/videos/tasks to start a render, poll GET /v1/tasks/:task_id every 8 seconds, and archive the 1080p 25fps MP4 within 72 hours.
Authentication & Gateway URL
Authenticate every request using HTTP Bearer auth headers: Content-Type: application/json and Authorization: Bearer <MAGI2_API_KEY>.
Manage your account credentials in Settings -> API Keys and fund usage balance in Settings -> Credits.
Core Endpoints
Backend integration spans five endpoints for creating video tasks, polling status, listing history, uploading local files, and checking credit usage.
| Method | Endpoint | Responsibility | Response |
|---|---|---|---|
| POST | /v1/videos/tasks | Create an asynchronous MAGI-2 generation task and return task ID | 201 Created |
| GET | /v1/tasks/{task_id} | Query task status (queued, processing, succeeded, failed) and output URL | 200 OK |
| GET | /v1/tasks | List recent generation tasks belonging to the authenticated key | 200 OK |
| POST | /v1/files | Upload local image/audio (<=50 MB) or video (<=100 MB) for HTTPS URLs | 201 Created |
| GET | /v1/usage?period=7d | Inspect aggregated credit consumption over 24h, 7d, 30d, or all | 200 OK |
Four Input Modes & Mutual-Exclusion Rules
MAGI-2 classifies each task payload automatically from present input arrays and rejects conflicting parameter sets.
Omit images[] and all reference_* arrays. Set aspect_ratio to 16:9, 9:16, 1:1, 4:3, 3:4, or 21:9.
Provide images[] with 1 public HTTPS URL. MAGI-2 locks start composition; omit aspect_ratio.
Provide images[] with 2 public HTTPS URLs (start, end). MAGI-2 interpolates motion between frames; omit aspect_ratio.
Provide reference_images (<=10), reference_videos (<=5), and reference_audios (<=5). Bind them inline via @image1, @video1, @audio1.
Request Body Parameters (POST /v1/videos/tasks)
All fields below match live validation constraints enforced on model="magi-2" before tasks enter the queue.
| Parameter | Type | Default | Constraints & Behavior |
|---|---|---|---|
| model | string (req) | magi-2 | Required literal "magi-2". Identifies Sand.ai MAGI-2 execution pipeline. |
| prompt | string (req) | - | Required UTF-8 text directive, 1–5000 characters. Supports @imageN, @videoN, @audioN. |
| duration | integer | 5 | Integer seconds between 4 and 30 inclusive. Bills linearly at $0.088/second. |
| aspect_ratio | enum | 16:9 | Allowed values: 16:9, 9:16, 1:1, 4:3, 3:4, 21:9. Forbidden when images[] is set. |
| resolution | enum | 1080p | Fixed to "1080p" (25 fps). Passing 480p or 720p returns 422. |
| generate_audio | boolean | true | Generates synchronized bilingual voice and ambient sound effects alongside video. |
| seed | integer | random | Optional integer from 0 to 2147483647 for reproducible noise initialization. |
| images | string[] | [] | 1 or 2 public HTTPS URLs. Sets First-Frame or First-Last Keyframe mode. |
| reference_images | string[] | [] | Up to 10 public HTTPS image URLs referenced inline as @image1..@image10. |
| reference_videos | string[] | [] | Up to 5 public HTTPS video URLs (2–30s each, 30s total) bound via @video1..@video5. |
| reference_audios | string[] | [] | Up to 5 public HTTPS audio URLs (2–30s each, 30s total) bound via @audio1..@audio5. |
| callback_url | string | - | Optional HTTPS webhook URL (<=2048 chars) receiving signed task updates. |
Asynchronous Submit & Poll Examples
Pass an explicit Idempotency-Key header (<=255 chars, 24h window) on POST /v1/videos/tasks so retries never create duplicate jobs.
curl -X POST "https://magi2api.net/api/v1/videos/tasks" \
-H "Authorization: Bearer $MAGI2_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: magi2-shot-001" \
-d '{
"model": "magi-2",
"prompt": "@image1 stands inside the workshop from @image2. Track her hand movement matching @video1 while preserving the acoustic cadence of @audio1.",
"duration": 8,
"aspect_ratio": "16:9",
"resolution": "1080p",
"generate_audio": true,
"reference_images": [
"https://example.com/refs/character.png",
"https://example.com/refs/workshop.png"
],
"reference_videos": ["https://example.com/refs/motion.mp4"],
"reference_audios": ["https://example.com/refs/voice.mp3"]
}'Response Lifecycle & 72-Hour Retention
Task creation returns HTTP 201 containing data.id, initial status ("queued"), and poll_after_seconds (8 by default).
Clients poll GET /v1/tasks/:task_id at or above poll_after_seconds until data.status transitions to "succeeded" or "failed".
Completed data.output.url links expire after 72 hours. Services must download and persist generated MP4 files into durable R2 or S3 storage immediately.
{
"data": {
"id": "tsk_01JXYZMAGI2DEMO",
"model": "magi-2",
"status": "queued",
"created_at": "2026-11-27T04:10:00Z"
},
"poll_after_seconds": 8
}Uploading Local Media (POST /v1/files)
Upload local assets to POST /v1/files before submitting a generation job. Images and audio accept up to 50 MB; videos accept up to 100 MB.
HTTP Error Reference
The API returns standard HTTP status codes paired with structured JSON error descriptions.
| Status Code | Root Cause & Client Action |
|---|---|
| 400 Bad Request | Malformed JSON body or missing required parameters. Fix syntax before retrying. |
| 401 Unauthorized | Missing or invalid Bearer API key. Check your key status inside the console. |
| 402 Payment Required | Insufficient credit balance for this render duration. Top up your console balance and retry. |
| 404 Not Found | Task ID does not exist or belongs to a different account key. |
| 422 Unprocessable | Validation failed (e.g., images + reference_* conflict, 720p requested, or aspect_ratio sent with images[]). |
| 429 Rate Limited | Account rate limit exceeded. Apply exponential backoff respecting Retry-After. |
| 5xx Server Error | Upstream node error. Retry safely with the same Idempotency-Key; failed tasks refund 100%. |