01
One Endpoint, Three MAGI-2 Models
Call POST /api/v1/magi-2/generations and switch between text-to-video, first/last frame image-to-video, and multimodal reference-to-video using the model field.
DEVELOPER API · V1
Generate 1080p AI videos with synchronized audio programmatically through one REST endpoint. Share the exact same credit ledger and generation history as the MAGI-2 web studio.
01
Call POST /api/v1/magi-2/generations and switch between text-to-video, first/last frame image-to-video, and multimodal reference-to-video using the model field.
02
Every MAGI-2 API request deducts from your existing account credit balance and appears automatically in your Personal Center History and Credit Ledger.
03
Pass an HTTPS webhook_url and optional webhook_secret for HMAC-SHA256 verified callbacks, or poll GET /api/v1/magi-2/generations/{id} anytime.
04
Available to paid accounts (any active subscription or credit pack) at the same 10 credits/second rate. Failed or timed-out tasks automatically refund credits in full.
AUTHENTICATION & BASE URL
Create and manage keys in Personal Center → API Keys. All requests use HTTPS and require a paid account (an active subscription or purchased credit pack).
Base URL
https://magi-2ai.org/api/v1Authorization Header
Idempotency Header (Optional)
Send Idempotency-Key on POST /api/v1/magi-2/generations so safe network retries return the original task without charging credits twice.
API generation requires a paid account with an active subscription or credit pack purchase. Free trial accounts can create keys but must upgrade before submitting jobs.
QUICK START
Choose a model mode and language below. Pass public HTTPS URLs for frame or reference media—no separate upload step required.
curl -X POST "https://magi-2ai.org/api/v1/magi-2/generations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: req_20261126_001" \
-d '{
"model": "magi-2/text-to-video",
"prompt": "A cinematic wide shot of a bullet train gliding over a misty mountain bridge at dawn, warm golden sunlight, subtle rail rumble.",
"aspect_ratio": "16:9",
"duration": 4,
"generate_audio": true,
"webhook_url": "https://your-app.example.com/webhooks/magi-2",
"webhook_secret": "whsec_replace_with_at_least_16_chars"
}'# 1. Poll generation status
curl -X GET "https://magi-2ai.org/api/v1/magi-2/generations/TASK_ID" \
-H "Authorization: Bearer YOUR_API_KEY"
# 2. Check remaining credit balance
curl -X GET "https://magi-2ai.org/api/v1/credits" \
-H "Authorization: Bearer YOUR_API_KEY"ENDPOINTS
All endpoints live under /api/v1 and accept/return application/json.
| Method | Path | Description |
|---|---|---|
| POST | /api/v1/magi-2/generations | Create a MAGI-2 video generation job (text-to-video, image-to-video, or reference-to-video). Supports Idempotency-Key and webhook_url. |
| GET | /api/v1/magi-2/generations/{id} | Retrieve task status, final video_url, credit cost, and error details. Automatically settles timed-out tasks and refunds credits. |
| GET | /api/v1/magi-2/generations | List your MAGI-2 generations (web and API shared). Supports ?page=1&limit=20 (max 50) and optional ?status=success|failed|pending|processing. |
| GET | /api/v1/credits | Query your current remaining credit balance, paid entitlement status, and MAGI-2 per-second rate. |
REQUEST SCHEMA
Select one of the three MAGI-2 models and supply its mode-specific fields. Publicly accessible HTTPS URLs are accepted directly for images, videos, and audio.
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | One of "magi-2/text-to-video", "magi-2/image-to-video", or "magi-2/reference-to-video". |
| prompt | string | Conditional | Required for text-to-video and reference-to-video; optional for image-to-video. Up to 15,000 characters. |
| duration | integer | No | Output clip length in seconds, integer from 4 to 30. Default: 4. Billed at 10 credits per second. |
| aspect_ratio | string | No | For text-to-video and reference-to-video: "16:9", "9:16", "1:1", "4:3", "3:4", or "21:9" (default "16:9"). For image-to-video, omit or pass "auto" (follows first frame). |
| generate_audio | boolean | No | Generate synchronized dialogue, sound effects, and ambience. Default: true. |
| seed | integer | No | Optional reproducibility seed between 0 and 2147483647. |
| webhook_url | string (HTTPS) | No | Public HTTPS endpoint to receive a POST callback when the task reaches success, failed, or canceled. |
| webhook_secret | string | No | Optional 16–256 character secret used to sign webhook payloads via HMAC-SHA256 in the X-Magi2-Signature header. Requires webhook_url. |
| Parameter | Type | Required | Description |
|---|---|---|---|
| first_frame_url | string (URL) | Yes | Publicly accessible image URL (JPG, PNG, or WebP) used as the opening frame. Alias: image. |
| last_frame_url | string (URL) | No | Optional closing frame image URL to guide transitions between start and end frames. Alias: last_image. |
| Parameter | Type | Required | Description |
|---|---|---|---|
| reference_image_urls | string[] | At least 1 media | Up to 10 public image URLs for character, product, or style consistency. Alias: images. |
| reference_video_urls | string[] | At least 1 media | Up to 5 public video URLs (MP4/MOV, 2–30s each) for motion or camera reference. Alias: videos. |
| reference_audio_urls | string[] | At least 1 media | Up to 5 public audio URLs (MP3/WAV, 2–30s each) for voice or music guidance. Alias: audios. |
RESPONSE OBJECT
Tasks transition from pending → processing → success (or failed / canceled). Once complete, video_url contains the persistent MP4 URL.
{
"id": "8f3b2c1a-4d5e-4f6a-9b7c-1234567890ab",
"object": "magi-2.generation",
"model": "magi-2/text-to-video",
"status": "pending",
"prompt": "A cinematic wide shot of a bullet train gliding over a misty mountain bridge at dawn...",
"duration": 4,
"resolution": "1080p",
"aspect_ratio": "16:9",
"generate_audio": true,
"seed": null,
"cost_credits": 40,
"credits_refunded": false,
"video_url": null,
"videos": [],
"error": null,
"webhook_url": "https://your-app.example.com/webhooks/magi-2",
"created_at": "2026-11-26T14:00:00.000Z",
"updated_at": "2026-11-26T14:00:01.000Z"
}{
"id": "8f3b2c1a-4d5e-4f6a-9b7c-1234567890ab",
"object": "magi-2.generation",
"model": "magi-2/text-to-video",
"status": "success",
"prompt": "A cinematic wide shot of a bullet train gliding over a misty mountain bridge at dawn...",
"duration": 4,
"resolution": "1080p",
"aspect_ratio": "16:9",
"generate_audio": true,
"seed": null,
"cost_credits": 40,
"credits_refunded": false,
"video_url": "https://cdn.example.com/kie/video/task-0.mp4",
"videos": [
"https://cdn.example.com/kie/video/task-0.mp4"
],
"error": null,
"webhook_url": "https://your-app.example.com/webhooks/magi-2",
"created_at": "2026-11-26T14:00:00.000Z",
"updated_at": "2026-11-26T14:01:18.000Z"
}WEBHOOKS
Provide webhook_url when creating a generation to avoid constant polling. We send an HTTPS POST request as soon as the task reaches a terminal state (success, failed, or canceled).
{
"event": "generation.completed",
"timestamp": 1764165678,
"data": {
"id": "8f3b2c1a-4d5e-4f6a-9b7c-1234567890ab",
"object": "magi-2.generation",
"model": "magi-2/text-to-video",
"status": "success",
"duration": 4,
"resolution": "1080p",
"aspect_ratio": "16:9",
"generate_audio": true,
"cost_credits": 40,
"credits_refunded": false,
"video_url": "https://cdn.example.com/kie/video/task-0.mp4",
"videos": ["https://cdn.example.com/kie/video/task-0.mp4"],
"error": null,
"created_at": "2026-11-26T14:00:00.000Z",
"updated_at": "2026-11-26T14:01:18.000Z"
}
}import crypto from "node:crypto";
export function verifyMagi2Signature({ rawBody, timestamp, signature, secret }) {
const expected =
"sha256=" +
crypto
.createHmac("sha256", secret)
.update(`${timestamp}.${rawBody}`)
.digest("hex");
const a = Buffer.from(signature || "", "utf8");
const b = Buffer.from(expected, "utf8");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}PRICING & BILLING
All three MAGI-2 API models output 1080p video at a flat rate of 10 credits per second of generated output. API usage draws from the same credit balance as the web studio.
| Output Duration | Credit Cost | Resolution | Audio Sync |
|---|---|---|---|
| 4 seconds (default) | 40 credits | 1080p | Included |
| 8 seconds | 80 credits | 1080p | Included |
| 15 seconds | 150 credits | 1080p | Included |
| 30 seconds (max) | 300 credits | 1080p | Included |
ERROR HANDLING
Error responses return a consistent JSON shape: {"error": {"code": "...", "message": "..."}}.
| HTTP | Error Code | Meaning & Resolution |
|---|---|---|
| 400 | invalid_model / invalid_parameters / invalid_webhook_url | Check required fields, duration (4–30), aspect_ratio, public media URLs, or HTTPS webhook_url format. |
| 401 | unauthorized | Missing, malformed, or revoked Bearer API key. |
| 402 | insufficient_credits | Account credit balance is lower than required (duration × 10 credits). Top up via Pricing. |
| 403 | paid_account_required | API access requires an active subscription or credit pack purchase. |
| 404 | not_found | The requested MAGI-2 generation ID does not exist or belongs to another account. |
| 409 | idempotency_conflict | The same Idempotency-Key was reused with a different model or request type. |
| 502 | upstream_error | Upstream job submission failed. Reserved credits have been refunded automatically. |
FAQ
Yes. API requests consume credits from the exact same FIFO credit ledger as the MAGI-2 web studio, and every task created through the API appears in your Personal Center History where you can preview or download it.
Any account with a valid paid entitlement (an active subscription or a credit pack purchase) can call the MAGI-2 API. Create your sk- API key from Personal Center → API Keys.
Pass publicly accessible HTTPS URLs directly in first_frame_url, last_frame_url, reference_image_urls, reference_video_urls, or reference_audio_urls. Reference video and audio clips should be between 2 and 30 seconds.
Credits are reserved when a task is created and automatically refunded in full if upstream generation fails or times out after 30 minutes. You can inspect credits_refunded in the task response and webhook payload.
Pass a 16–256 character webhook_secret alongside webhook_url when creating the job. When we deliver the callback, compute HMAC-SHA256 over "{X-Magi2-Timestamp}.{rawBody}" with your secret and compare it in constant time against X-Magi2-Signature.
Include a unique Idempotency-Key HTTP header on POST /api/v1/magi-2/generations. Retrying with the same key returns HTTP 200 with the original task instead of creating a duplicate job or charging credits again.
Generate an API key in seconds and ship 1080p audio-synchronized video generation directly in your product or workflow.