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
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-levelvideo_generation_mode) - Output:
1080pMP4 video with synchronized native audio (dialogue, sound effects, ambience), any integer duration from4to30seconds - 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; pollGET /v1/videos/generations/{task_id}orGET /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
All endpoints require Bearer Token authentication.
Authorization: Bearer <token>Request Parameters
Platform video generation model name, fixed to magi-2 across all three modes.
Video generation mode. Defaults to text_to_video.
text_to_video: Text-to-video; no media fields allowedfirst_frame_image_to_video: First-frame (and optional last-frame) image-to-videoreference_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.
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.
Output video length in seconds: any whole number from 4 to 30, defaulting to 5. Billed per generated second.
Output aspect ratio. Supported values: 21:9, 16:9, 4:3, 1:1, 3:4, 9:16.
text_to_videoandreference_to_video: Defaults to16:9first_frame_image_to_video: Optional; when omitted, output aspect ratio automatically follows the first-frame image
Output resolution. Only 1080p is supported; other values are rejected.
Whether to generate synchronized native audio (dialogue, sound effects, ambience). Defaults to true. Set to false for a silent video; billing behavior is unchanged.
Optional random seed, integer 0 through 2147483647 (inclusive). Omit for a random seed; explicit 0 is preserved; negative values are rejected.
Public HTTP(S) image URLs (JPG / PNG / WEBP). Upload local images first via Upload Images.
text_to_video: Forbiddenfirst_frame_image_to_video: Required, exactly1image URL used as the first framereference_to_video: Optional,1-10image URLs used as subject/style references (not interpreted as a first frame)
Omit when unused; passing an empty array [] or null returns HTTP 400.
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.
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 intext_to_videoandfirst_frame_image_to_video - Each clip should be
2-30seconds with total reference video duration<= 30seconds (submission validates URL format and count; duration limits are checked during generation)
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 intext_to_videoandfirst_frame_image_to_video - Each clip should be
2-30seconds with total reference audio duration<= 30seconds (submission validates URL format and count; duration limits are checked during generation)
Optional business identifier (such as an order or transaction ID) that can be used to look up the task through the same status endpoint.
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://orhttps://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 ofimage_urls,video_urls, oraudio_urlsmust be provided and non-empty; all three modalities can be combined freely. - Omit unused optional media fields rather than passing empty arrays
[]ornull. - 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-rangeseed/duration, unsupportedresolution/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
ToAPIs platform task ID used to query task status.
Object type, always generation.task.
Platform model name used for this request, always magi-2.
Task status: queued, in_progress, completed, or failed.
Task progress percentage from 0 to 100.
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
}