# MAGI-2 動画生成 > テキスト、先頭/末尾フレーム画像、または画像・動画・音声のマルチモーダル参照から 1080p の同期音声付き MP4 動画を生成(4-30 秒) **API:** POST https://toapis.com/v1/videos/generations **Note:** **中国本土のユーザーへ:** 中国本土からは `https://toapis.cn` を API エンドポイント(Base URL)としてご利用いただき、例中の `https://toapis.com` を `https://toapis.cn` に置き換えてください。中国本土サイトでは、タスク照会および Webhook で返されるメディア URL が自動的に中国本土ドメインへ書き換えられます。 - プラットフォームモデル名:`magi-2`(3 つのモードを単一モデル名で提供し、トップレベルの `video_generation_mode` で切り替え) - 出力仕様:同期音声(セリフ・効果音・環境音)付き `1080p` MP4 動画、長さ `4-30` 秒の任意整数 - 課金方式:正常に生成された動画の秒数に応じて課金されます。3 つのモードで同じ課金ルールが適用され、無音(`generate_audio: false`)でも課金ルールは変わらず、参照素材は入力項目として個別課金されず、失敗したタスクは課金されません - 提供範囲:グローバルサイト(`https://toapis.com`)および中国本土サイト(`https://toapis.cn`)の両方で利用可能 - 非同期タスク API:送信後に統一形式の `generation.task` を返します。`GET /v1/videos/generations/{task_id}` または `GET /v1/tasks/{task_id}` で結果を取得してください **Warning:** 本モデルは厳格なトップレベルフラット JSON ホワイトリストを適用します。画像からの生成を含む全モードで `prompt` は必須かつ空欄不可です。メディア入力からモードを自動推測せず、ネストされたラッパー(`input`、`options`、`config`、`metadata`)、旧エイリアス、未定義パラメータ、Base64/Data URI、multipart アップロードは HTTP 400 で拒否されます。 ## 入力モード | `video_generation_mode` | モード | 素材要件 | `aspect_ratio` | | --- | --- | --- | --- | | `text_to_video`(デフォルト) | テキスト生成 | `image_urls`、`last_frame_url`、`video_urls`、`audio_urls` は指定不可 | 任意、6 種類、デフォルト `16:9` | | `first_frame_image_to_video` | 先頭/末尾フレーム生成 | `image_urls` 必須(先頭フレーム 1 枚のみ);`last_frame_url` 任意;`video_urls` / `audio_urls` は指定不可 | 任意、6 種類;省略時は先頭フレームに従う | | `reference_to_video` | マルチモーダル参照生成 | `image_urls`(1-10 枚)、`video_urls`(1-5 本)、`audio_urls`(1-5 本)のうち少なくとも 1 つを指定(併用可);`last_frame_url` は指定不可 | 任意、6 種類、デフォルト `16:9` | ## 認証 **Authorization (string, required)** すべてのエンドポイントで Bearer Token 認証が必要です。 ```text Authorization: Bearer ``` ## リクエストパラメータ **model (string, required)** Default: "magi-2" プラットフォームの動画生成モデル名。全モード共通で `magi-2` 固定です。 **video_generation_mode (string)** Default: "text_to_video" Allowed values: ["text_to_video","first_frame_image_to_video","reference_to_video"] 動画生成モード。デフォルトは `text_to_video`。 - `text_to_video`:テキスト生成(メディアフィールド不可) - `first_frame_image_to_video`:先頭フレーム(任意で末尾フレーム)画像生成 - `reference_to_video`:画像・動画・音声によるマルチモーダル参照生成 メディア入力を渡す場合は必ず対応するモードを明示してください。`image_urls` からモードを自動推測しません。 **prompt (string, required)** 動画の内容説明。前後空白除去後 `1-8000` Unicode 文字。**画像生成を含む全モードで必須(空欄不可)です。** 被写体、動作、カメラワーク、セリフ(引用符で表記)、効果音、環境音を記述してください。 **duration (integer)** Default: 5 動画の長さ(秒)。`4` から `30` の整数、デフォルトは `5`。生成秒数に応じて課金されます。 **aspect_ratio (string)** Default: "16:9" Allowed values: ["21:9","16:9","4:3","1:1","3:4","9:16"] 出力動画のアスペクト比。対応値:`21:9`、`16:9`、`4:3`、`1:1`、`3:4`、`9:16`。 - `text_to_video` と `reference_to_video`:デフォルト `16:9` - `first_frame_image_to_video`:任意;省略時は先頭フレーム画像の比率に自動で従います **resolution (string)** Default: "1080p" Allowed values: ["1080p"] 出力解像度。`1080p` のみ対応し、他の値は拒否されます。 **generate_audio (boolean)** Default: true 同期音声(セリフ・効果音・環境音)を生成するかどうか。デフォルトは `true`。`false` で無音動画になりますが、課金ルールは同じです。 **seed (integer)** 任意の乱数シード。`0` から `2147483647` の整数(両端含む)。省略時はランダム、明示的な `0` は保持され、負数は拒否されます。 **image_urls (string[])** 公開アクセス可能な HTTP(S) 画像 URL 配列(JPG / PNG / WEBP)。ローカル画像は事前に [画像アップロード](/docs/ja/api-reference/uploads/images) で URL を取得してください。 - `text_to_video`:指定不可 - `first_frame_image_to_video`:必須、先頭フレームとしてちょうど `1` 枚 - `reference_to_video`:任意、`1-10` 枚の参照画像(先頭フレームとしては解釈されません) 未使用時はフィールド自体を省略してください。空配列 `[]` や `null` は HTTP 400 になります。 **last_frame_url (string)** 終了画面を指定する単一の公開 HTTP(S) 画像 URL(JPG / PNG / WEBP)。 `first_frame_image_to_video` で `image_urls` と併用する場合のみ有効です。`text_to_video` と `reference_to_video` では指定不可です。 **video_urls (string[])** 参照動画の公開 HTTP(S) URL 配列(MP4 / MOV)、`1-5` 本。ローカル動画は事前に [動画アップロード](/docs/ja/api-reference/uploads/videos) で URL を取得してください。 - `reference_to_video` のみ有効;`text_to_video` と `first_frame_image_to_video` では指定不可 - 各動画は `2-30` 秒、参照動画の合計長さは `<= 30` 秒としてください(送信時は URL と本数上限を検証し、長さ制約は生成処理時に検証されます) **audio_urls (string[])** 参照音声の公開 HTTP(S) URL 配列(MP3 / WAV)、`1-5` 本。ローカル音声は事前に [音声アップロード](/docs/ja/api-reference/uploads/audios) で URL を取得してください。 - `reference_to_video` のみ有効;`text_to_video` と `first_frame_image_to_video` では指定不可 - 各音声は `2-30` 秒、参照音声の合計長さは `<= 30` 秒としてください(送信時は URL と本数上限を検証し、長さ制約は生成処理時に検証されます) **client_business_id (string)** 注文番号や取引 ID などの任意の業務識別子。同じステータス照会エンドポイントでこの値からタスクを取得できます。 **webhook (string)** 任意の ToAPIs タスク完了コールバック URL(`callback_url` も互換サポート)。プラットフォームが HMAC-SHA256 署名付きで配信します。詳細は [タスク Webhook](/docs/ja/api-reference/webhooks/task-webhooks) を参照してください。 ## 素材ルールと検証境界 - すべてのメディア入力は公開アクセス可能な `http://` または `https://` URL のみ受け付けます。プライベート/ループバックアドレス、認証情報埋め込み URL、Data URI、Base64、multipart アップロードは拒否されます。 - `reference_to_video` では `image_urls`、`video_urls`、`audio_urls` のうち少なくとも 1 つを空でない配列で指定してください。3 種類は自由に組み合わせ可能です。 - 未使用の任意メディア配列は空配列 `[]` や `null` を渡さず省略してください。 - ネストされたラッパー(`input`、`options`、`config`、`metadata`)、旧エイリアス(`seconds`、`size`、`ratio`、`audio`、`audio_setting`、`image`、`images`、`reference_images`)、`stream`、`n`、`fps`、`watermark`、`return_last_frame`、`negative_prompt`、範囲外の `seed` / `duration`、未対応の `resolution` / `aspect_ratio`、モード不整合は HTTP `400` で拒否されます。 ## 課金ルール | 項目 | 内容 | | --- | --- | | 課金方式 | 成功出力動画の秒数課金(`per_second`、`4-30` 整数秒) | | モード適用 | `text_to_video`、`first_frame_image_to_video`、`reference_to_video` の 3 モードで同じ課金ルールを適用 | | 音声・参照素材 | `generate_audio: false`(無音)でも課金ルールは変わりません;参照画像/動画/音声は入力項目として個別課金されません | | 失敗・確定精算 | タスク失敗時は課金なし(事前仮押さえ分は返金);最終精算は完了時の `billing`(`status: "settled"` / `"refunded"`)と `usage`(`charge_type: "per_second"`、`output_seconds`)で確認してください | **Note:** 送信レスポンスにはタスク ID のみが含まれ、確定料金は含まれません。実際の利用可否とアカウント課金詳細はご利用サイトのコンソールおよび最終タスク状態の `billing` / `usage` をご確認ください。 ## リクエスト例 ### テキスト生成(明示的な `seed: 0` を指定) ```json { "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 } ``` ### 先頭/末尾フレーム画像生成(無音、`aspect_ratio` なし) ```json { "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 } ``` ### マルチモーダル参照生成(画像 + 動画 + 音声) ```json { "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 } ``` ## レスポンス **id (string)** タスクステータスの照会に使用する ToAPIs タスク ID。 **object (string)** オブジェクトタイプ。常に `generation.task`。 **model (string)** このリクエストで使用されたプラットフォームモデル名。常に `magi-2`。 **status (string)** タスクステータス:`queued`、`in_progress`、`completed`、`failed` のいずれか。 **progress (integer)** タスク進捗(`0` から `100` のパーセント)。 **created_at (integer)** タスク作成時刻(Unix 秒タイムスタンプ)。 **Note:** 送信後は [動画タスクステータスの取得](/docs/ja/api-reference/tasks/video-status)(`GET /v1/videos/generations/{task_id}`、`GET /v1/tasks/{task_id}` 互換)をポーリングするか、[タスク Webhook](/docs/ja/api-reference/webhooks/task-webhooks) を設定してください。完了後、MP4 動画 URL は `result.data[0].url` に返されます。ポーリング間隔は 5-10 秒以上(ジッター付き)とし、HTTP 429 時は `Retry-After` に従ってください。 ## Request Examples ```bash cURL (テキスト生成) curl --request POST \ --url https://toapis.com/v1/videos/generations \ --header 'Authorization: Bearer ' \ --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 }' ``` ```bash cURL (先頭/末尾フレーム) curl --request POST \ --url https://toapis.com/v1/videos/generations \ --header 'Authorization: Bearer ' \ --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 }' ``` ```bash cURL (マルチモーダル参照) curl --request POST \ --url https://toapis.com/v1/videos/generations \ --header 'Authorization: Bearer ' \ --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 }' ``` ```python Python import requests response = requests.post( "https://toapis.com/v1/videos/generations", headers={ "Authorization": "Bearer ", "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()) ``` ```javascript JavaScript const response = await fetch("https://toapis.com/v1/videos/generations", { method: "POST", headers: { Authorization: "Bearer ", "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 Examples ```json 200 { "id": "tsk_vid_01M840FXWTM23BKN1JR68C5XEM", "object": "generation.task", "model": "magi-2", "status": "queued", "progress": 0, "created_at": 1795575600 } ```