> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apimart.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# MAGI-2 動画生成

> テキスト、開始・終了フレーム、画像・動画・音声の参照から動画を生成。出力は 1080p 固定、長さは 4–30 秒、音声生成はデフォルトで有効です。

```bash cURL theme={null}
curl --request POST \
  --url https://api.apimart.ai/v1/videos/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "magi-2",
  "prompt": "雨の夜、赤い紙の船が側溝を流れる。マクロ撮影と雨音",
  "duration": 5,
  "aspect_ratio": "9:16",
  "generate_audio": true,
  "nsfw_check": true
}'
```

```python Python theme={null}
import requests

payload = {
  "model": "magi-2",
  "prompt": "雨の夜、赤い紙の船が側溝を流れる。マクロ撮影と雨音",
  "duration": 5,
  "aspect_ratio": "9:16",
  "generate_audio": True,
  "nsfw_check": True
}
response = requests.post(
    "https://api.apimart.ai/v1/videos/generations",
    headers={"Authorization": "Bearer <token>"},
    json=payload,
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

```javascript JavaScript theme={null}
const payload = {
  "model": "magi-2",
  "prompt": "雨の夜、赤い紙の船が側溝を流れる。マクロ撮影と雨音",
  "duration": 5,
  "aspect_ratio": "9:16",
  "generate_audio": true,
  "nsfw_check": true
};
const response = await fetch("https://api.apimart.ai/v1/videos/generations", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  },
  body: JSON.stringify(payload)
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

```json 200 theme={null}
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_example_magi2"
    }
  ]
}
```

MAGI-2 は Sand AI の動画生成モデルです。`POST /v1/videos/generations` に送信し、`data[0].task_id` を取得してから[タスク照会 API](https://docs.apimart.ai/ja/api-reference/tasks/status.md)で結果を確認します。

**Authorization** `string` *required*

`Authorization: Bearer <token>` を使用します。`<token>` は APIMart API キーです。

## 生成モード

| モード | 送信方法 |
| - | - |
| テキストから動画 | `prompt` を指定し、画像・動画・音声素材は送信しません。 |
| 画像から動画 | `image_urls` で開始フレームと任意の終了フレームを送信するか、専用のフレームフィールドを使用します。 |
| 参照から動画 | `video_urls`、`audio_urls`、または `role: "reference_image"` の画像があると自動で参照モードになります。`image_urls` のみの場合は `omni_reference_task_type: "reference"` を明示してください。 |

まず入力素材によってモードが決まります。自動選択された参照モードと明示的な `reference` の動作は同じです。参照モードでは全画像を参照として扱い、`image_urls` と `image_with_roles` 内の `role: "reference_image"` の画像は**合計最大 10 枚**です。

参照生成の例では `omni_reference_task_type: "reference"` を明示しています。各素材の用途をプロンプトで説明してください。素材は生成の参考となり、元動画の直接結合や元音声のそのままの再利用は行いません。

## リクエストパラメータ

**model** `string` *required*

`magi-2`

**nsfw\_check** `boolean` (default: false)

動画タスクを送信する前にコンテンツモデレーションを実行するかどうかを指定します。

* `true`：`omni-moderation-latest` でプロンプトと入力画像を審査
* `false` または省略：審査リクエストを行わず、審査コストや遅延を追加しない（デフォルト）

**prompt** `string` *required*

すべてのモードで必須、最大 15,000 文字。画面・動作・カメラ・音を説明し、台詞は引用符で囲みます。

**duration** `integer` (default: 5)

整数秒 `4`–`30`、デフォルト `5`。`0`、小数、範囲外の値は HTTP 400。デフォルトを使う場合は省略します。

**seconds** `integer`

`duration` の別名。両方送信する場合は同じ値にしてください。

**resolution** `string` (default: 1080p)

`1080p` のみ。省略時も 1080p を出力し、それ以外は HTTP 400 です。

**aspect\_ratio** `string`

テキスト・参照モードは `16:9`（デフォルト）、`9:16`、`1:1`、`4:3`、`3:4`、`21:9`。画像から動画は前の 5 種のみで `21:9` は非対応。省略または `auto` で開始フレームの比率に従い、解像度は 1080p のままです。

**generate\_audio** `boolean` (default: true)

音声を生成するかどうか。デフォルト `true`、`false` では音声トラックなし。`audio` と併用する場合は同じ値にします。

**audio** `boolean`

`generate_audio` の別名で、値の矛盾は不可。参照音声は `audio_urls` で送信します。

**seed** `integer`

整数 `0`–`2147483647`。省略または `-1` でランダム。固定すると同じ条件の結果が近づきますが、完全一致は保証されません。

**omni\_reference\_task\_type** `string` (default: auto)

`auto`（デフォルト）と `reference` に対応。複数の `image_urls` を参照に使う場合は `reference` を明示します。`edit` / `extend` は非対応です。

**image\_urls** `string[]`

各項目は公開 HTTP(S) 画像 URL です。最大 2 枚という制限は画像から動画の場合のみで、開始フレームと任意の終了フレームを指定します。このモードは、画像のみを送り、参照動画・音声、明示的な `reference`、`reference_image` ロールがない場合に適用されます。参照モードでは配列全体が参照となり、`image_with_roles` の `reference_image` と合計最大 10 枚です。自動選択と明示指定で上限は同じです。

**first\_frame\_image** `string`

開始フレームの公開 HTTP(S) URL。専用の開始・終了フィールドと `image_urls` はどちらか一方を使用します。

**last\_frame\_image** `string`

開始フレームと組み合わせる任意の終了フレームの公開 HTTP(S) URL。専用フィールドと `image_urls` はどちらか一方を使用します。

**image\_with\_roles** `object[]`

各項目に `url`（公開 HTTP(S) 画像 URL）と `role` を指定します。ロールは `first_frame`、`last_frame`、`reference_image`。画像から動画では開始・終了フレームは各 1 枚まで。`reference_image` は参照モードを選択し、その画像と `image_urls` の画像を合わせて最大 10 枚です。

**video\_urls** `string[]`

参照動画は最大 5 本、各 2–30 秒。合計は 30 秒以内にしてください。超過分は上流サービスで切り詰められる場合があります。公開 HTTP(S) URL の配列を使用し、単数の `video_url` は使えません。

**audio\_urls** `string[]`

参照音声は最大 5 件、各 2–30 秒。合計は 30 秒以内にしてください。超過分は上流サービスで切り詰められる場合があります。公開 HTTP(S) URL を使用します。

## 素材の要件

素材は公開された直接アクセス可能な HTTP(S) URL を使用します。ログイン・直リンク制限・ダウンロード失敗はタスク失敗の原因になります。ローカルファイルは[画像](https://docs.apimart.ai/ja/api-reference/uploads/images.md)、[動画](https://docs.apimart.ai/ja/api-reference/uploads/videos.md)、[音声](https://docs.apimart.ai/ja/api-reference/uploads/audios.md)のアップロード API で URL を取得できます。

## リクエスト例

### 開始・終了フレーム

```json theme={null}
{
  "model": "magi-2",
  "prompt": "少女がゆっくり振り向き、柔らかな光の中で終了フレームの姿勢へ滑らかに移る",
  "image_urls": [
    "https://example.com/start.jpg",
    "https://example.com/end.jpg"
  ],
  "duration": 5
}
```

1 枚だけの場合は開始フレームとして使用します。`aspect_ratio` の省略時はその比率に従います。`image_urls` の代わりに `first_frame_image` と `last_frame_image` も使用できます。

### 画像のみの参照

```json theme={null}
{
  "model": "magi-2",
  "prompt": "2 枚の参照画像の人物が同じ庭で出会い、それぞれの外見を保つ",
  "image_urls": [
    "https://example.com/reference-1.jpg"
  ],
  "image_with_roles": [
    {
      "url": "https://example.com/reference-2.jpg",
      "role": "reference_image"
    }
  ],
  "omni_reference_task_type": "reference",
  "aspect_ratio": "16:9",
  "duration": 5
}
```

### 画像・動画・音声の混合参照

```json theme={null}
{
  "model": "magi-2",
  "prompt": "参照動画のカメラワーク、画像の少女の外見、音声の音楽スタイルを参考に夕暮れの海辺を歩く場面を生成",
  "image_urls": [
    "https://example.com/girl.jpg"
  ],
  "video_urls": [
    "https://example.com/camera.mp4"
  ],
  "audio_urls": [
    "https://example.com/bgm.mp3"
  ],
  "omni_reference_task_type": "reference",
  "aspect_ratio": "16:9",
  "duration": 8
}
```

## タスクの照会と結果

[タスク照会 API](https://docs.apimart.ai/ja/api-reference/tasks/status.md)を `completed` または `failed` までポーリングします。通常は数分かかり、混雑時はさらに長くなる場合があります。一定時間の経過だけで失敗と判断しないでください。照会を停止してもタスクは取消されません。

```bash theme={null}
curl --request GET \
  --url 'https://api.apimart.ai/v1/tasks/task_example_magi2' \
  --header 'Authorization: Bearer <token>'
```

| フィールド | 説明 |
| - | - |
| `data.status` | `pending` / `processing` は処理中、`completed` は成功、`failed` は失敗。 |
| `data.progress` | 進捗、0–100。 |
| `data.result.videos[0].url` | プラットフォームの保存領域に転送された生成動画の URL。詳細な構造はタスク照会 API を参照。 |
| `data.error.message` | タスク失敗時の詳細。 |

## 非対応の機能

以下を送信すると HTTP 400 になります： `mode`, `negative_prompt`, `watermark: true`, `camera_control`, `multi_shot` / `multi_prompt`, `element_list`, `video_list`, `voice_list`, `audio_setting`, `keyframe`, `omni_reference_task_type: "edit"` / `"extend"`, `video_url`. `resolution` は `1080p` のみ。動画編集・延長と中間フレームには対応していません。

## よくあるエラー

送信失敗は `error.message`、作成後のタスク失敗は照会結果の `data.error.message` を確認してください。

| エラーメッセージ・状況 | 対処 |
| - | - |
| `duration must be between 4 and 30 whole seconds` | 4–30 の整数秒を使用。省略時は 5。 |
| `duration (5) and seconds (6) are aliases and must match` | 時長の別名は同じ値にするか、片方のみ送信。 |
| `requires prompt` | すべてのモードでプロンプトを指定。 |
| `image_urls takes at most 2 images` | 開始・終了は最大 2 枚。画像のみの参照では `reference` を明示。 |
| `image-to-video only supports aspect_ratio` | 画像から動画では `21:9` を削除。省略または `auto` で開始フレームの比率を使用。 |
| `accepts at most 10 reference images` / `5 videos` / `5 audios` | 参照画像は 10 枚、動画は 5 本、音声は 5 件まで。 |
| `has no video edit / extend` / `does not support keyframes` | 編集・延長・中間フレームを削除。参照動画は `video_urls`。 |
| `always outputs 1080p` | `1080p` のみを送信するか `resolution` を省略。 |
| `audio (true) and generate_audio (false) are aliases and must match` | 音声スイッチの値をそろえるか片方のみ送信。 |
| `Could not download the input...` | 直接ダウンロードできる公開 URL を確認して再送信。 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.