DEVELOPER API · V1

MAGI-2 API

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.

  • 1080p Output
  • 4–30s Duration
  • Native Audio Sync
  • Signed Webhooks
  • Shared Credits & History

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.

02

Shared Credit Ledger & History

Every MAGI-2 API request deducts from your existing account credit balance and appears automatically in your Personal Center History and Credit Ledger.

03

Signed Webhooks + Polling

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

Paid Access & Auto-Refunds

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

Authenticate every MAGI-2 API call with a Bearer API key

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/v1

Authorization Header

Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Idempotency Header (Optional)

Idempotency-Key: order_20261126_001

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

Submit your first MAGI-2 API video generation

Choose a model mode and language below. Pass public HTTPS URLs for frame or reference media—no separate upload step required.

1. Create generation
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"
}'
2. Poll status & check balance
# 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

REST API Endpoints

All endpoints live under /api/v1 and accept/return application/json.

MethodPathDescription
POST/api/v1/magi-2/generationsCreate 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/generationsList 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/creditsQuery your current remaining credit balance, paid entitlement status, and MAGI-2 per-second rate.

REQUEST SCHEMA

POST /api/v1/magi-2/generations Parameters

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.

Common Parameters (All Models)

ParameterTypeRequiredDescription
modelstringYesOne of "magi-2/text-to-video", "magi-2/image-to-video", or "magi-2/reference-to-video".
promptstringConditionalRequired for text-to-video and reference-to-video; optional for image-to-video. Up to 15,000 characters.
durationintegerNoOutput clip length in seconds, integer from 4 to 30. Default: 4. Billed at 10 credits per second.
aspect_ratiostringNoFor 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_audiobooleanNoGenerate synchronized dialogue, sound effects, and ambience. Default: true.
seedintegerNoOptional reproducibility seed between 0 and 2147483647.
webhook_urlstring (HTTPS)NoPublic HTTPS endpoint to receive a POST callback when the task reaches success, failed, or canceled.
webhook_secretstringNoOptional 16–256 character secret used to sign webhook payloads via HMAC-SHA256 in the X-Magi2-Signature header. Requires webhook_url.

Image-to-Video (magi-2/image-to-video)

ParameterTypeRequiredDescription
first_frame_urlstring (URL)YesPublicly accessible image URL (JPG, PNG, or WebP) used as the opening frame. Alias: image.
last_frame_urlstring (URL)NoOptional closing frame image URL to guide transitions between start and end frames. Alias: last_image.

Reference-to-Video (magi-2/reference-to-video)

ParameterTypeRequiredDescription
reference_image_urlsstring[]At least 1 mediaUp to 10 public image URLs for character, product, or style consistency. Alias: images.
reference_video_urlsstring[]At least 1 mediaUp to 5 public video URLs (MP4/MOV, 2–30s each) for motion or camera reference. Alias: videos.
reference_audio_urlsstring[]At least 1 mediaUp to 5 public audio URLs (MP3/WAV, 2–30s each) for voice or music guidance. Alias: audios.

RESPONSE OBJECT

Generation Object & Lifecycle

Tasks transition from pending → processing → success (or failed / canceled). Once complete, video_url contains the persistent MP4 URL.

201 Created — Queued Task
{
  "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"
}
200 OK — Completed Task
{
  "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

Receive Asynchronous Completion Callbacks

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).

Webhook Request Headers

X-Magi2-Event
Event name: generation.completed, generation.failed, or generation.canceled.
X-Magi2-Delivery
Unique UUID for this webhook delivery attempt sequence.
X-Magi2-Timestamp
Unix epoch timestamp in seconds when the webhook payload was generated.
X-Magi2-Signature
Present when webhook_secret is supplied. Format: sha256=<hex(HMAC_SHA256(secret, "{timestamp}.{rawBody}"))>.
  • Only public HTTPS URLs are accepted; localhost, private networks, and HTTP redirects are rejected for security.
  • Return any 2xx HTTP status within 10 seconds to acknowledge delivery.
  • On network errors, 408, 429, or 5xx responses, delivery retries up to 3 attempts automatically.
Example Webhook Payload
{
  "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"
  }
}
Verify X-Magi2-Signature
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

Transparent Credit Pricing — Identical to Web

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.

10 credits / second
Output DurationCredit CostResolutionAudio Sync
4 seconds (default)40 credits1080pIncluded
8 seconds80 credits1080pIncluded
15 seconds150 credits1080pIncluded
30 seconds (max)300 credits1080pIncluded
  • No extra API markup—10 credits/second applies across text-to-video, image-to-video, and reference-to-video.
  • Automatic full refund: if a task fails upstream or times out after 30 minutes, its reserved credits are returned automatically to the original FIFO credit grants.
  • No separate API concurrency or RPM cap in v1.
View Credit Packs & Plans

ERROR HANDLING

HTTP Status & Error Codes

Error responses return a consistent JSON shape: {"error": {"code": "...", "message": "..."}}.

HTTPError CodeMeaning & Resolution
400invalid_model / invalid_parameters / invalid_webhook_urlCheck required fields, duration (4–30), aspect_ratio, public media URLs, or HTTPS webhook_url format.
401unauthorizedMissing, malformed, or revoked Bearer API key.
402insufficient_creditsAccount credit balance is lower than required (duration × 10 credits). Top up via Pricing.
403paid_account_requiredAPI access requires an active subscription or credit pack purchase.
404not_foundThe requested MAGI-2 generation ID does not exist or belongs to another account.
409idempotency_conflictThe same Idempotency-Key was reused with a different model or request type.
502upstream_errorUpstream job submission failed. Reserved credits have been refunded automatically.

FAQ

Frequently Asked Questions about the MAGI-2 API

Do MAGI-2 API calls share credits and history with the web app?

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.

Who can use the MAGI-2 API?

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.

How do I pass images, videos, or audio for image-to-video and reference-to-video?

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.

What happens to my credits if a MAGI-2 API task fails?

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.

How should I verify MAGI-2 webhooks?

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.

How do I prevent duplicate charges when retrying network requests?

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.

Ready to integrate the MAGI-2 API?

Generate an API key in seconds and ship 1080p audio-synchronized video generation directly in your product or workflow.