ToAPIs ToAPIs
MAGI-2

MAGI-2 Video Generation

Generate 1080p MP4 videos with synchronized sound from text, first/last frames, or multimodal image, video, and audio references, 4-30 seconds long

POST
/v1/videos/generations

Note for users in mainland China: Please use https://toapis.cn as the API endpoint (Base URL) and replace https://toapis.com with https://toapis.cn in the examples below. Task status responses and webhooks on the CN site automatically return media URLs on the CN file domain.

  • Platform model name: magi-2 (single model name for all three modes, selected via top-level video_generation_mode)
  • Output: 1080p MP4 video with synchronized native audio (dialogue, sound effects, ambience), any integer duration from 4 to 30 seconds
  • Billing: Successful output is billed per second of generated video. All three modes use the same billing rules; silent output (generate_audio: false) does not change the billing behavior, reference media are not billed as separate input items, and failed tasks are not charged
  • Regional availability: Available on both global (https://toapis.com) and CN (https://toapis.cn) sites
  • Async task API: Returns a unified generation.task; poll GET /v1/videos/generations/{task_id} or GET /v1/tasks/{task_id} for progress and output

This model enforces a strict flat top-level JSON parameter whitelist: prompt is required and non-empty in all modes (including image-to-video); modes are never inferred automatically from media inputs; nested wrapper objects (input, options, config, metadata), legacy aliases, unknown parameters, Base64/Data URI inputs, and multipart file uploads are rejected with HTTP 400.

Input Modes

video_generation_mode Mode Media Requirements aspect_ratio
text_to_video (default) Text-to-video Must omit image_urls, last_frame_url, video_urls, and audio_urls Optional, 6 ratios, defaults to 16:9
first_frame_image_to_video First/last-frame image-to-video image_urls required with exactly 1 first-frame image; last_frame_url optional; video_urls and audio_urls forbidden Optional, 6 ratios; follows the first frame when omitted
reference_to_video Multimodal reference-to-video At least one non-empty array among image_urls (1-10), video_urls (1-5), and audio_urls (1-5); combinable; last_frame_url forbidden Optional, 6 ratios, defaults to 16:9

Authentication

Authorizationstringheaderrequired

All endpoints require Bearer Token authentication.

Authorization: Bearer <token>

Request Parameters

modelstringbodyrequireddefault: magi-2

Platform video generation model name, fixed to magi-2 across all three modes.

video_generation_modestringbodydefault: text_to_video

Video generation mode. Defaults to text_to_video.

  • text_to_video: Text-to-video; no media fields allowed
  • first_frame_image_to_video: First-frame (and optional last-frame) image-to-video
  • reference_to_video: Multimodal reference-to-video using images, videos, and/or audio clips

When supplying media inputs, you must set video_generation_mode explicitly; the platform does not infer the mode from image_urls.

promptstringbodyrequired

Video description, 1-8000 Unicode characters after trimming whitespace. Required and non-empty in all modes (including image-to-video). Describe subjects, actions, camera motion, dialogue (in quotes), sound effects, and ambience.

durationintegerbodydefault: 5

Output video length in seconds: any whole number from 4 to 30, defaulting to 5. Billed per generated second.

aspect_ratiostringbodydefault: 16:9

Output aspect ratio. Supported values: 21:9, 16:9, 4:3, 1:1, 3:4, 9:16.

  • text_to_video and reference_to_video: Defaults to 16:9
  • first_frame_image_to_video: Optional; when omitted, output aspect ratio automatically follows the first-frame image
resolutionstringbodydefault: 1080p

Output resolution. Only 1080p is supported; other values are rejected.

generate_audiobooleanbodydefault: true

Whether to generate synchronized native audio (dialogue, sound effects, ambience). Defaults to true. Set to false for a silent video; billing behavior is unchanged.

seedintegerbody

Optional random seed, integer 0 through 2147483647 (inclusive). Omit for a random seed; explicit 0 is preserved; negative values are rejected.

image_urlsstring[]body

Public HTTP(S) image URLs (JPG / PNG / WEBP). Upload local images first via Upload Images.

  • text_to_video: Forbidden
  • first_frame_image_to_video: Required, exactly 1 image URL used as the first frame
  • reference_to_video: Optional, 1-10 image URLs used as subject/style references (not interpreted as a first frame)

Omit when unused; passing an empty array [] or null returns HTTP 400.

last_frame_urlstringbody

Optional single public HTTP(S) image URL (JPG / PNG / WEBP) specifying the ending frame.

Allowed only in first_frame_image_to_video together with image_urls; forbidden in text_to_video and reference_to_video.

video_urlsstring[]body

Reference video public HTTP(S) URLs (MP4 / MOV), 1-5 clips. Upload local videos first via Upload Videos.

  • Allowed only in reference_to_video; forbidden in text_to_video and first_frame_image_to_video
  • Each clip should be 2-30 seconds with total reference video duration <= 30 seconds (submission validates URL format and count; duration limits are checked during generation)
audio_urlsstring[]body

Reference audio public HTTP(S) URLs (MP3 / WAV), 1-5 clips. Upload local audio files first via Upload Audios.

  • Allowed only in reference_to_video; forbidden in text_to_video and first_frame_image_to_video
  • Each clip should be 2-30 seconds with total reference audio duration <= 30 seconds (submission validates URL format and count; duration limits are checked during generation)
client_business_idstringbody

Optional business identifier (such as an order or transaction ID) that can be used to look up the task through the same status endpoint.

webhookstringbody

Optional ToAPIs task-completion callback URL (callback_url is also accepted). Managed and signed with HMAC-SHA256 by ToAPIs; see Task Webhooks.

Media Rules & Validation

  • Media inputs must be publicly reachable http:// or https:// URLs. Private/loopback addresses, URLs with embedded credentials, Data URIs, Base64 strings, and multipart file uploads are rejected.
  • In reference_to_video, at least one of image_urls, video_urls, or audio_urls must be provided and non-empty; all three modalities can be combined freely.
  • Omit unused optional media fields rather than passing empty arrays [] or null.
  • The following inputs return HTTP 400: nested wrapper objects (input, options, config, metadata), legacy aliases (seconds, size, ratio, audio, audio_setting, image, images, reference_images), stream, n, fps, watermark, return_last_frame, negative_prompt, out-of-range seed / duration, unsupported resolution / aspect_ratio, and cross-mode conflicts.

Billing

Item Details
Billing model Billed per second of generated output video (per_second, 4-30 integer seconds)
Mode coverage text_to_video, first_frame_image_to_video, and reference_to_video use the same billing rules
Audio & reference media generate_audio: false (silent) does not change billing behavior; reference images, videos, and audio are not billed as separate input items
Failure & settlement Failed tasks are not charged (pre-authorized credits are refunded); final billing is confirmed via billing (status: "settled" / "refunded") and usage (charge_type: "per_second", output_seconds) on terminal task status

The submission response returns only a task handle and not final charges. Actual availability and billing details are subject to your site console and the terminal task billing / usage payload.

Request Examples

Text-to-video (with explicit seed: 0)

{
  "model": "magi-2",
  "video_generation_mode": "text_to_video",
  "prompt": "A small boat crosses a quiet lake at sunrise, with gentle water sounds and distant birds.",
  "duration": 5,
  "aspect_ratio": "16:9",
  "resolution": "1080p",
  "generate_audio": true,
  "seed": 0
}

First-frame and last-frame image-to-video (silent, no aspect_ratio)

{
  "model": "magi-2",
  "video_generation_mode": "first_frame_image_to_video",
  "prompt": "The camera slowly pushes toward the subject and transitions smoothly into the ending composition.",
  "image_urls": [
    "https://example.com/first-frame.jpg"
  ],
  "last_frame_url": "https://example.com/last-frame.jpg",
  "duration": 5,
  "resolution": "1080p",
  "generate_audio": false
}

Multimodal reference-to-video (image + video + audio)

{
  "model": "magi-2",
  "video_generation_mode": "reference_to_video",
  "prompt": "Keep the subject from the reference image, follow the camera movement from the reference video, and match the mood of the reference audio.",
  "image_urls": [
    "https://example.com/reference-subject.jpg"
  ],
  "video_urls": [
    "https://example.com/reference-motion.mp4"
  ],
  "audio_urls": [
    "https://example.com/reference-ambience.wav"
  ],
  "duration": 5,
  "aspect_ratio": "16:9",
  "resolution": "1080p",
  "generate_audio": true
}

Response

idstring

ToAPIs platform task ID used to query task status.

objectstring

Object type, always generation.task.

modelstring

Platform model name used for this request, always magi-2.

statusstring

Task status: queued, in_progress, completed, or failed.

progressinteger

Task progress percentage from 0 to 100.

created_atinteger

Task creation time as a Unix timestamp in seconds.

After submission, poll Get Video Task Status (GET /v1/videos/generations/{task_id}, also compatible with GET /v1/tasks/{task_id}) or configure Task Webhooks. Once completed, the MP4 video URL is in result.data[0].url. Poll every 5-10 seconds with jitter and respect Retry-After on HTTP 429.

Request Example

curl --request POST \
  --url https://toapis.com/v1/videos/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "magi-2",
    "video_generation_mode": "text_to_video",
    "prompt": "A small boat crosses a quiet lake at sunrise, with gentle water sounds.",
    "duration": 5,
    "aspect_ratio": "16:9",
    "resolution": "1080p",
    "generate_audio": true,
    "seed": 0
  }'
curl --request POST \
  --url https://toapis.com/v1/videos/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "magi-2",
    "video_generation_mode": "first_frame_image_to_video",
    "prompt": "The camera slowly pushes in and transitions smoothly to the ending frame.",
    "image_urls": [
      "https://example.com/first-frame.jpg"
    ],
    "last_frame_url": "https://example.com/last-frame.jpg",
    "duration": 5,
    "resolution": "1080p",
    "generate_audio": false
  }'
curl --request POST \
  --url https://toapis.com/v1/videos/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "magi-2",
    "video_generation_mode": "reference_to_video",
    "prompt": "Keep the subject from the reference image, use the camera motion from the video, and match the ambience from the audio.",
    "image_urls": [
      "https://example.com/reference-subject.jpg"
    ],
    "video_urls": [
      "https://example.com/reference-motion.mp4"
    ],
    "audio_urls": [
      "https://example.com/reference-ambience.wav"
    ],
    "duration": 5,
    "aspect_ratio": "16:9",
    "resolution": "1080p",
    "generate_audio": true
  }'
import requests

response = requests.post(
    "https://toapis.com/v1/videos/generations",
    headers={
        "Authorization": "Bearer <token>",
        "Content-Type": "application/json",
    },
    json={
        "model": "magi-2",
        "video_generation_mode": "reference_to_video",
        "prompt": "Keep the subject from the reference image and show it moving in a sunlit garden.",
        "image_urls": ["https://example.com/reference-subject.jpg"],
        "duration": 5,
        "aspect_ratio": "16:9",
        "resolution": "1080p",
        "generate_audio": True,
    },
)

print(response.json())
const response = await fetch("https://toapis.com/v1/videos/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer <token>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "magi-2",
    video_generation_mode: "text_to_video",
    prompt: "A small boat crosses a quiet lake at sunrise, with gentle water sounds.",
    duration: 5,
    aspect_ratio: "16:9",
    resolution: "1080p",
    generate_audio: true
  })
});

console.log(await response.json());

Response Example

{
  "id": "tsk_vid_01M840FXWTM23BKN1JR68C5XEM",
  "object": "generation.task",
  "model": "magi-2",
  "status": "queued",
  "progress": 0,
  "created_at": 1795575600
}