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

# Wan2.7 動画生成

>  - アリババクラウド万相 2.7 動画生成モデル（統一エンドポイント）
- パラメータに応じて自動ルーティング：テキストから動画 / 画像から動画（先頭フレーム、先頭・最終フレーム、動画継続）
- 720P/1080P 解像度、2〜15 秒の長さに対応
- カスタムオーディオ対応（テキストモードではBGM、画像モードでは駆動音声として使用） 

<RequestExample>
  ```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": "wan2.7",
      "prompt": "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
      "resolution": "1080P",
      "duration": 8,
      "size": "16:9"
    }'
  ```

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

  url = "https://api.apimart.ai/v1/videos/generations"

  payload = {
      "model": "wan2.7",
      "prompt": "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
      "resolution": "1080P",
      "duration": 8,
      "size": "16:9"
  }

  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }

  response = requests.post(url, json=payload, headers=headers)

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const url = "https://api.apimart.ai/v1/videos/generations";

  const payload = {
    model: "wan2.7",
    prompt: "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
    resolution: "1080P",
    duration: 8,
    size: "16:9"
  };

  const headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  };

  fetch(url, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(payload)
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "io/ioutil"
      "net/http"
  )

  func main() {
      url := "https://api.apimart.ai/v1/videos/generations"

      payload := map[string]interface{}{
          "model":      "wan2.7",
          "prompt":     "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
          "resolution": "1080P",
          "duration":   8,
          "size":       "16:9",
      }

      jsonData, _ := json.Marshal(payload)

      req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", "Bearer <token>")
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      body, _ := ioutil.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```

  ```java Java theme={null}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;

  public class Main {
      public static void main(String[] args) throws Exception {
          String url = "https://api.apimart.ai/v1/videos/generations";

          String payload = """
          {
            "model": "wan2.7",
            "prompt": "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
            "resolution": "1080P",
            "duration": 8,
            "size": "16:9"
          }
          """;

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create(url))
              .header("Authorization", "Bearer <token>")
              .header("Content-Type", "application/json")
              .POST(HttpRequest.BodyPublishers.ofString(payload))
              .build();

          HttpResponse<String> response = client.send(request,
              HttpResponse.BodyHandlers.ofString());

          System.out.println(response.body());
      }
  }
  ```

  ```php PHP theme={null}
  <?php

  $url = "https://api.apimart.ai/v1/videos/generations";

  $payload = [
      "model" => "wan2.7",
      "prompt" => "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
      "resolution" => "1080P",
      "duration" => 8,
      "size" => "16:9"
  ];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "Authorization: Bearer <token>",
      "Content-Type: application/json"
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ?>
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'
  require 'uri'

  url = URI("https://api.apimart.ai/v1/videos/generations")

  payload = {
    model: "wan2.7",
    prompt: "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
    resolution: "1080P",
    duration: 8,
    size: "16:9"
  }

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(url)
  request["Authorization"] = "Bearer <token>"
  request["Content-Type"] = "application/json"
  request.body = payload.to_json

  response = http.request(request)
  puts response.body
  ```

  ```swift Swift theme={null}
  import Foundation

  let url = URL(string: "https://api.apimart.ai/v1/videos/generations")!

  let payload: [String: Any] = [
      "model": "wan2.7",
      "prompt": "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像",
      "resolution": "1080P",
      "duration": 8,
      "size": "16:9"
  ]

  var request = URLRequest(url: url)
  request.httpMethod = "POST"
  request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
  request.setValue("application/json", forHTTPHeaderField: "Content-Type")
  request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

  let task = URLSession.shared.dataTask(with: request) { data, response, error in
      if let error = error {
          print("Error: \(error)")
          return
      }

      if let data = data, let responseString = String(data: data, encoding: .utf8) {
          print(responseString)
      }
  }

  task.resume()
  ```

  ```csharp C# theme={null}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;

  class Program
  {
      static async Task Main(string[] args)
      {
          var url = "https://api.apimart.ai/v1/videos/generations";

          var payload = @"{
              ""model"": ""wan2.7"",
              ""prompt"": ""夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像"",
              ""resolution"": ""1080P"",
              ""duration"": 8,
              ""size"": ""16:9""
          }";

          using var client = new HttpClient();
          client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");

          var content = new StringContent(payload, Encoding.UTF8, "application/json");
          var response = await client.PostAsync(url, content);
          var result = await response.Content.ReadAsStringAsync();

          Console.WriteLine(result);
      }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "code": 200,
    "data": [
      {
        "status": "submitted",
        "task_id": "task_01J9HA7JPQ9A0Z6JZ3V8M9W6PZ"
      }
    ]
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": 400,
      "message": "リクエストパラメータが無効です",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "認証に失敗しました。APIキーを確認してください",
      "type": "authentication_error"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "code": 402,
      "message": "残高が不足しています。チャージしてください",
      "type": "payment_required"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "code": 429,
      "message": "リクエストが多すぎます。しばらくしてからお試しください",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "サーバー内部エラー。しばらくしてからお試しください",
      "type": "server_error"
    }
  }
  ```
</ResponseExample>

## 認証

<ParamField header="Authorization" type="string" required>
  すべてのAPIエンドポイントでBearer Token認証が必要です

  APIキーの取得：

  [APIキー管理ページ](https://apimart.ai/keys)からAPIキーを取得してください

  リクエストヘッダーに追加：

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## モードルーティング

`wan2.7` はテキストから動画および画像から動画の統一エンドポイントです。バックエンドは受信したパラメータに基づいて自動的にモードを判定します。**両モードの料金は同一です**：

| 条件                                                        | ルーティング先  | モード説明                     |
| --------------------------------------------------------- | -------- | ------------------------- |
| `image_urls` / `image_with_roles` / `video_urls` のいずれかが指定 | 画像から動画   | 先頭フレーム / 先頭・最終フレーム / 動画継続 |
| 上記パラメータがいずれも未指定                                           | テキストから動画 | テキスト説明のみから動画生成            |

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

<ParamField body="model" type="string" required>
  動画生成モデル名。`wan2.7` で固定
</ParamField>

<ParamField body="prompt" type="string">
  動画内容の説明、最大 5000 文字

  * **テキストモード**（画像/動画なし）：必須
  * **画像モード**：任意だが、カメラワークやアクションの指示のため推奨

  例：`"猫が草原で蝶を追いかける、晴天、スローモーション"`
</ParamField>

<ParamField body="image_urls" type="array<string>">
  画像URLの配列。指定すると自動的に画像モードに入ります

  * **1 枚**：先頭フレームから動画
  * **2 枚**：先頭・最終フレームから動画（1枚目が先頭、2枚目が最終）

  `image_with_roles` とどちらか一方を使用

  <Warning>
    `image_urls` と `audio_url` は競合するため、同時に指定することはできません
  </Warning>
</ParamField>

<ParamField body="image_with_roles" type="array<object>">
  ロール付き画像の配列。`image_urls` の代わりに使用し、各画像のロールを精密に指定

  各オブジェクトのフィールド：

  * `url` (string)：画像URL（http/httpsに対応）
  * `role` (string)：画像ロール、`first_frame`（先頭フレーム）/ `last_frame`（最終フレーム）、デフォルト `first_frame`

  例：

  ```json theme={null}
  [
    { "url": "https://cdn.example.com/start.jpg", "role": "first_frame" },
    { "url": "https://cdn.example.com/end.jpg", "role": "last_frame" }
  ]
  ```

  <Warning>
    `image_with_roles` と `audio_url` は競合するため、同時に指定することはできません
  </Warning>
</ParamField>

<ParamField body="video_urls" type="array<string>">
  動画URLの配列。指定すると**動画継続**モードに入ります（最初の1本のみ使用）

  <Warning>
    `video_urls` と `audio_url` は競合するため、同時に指定することはできません
  </Warning>

  <Note>
    **動画の制限：**

    * フォーマット：mp4、mov
    * 長さ：2〜10秒
    * 解像度：幅・高さともに \[240, 4096] ピクセルの範囲
    * アスペクト比：1:8 〜 8:1
    * ファイルサイズ：100MB 以下
  </Note>
</ParamField>

<ParamField body="negative_prompt" type="string">
  ネガティブプロンプト。含めたくない内容を記述、最大 500 文字

  例：`"ぼやけ、歪み、低品質"`
</ParamField>

<ParamField body="resolution" type="string" default="1080P">
  動画解像度

  選択肢：

  * `720P` - 標準
  * `1080P` - 高解像度（デフォルト）
</ParamField>

<ParamField body="duration" type="integer" default="5">
  動画の長さ（秒）

  対応範囲：`2`〜`15` 秒

  デフォルト：`5`
</ParamField>

<ParamField body="size" type="string" default="16:9">
  画面のアスペクト比。**テキストモードのみ有効**（画像/動画なしの場合）

  対応フォーマット：

  * `16:9` - 横向きワイド（デフォルト）
  * `9:16` - 縦向き
  * `1:1` - 正方形
  * `4:3` - 横向き
  * `3:4` - 縦向き

  <Warning>
    画像モードではこのパラメータは無視され、アスペクト比は入力画像により自動決定されます
  </Warning>
</ParamField>

<ParamField body="audio_url" type="string">
  カスタムオーディオURL

  * **テキストモード**：動画のBGMとして使用
  * **画像モード**：駆動音声として使用、画面のアクションに同期

  形式：wav / mp3、長さ2〜30秒、ファイルサイズ≤15MB

  <Warning>
    `audio_url` は `video_urls`、`image_urls`、`image_with_roles` と競合するため、これらと同時に指定することはできません
  </Warning>
</ParamField>

<ParamField body="prompt_extend" type="boolean" default="true">
  プロンプトのインテリジェントな書き換えを有効にするか

  短いプロンプトで効果が顕著ですが、処理時間が増加します

  デフォルト：`true`
</ParamField>

<ParamField body="watermark" type="boolean" default="false">
  生成された動画に "AI生成" ウォーターマークを追加するか

  * `true`：ウォーターマークを追加
  * `false`：追加しない（デフォルト）
</ParamField>

<ParamField body="seed" type="integer">
  生成内容のランダム性を制御するシード整数

  範囲：`≥0` の整数

  <Note>
    * 同一リクエストで異なるseed値を受け取ると（seedを指定しない場合など）、異なる結果が生成されます
    * 同一リクエストで同じseed値を受け取ると、類似した結果が生成されますが、完全一致は保証されません
  </Note>
</ParamField>

## レスポンス

<ResponseField name="code" type="integer">
  レスポンスステータスコード。成功時は 200
</ResponseField>

<ResponseField name="data" type="array">
  レスポンスデータ配列

  <Expandable title="配列要素">
    <ResponseField name="status" type="string">
      タスクステータス。初回送信時は `submitted`
    </ResponseField>

    <ResponseField name="task_id" type="string">
      タスクの一意識別子。タスクステータスおよび結果の取得に使用
    </ResponseField>
  </Expandable>
</ResponseField>

## 使用例

### 例 1：テキストから動画（最小リクエスト）

```json theme={null}
{
  "model": "wan2.7",
  "prompt": "夕日に照らされた海沿いの道路、スローモーションのカメラプッシュイン、映画のような映像"
}
```

### 例 2：テキストから動画（フルパラメータ）

```json theme={null}
{
  "model": "wan2.7",
  "prompt": "猫が草原で蝶を追いかける、晴天、スローモーション",
  "negative_prompt": "ぼやけ、歪み、低品質",
  "resolution": "1080P",
  "duration": 8,
  "size": "16:9",
  "audio_url": "https://cdn.example.com/bgm.mp3",
  "prompt_extend": true,
  "watermark": false,
  "seed": 42
}
```

### 例 3：先頭フレームから動画

```json theme={null}
{
  "model": "wan2.7",
  "prompt": "人物がゆっくり立ち上がり、カメラに向かって歩いてくる",
  "image_urls": ["https://cdn.example.com/person.jpg"],
  "resolution": "1080P",
  "duration": 8
}
```

### 例 4：先頭・最終フレームから動画

```json theme={null}
{
  "model": "wan2.7",
  "prompt": "カメラが海辺から山頂へゆっくり移動",
  "image_urls": [
    "https://cdn.example.com/beach.jpg",
    "https://cdn.example.com/mountain.jpg"
  ],
  "resolution": "1080P",
  "duration": 10
}
```

> 2枚指定の場合：1枚目が先頭フレーム、2枚目が最終フレーム。`image_with_roles` で精密指定も可能。

### 例 5：動画継続

```json theme={null}
{
  "model": "wan2.7",
  "prompt": "前進を続け、カメラが追随",
  "video_urls": ["https://cdn.example.com/clip.mp4"],
  "resolution": "1080P",
  "duration": 8
}
```

### 例 6：画像 + 駆動音声

```json theme={null}
{
  "model": "wan2.7",
  "prompt": "人物が音楽のリズムに合わせて動く",
  "image_urls": ["https://cdn.example.com/dancer.jpg"],
  "audio_url": "https://cdn.example.com/beat.mp3",
  "resolution": "1080P",
  "duration": 8
}
```

## モード選択ガイド

| 要件           | 推奨方法                      |
| ------------ | ------------------------- |
| テキストのみから動画生成 | `prompt` のみ指定（画像/動画なし）    |
| 画像を"動かす"     | `image_urls` に1枚指定        |
| 開始・終了シーンを制御  | `image_urls` に2枚指定（先頭+最終） |
| 既存動画を延長      | `video_urls` に動画を指定       |
| 画像を音楽に合わせる   | 画像 + `audio_url`          |

<Note>
  **タスク結果の取得**

  動画生成は非同期タスクで、送信時に `task_id` が返されます。[タスクステータス取得](/ja/api-reference/tasks/status) エンドポイントで生成進捗と結果を取得してください。
</Note>
