> ## 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-R2V リファレンス動画生成

>  - アリババクラウド万相 2.7 リファレンス動画生成モデル
- 1枚以上の参考画像/動画に基づき、スタイル・キャラクター・シーンに一貫性のある新しい動画を生成
- キャラクター一貫性、スタイル転送、複数素材の組み合わせに対応
- 参考音声（reference_voice）によるキャラクターボイス制御に対応 

<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-r2v",
      "prompt": "この人物が車が行き交う通りを歩いている",
      "image_with_roles": [{"url": "https://cdn.example.com/character.jpg", "role": "reference_image"}],
      "resolution": "1080P",
      "duration": 8
    }'
  ```

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

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

  payload = {
      "model": "wan2.7-r2v",
      "prompt": "この人物が車が行き交う通りを歩いている",
      "image_with_roles": [{"url": "https://cdn.example.com/character.jpg", "role": "reference_image"}],
      "resolution": "1080P",
      "duration": 8
  }

  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-r2v",
    prompt: "この人物が車が行き交う通りを歩いている",
    image_with_roles: [{ url: "https://cdn.example.com/character.jpg", role: "reference_image" }],
    resolution: "1080P",
    duration: 8
  };

  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-r2v",
          "prompt": "この人物が車が行き交う通りを歩いている",
          "image_with_roles": []map[string]string{
              {"url": "https://cdn.example.com/character.jpg", "role": "reference_image"},
          },
          "resolution": "1080P",
          "duration":   8,
      }

      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-r2v",
            "prompt": "この人物が車が行き交う通りを歩いている",
            "image_with_roles": [{"url": "https://cdn.example.com/character.jpg", "role": "reference_image"}],
            "resolution": "1080P",
            "duration": 8
          }
          """;

          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-r2v",
      "prompt" => "この人物が車が行き交う通りを歩いている",
      "image_with_roles" => [["url" => "https://cdn.example.com/character.jpg", "role" => "reference_image"]],
      "resolution" => "1080P",
      "duration" => 8
  ];

  $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-r2v",
    prompt: "この人物が車が行き交う通りを歩いている",
    image_with_roles: [{ url: "https://cdn.example.com/character.jpg", role: "reference_image" }],
    resolution: "1080P",
    duration: 8
  }

  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-r2v",
      "prompt": "この人物が車が行き交う通りを歩いている",
      "image_with_roles": [["url": "https://cdn.example.com/character.jpg", "role": "reference_image"]],
      "resolution": "1080P",
      "duration": 8
  ]

  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-r2v"",
              ""prompt"": ""この人物が車が行き交う通りを歩いている"",
              ""image_with_roles"": [{""url"": ""https://cdn.example.com/character.jpg"", ""role"": ""reference_image""}],
              ""resolution"": ""1080P"",
              ""duration"": 8
          }";

          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>

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

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

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

  複数画像/動画の場合、「画像1」「画像2」「動画1」などの番号で参考素材を指定（入力順）

  例：`"画像1の人物が画像2のシーンに入り、周りを見回す"`
</ParamField>

<ParamField body="image_with_roles" type="array<object>">
  ロール付き画像の配列。`video_urls` と少なくとも片方を指定

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

  * `url` (string)：画像URL
  * `role` (string)：画像ロール
    * `reference_image` - 参考画像（デフォルト）
    * `first_frame` - 先頭フレーム指定（指定すると `size` パラメータは無効となり、先頭フレーム画像のアスペクト比が適用されます）
  * `reference_voice` (string、任意)：参考キャラクターの音声サンプルURL。生成動画内のキャラクターボイスの制御に使用

  例：

  ```json theme={null}
  [
    {
      "url": "https://cdn.example.com/character.jpg",
      "role": "reference_image",
      "reference_voice": "https://cdn.example.com/voice_sample.mp3"
    },
    { "url": "https://cdn.example.com/start.jpg", "role": "first_frame" }
  ]
  ```
</ParamField>

<ParamField body="video_urls" type="array<string>">
  参考動画URLの配列。最大 5 本（画像+動画の合計 ≤ 5）

  `image_with_roles` と少なくとも片方を指定

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

    * フォーマット：mp4、mov
    * 長さ：1〜30秒
    * 解像度：幅・高さともに \[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`

  <Warning>
    参考素材に動画が含まれる場合：\[2, 10] の範囲の整数

    参考素材に動画が含まれない場合：\[2, 15] の範囲の整数
  </Warning>
</ParamField>

<ParamField body="size" type="string" default="16:9">
  画面のアスペクト比

  対応フォーマット：

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

  <Warning>
    `image_with_roles` で `first_frame` を指定した場合、このパラメータは無視され、先頭フレーム画像のアスペクト比が適用されます
  </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-r2v",
  "prompt": "この人物が車が行き交う通りを歩いている",
  "image_with_roles": [
    { "url": "https://cdn.example.com/character.jpg", "role": "reference_image" }
  ]
}
```

### 例 2：複数参考画像

```json theme={null}
{
  "model": "wan2.7-r2v",
  "prompt": "画像1の人物が画像2のシーンに入り、画像3のポーズを真似る",
  "image_with_roles": [
    { "url": "https://cdn.example.com/person.jpg", "role": "reference_image" },
    { "url": "https://cdn.example.com/background.jpg", "role": "reference_image" },
    { "url": "https://cdn.example.com/pose.jpg", "role": "reference_image" }
  ],
  "resolution": "1080P",
  "duration": 8,
  "size": "16:9"
}
```

### 例 3：参考動画ベースの生成

```json theme={null}
{
  "model": "wan2.7-r2v",
  "prompt": "参考動画のスタイルで海辺の夕日シーンを生成",
  "video_urls": ["https://cdn.example.com/style_reference.mp4"],
  "resolution": "720P",
  "duration": 8
}
```

### 例 4：先頭フレーム指定 + 参考画像

```json theme={null}
{
  "model": "wan2.7-r2v",
  "prompt": "参考人物がこの位置から前方へ歩き出す",
  "image_with_roles": [
    { "url": "https://cdn.example.com/character.jpg", "role": "reference_image" },
    { "url": "https://cdn.example.com/start.jpg", "role": "first_frame" }
  ],
  "resolution": "1080P",
  "duration": 8
}
```

### 例 5：参考画像 + 参考音声（精密）

```json theme={null}
{
  "model": "wan2.7-r2v",
  "prompt": "この人物が通りを歩きながら話す",
  "image_with_roles": [
    {
      "url": "https://cdn.example.com/character.jpg",
      "role": "reference_image",
      "reference_voice": "https://cdn.example.com/voice_sample.mp3"
    }
  ],
  "resolution": "1080P",
  "duration": 10
}
```

## 画像参照ルール

複数参考画像がある場合、`prompt` 内で番号を使って参照：

* 1枚目 → 「画像1」または「1枚目の画像」
* 1本目の動画 → 「動画1」または「1本目の動画」

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

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