すべてのプロダクト
Search
ドキュメントセンター

Alibaba Cloud Model Studio:Wan2.7 - ビデオ編集 API リファレンス

最終更新日:Jun 04, 2026

Wan 2.7 ビデオ編集モデルは、命令に基づく編集およびスタイル変換のためのマルチモーダル入力(テキスト、画像、ビデオ)を受け付けます。

関連ドキュメントガイド

適用範囲

モデル、エンドポイント URL、API キーはすべて同一のリージョンに属している必要があります。クロスリージョンでの呼び出しは失敗します。

  • モデルの選択: モデルのリージョンを確認します。

  • エンドポイント URL の選択: 対応するリージョンのエンドポイント URL を選択します。HTTP および DashScope SDK の両方の URL がサポートされています。

  • API キーの設定: 対象リージョンのAPI キーを取得し、環境変数として設定します。

説明

本トピックのサンプルコードはシンガポールを使用しています。

重要

シンガポールリージョン向けのレガシドメイン https://dashscope-intl.aliyuncs.com はまもなく非推奨になります。できるだけ早く新しいドメイン https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com に移行してください。

HTTP

ビデオ編集タスクは通常 1~5 分かかります。この API は非同期呼び出しを採用しており、タスクの作成 → 結果のポーリングという 2 つの主要ステップで構成されます。

ステップ 1:タスクの作成

シンガポール

POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

WorkspaceId は実際のワークスペース IDに置き換えてください。

北京

POST https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis

説明
  • タスク作成後、返された task_id を使用して結果をクエリします。task_id の有効期間は 24 時間です。重複したタスクを作成しないでください。代わりに、ポーリングを使用して結果を取得してください。

  • 初心者向けのガイドについては、「Postman」をご参照ください。

リクエストパラメーター

命令のみによる編集

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-videoedit",
        "input": {
            "prompt": "Convert the entire scene to a claymation style",
            "media": [
                {
                    "type": "video",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/ldnfdf/wan2.7-videoedit-style-change.mp4"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "prompt_extend": true,
            "watermark": true
        }
    }'

命令とリファレンス画像による編集

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
        -H 'X-DashScope-Async: enable' \
        -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
        -H 'Content-Type: application/json' \
        -d '{
        "model": "wan2.7-videoedit",
        "input": {
            "prompt": "Replace the girl''s clothes in the video with the clothes from the image",
            "media": [
                {
                    "type": "video",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4"
                },
                {
                    "type": "reference_image",
                    "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png"
                }
            ]
        },
        "parameters": {
            "resolution": "720P",
            "prompt_extend": true,
            "watermark": true
        }
    }'

Content-Type string (必須)

リクエストのコンテンツタイプです。必ず application/json にしてください。

Authorization string (必須)

Model Studio API キーを使用してリクエストを認証します。例:Bearer sk-xxxx。

X-DashScope-Async string (必須)

非同期処理を有効にします。HTTP リクエストでは非同期呼び出しのみサポートされています。必ず enable にしてください。

重要

このリクエストヘッダーが指定されていない場合、「current user api does not support synchronous calls」というエラーが返されます。

リクエスト本文

model string (必須)

モデル名です。

例:wan2.7-videoedit。

input object (必須)

プロンプトを含む入力パラメーターです。

プロパティ

prompt string (任意)

生成されるビデオに求められる要素や視覚的特徴を記述します。

中国語および英語の両方がサポートされています。中国語の各文字または英語の各文字は 1 文字としてカウントされます。長いテキストは自動的に切り捨てられます。

  • wan2.7-videoedit:最大 5,000 文字。

例:キャラクターの服をクールで派手な衣装に変更し、リファレンス画像の帽子を追加してください。

negative_prompt string (任意)

ビデオから除外したい内容を記述する否定的なプロンプトで、出力を洗練させるのに役立ちます。

中国語および英語の両方がサポートされています。長さは 500 文字を超えてはいけません。長いテキストは自動的に切り捨てられます。

例:低解像度、エラー、最悪の品質、低品質、歪んだ、余分な指、不均衡な比率。

media array (必須)

ビデオ生成のリファレンスとして使用される画像やビデオなどのメディアアセットのリストです。

配列内の各要素は、type および url フィールドを含むメディアオブジェクトです。

プロパティ

type string (必須)

メディアアセットのタイプです。有効値:

  • video:必須。編集対象のビデオ。

  • reference_image:任意。リファレンス画像。

アセット制限:

  • ビデオは 1 つだけ許可されています。

  • リファレンス画像は最大 4 枚までです。

url string (必須)

メディアアセットの URL または Base64 エンコードデータです。アセットにはビデオと画像が含まれます。

入力ビデオ(type=video)

編集対象のビデオファイルの URL です。

ビデオ要件:

  • 形式:MP4、MOV。

  • 長さ:2~10 秒。

  • 解像度:幅および高さは 240~4096 ピクセルの範囲内である必要があります。

  • 縦横比:1:8~8:1。

  • ファイルサイズ:最大 100 MB。

サポートされる入力形式:

  1. 公開 URL:

    • HTTP および HTTPS プロトコルがサポートされています。

    • 例:https://xxx/xxx.mp4。

入力画像(type=reference_image)

リファレンス画像の URL または Base64 エンコードデータです。

画像要件:

  • 形式:JPEG、JPG、PNG(alpha チャンネルは未対応)、BMP、WEBP。

  • 解像度:幅および高さは 240~8000 ピクセルの範囲内である必要があります。

  • 縦横比:1:8~8:1。

  • ファイルサイズ:最大 20 MB。

サポートされる入力形式:

  1. 公開 URL:

    • HTTP および HTTPS プロトコルがサポートされています。

    • 例:https://xxx/xxx.png。

  2. Base64 エンコード文字列:

    • データ形式:data:{MIME_type};base64,{base64_data}

    • 例:data:image/png;base64,GDU7MtCZzEbTbmRZ......(この例は説明のために省略されています)。

    Base64 エンコードデータ形式

    形式:data:{MIME_type};base64,{base64_data}

    • {base64_data}:画像ファイルの Base64 エンコード文字列。

    • {MIME_type}:画像のメディアタイプで、ファイル形式に対応している必要があります。

    画像形式

    MIME タイプ

    JPEG

    image/jpeg

    JPG

    image/jpeg

    PNG

    image/png

    BMP

    image/bmp

    WEBP

    image/webp

parameters object (任意)

解像度、長さ、インテリジェントプロンプトリライト、ウォーターマークなどのビデオ処理パラメーターです。

プロパティ

resolution string (任意)

生成されるビデオの解像度階層で、その鮮明さ(総ピクセル数)を制御します。

  • wan2.7-videoedit:有効値は 720P および 1080P です。デフォルト値は 1080P です。

ratio string (任意)

生成されるビデオの縦横比です。

動作:

  • ratio パラメーターを指定しない場合、モデルは入力ビデオと同様の縦横比を持つビデオを生成します。

  • ratio パラメーターを指定した場合、モデルは指定された ratio の縦横比を持つビデオを生成します。

有効値:

  • 16:9

  • 9:16

  • 1:1

  • 4:3

  • 3:4

異なる縦横比における出力ビデオの解像度(幅 × 高さ)については、以下の表をご参照ください。

解像度階層

縦横比

出力ビデオ解像度(幅*高さ)

720P

16:9

1280*720

9:16

720*1280

1:1

960*960

4:3

1104*832

3:4

832*1104

1080P

16:9

1920*1080

9:16

1080*1920

1:1

1440*1440

4:3

1648*1248

3:4

1248*1648

duration integer (任意)

生成されるビデオの長さ(秒単位)です。

推奨事項: このパラメーターはビデオを切り詰める場合にのみ設定してください。入力ビデオと同じ長さを維持するには、このパラメーターを省略するか、デフォルト値の 0 を渡してください。

使用ルール:

  • デフォルト動作:デフォルト値は 0 で、入力ビデオの長さが切り詰められずに使用されます。

  • 切り詰め:特定の長さを渡すと、システムは元のビデオを 0 秒から duration で指定された長さまで切り詰めます。

  • 値の範囲:[2, 10] の範囲内の整数。

audio_setting string (任意)

ビデオの音声設定です。

  • auto(デフォルト):モデルは prompt に基づいて音声をインテリジェントに決定します。プロンプトが音声を記述している場合、新しい音声が生成される可能性があります。それ以外の場合、入力アセットの元の音声が保持される可能性があります。

  • origin:入力ビデオの元の音声を強制的に保持し、再生成しません。

prompt_extend boolean (任意)

インテリジェントプロンプトリライトを有効にします。有効にすると、大規模モデルが入力プロンプトを書き換え、短いプロンプトの場合に生成品質を大幅に向上させますが、処理時間が増加します。

  • true:デフォルト値。インテリジェント書き換えを有効にします。

  • false:インテリジェント書き換えを無効にします。

watermark boolean (任意)

ウォーターマークを追加するかどうかを指定します。ウォーターマークはビデオの右下隅に「AI Generated」というテキストで表示されます。

  • false(デフォルト)

  • true

例:false。

seed integer (任意)

乱数シードで、[0, 2147483647] の範囲内の整数である必要があります。

指定しない場合、ランダムなシードが生成されます。固定シードを使用すると、再現性が向上します。

モデル生成は確率的であるため、同じシードでも完全に同一の結果が保証されるわけではありません。

レスポンスパラメーター

成功時のレスポンス

task_id を保存して、タスクのステータスと結果をクエリします。

{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

エラー時のレスポンス

タスクの作成に失敗しました。「エラーコード」をご参照ください。

{
    "code": "InvalidApiKey",
    "message": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

output object

タスクの出力を含みます。

プロパティ

task_id string

タスク ID です。クエリの有効期間は 24 時間です。

task_status string

タスクのステータスです。

列挙値

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN:タスクが存在しない、またはステータスが不明です。

request_id string

トレースおよびトラブルシューティング用の一意なリクエスト識別子です。

code string

エラーコードです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。

message string

詳細なエラーメッセージです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。

ステップ 2:結果のクエリ

シンガポール

GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}

WorkspaceId は実際のワークスペース IDに置き換えてください。

北京

GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}

説明
  • ポーリングの推奨事項: ビデオ生成には数分かかります。15 秒などの適切な間隔でポーリングメカニズムを使用してください。

  • タスク状態の遷移: PENDING → RUNNING → SUCCEEDED または FAILED。

  • 結果リンク: タスクが成功すると、24 時間有効なビデオ URL が返されます。OSS などの永続ストレージにビデオをダウンロードして保存してください。

  • task_id の有効期間24 時間。この期間を過ぎると、クエリはタスクステータスとして UNKNOWN を返します。

リクエストパラメーター

結果のクエリ

{task_id} は前回の API 呼び出しで返された task_id の値に置き換えてください。task_id の有効期間は 24 時間です。

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
ヘッダー

Authorization string (必須)

Model Studio API キーを使用してリクエストを認証します。例:Bearer sk-xxxx。

パスパラメーター

task_id string (必須)

タスクの ID です。

レスポンスパラメーター

タスク成功

ビデオ URL の有効期間は 24 時間のみで、その後自動的に消去されます。生成されたビデオは速やかに保存してください。

{
    "request_id": "f16ae7e9-d518-92f8-a02c-xxxxxx",
    "output": {
        "task_id": "05e68c7e-850c-49e4-b866-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2026-04-03 00:08:03.576",
        "scheduled_time": "2026-04-03 00:08:13.408",
        "end_time": "2026-04-03 00:11:57.286",
        "orig_prompt": "Replace the girl''s clothes in the video with the clothes from the image",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?xxxx"
    },
    "usage": {
        "duration": 10.04,
        "input_video_duration": 5.02,
        "output_video_duration": 5.02,
        "video_count": 1,
        "SR": 720
    }
}

タスク失敗

タスクが失敗した場合、task_status は FAILED となり、エラーコードおよびメッセージが返されます。「エラーコード」をご参照ください。

{
    "request_id": "e5d70b02-ebd3-98ce-9fe8-759d7d7b107d",
    "output": {
        "task_id": "86ecf553-d340-4e21-af6e-a0c6a421c010",
        "task_status": "FAILED",
        "code": "InvalidParameter",
        "message": "The size is not match xxxxxx"
    }
}

期限切れクエリ

task_id の有効期間は 24 時間です。この期間を過ぎると、クエリは次のエラーを返します。

{
    "request_id": "a4de7c32-7057-9f82-8581-xxxxxx",
    "output": {
        "task_id": "502a00b1-19d9-4839-a82f-xxxxxx",
        "task_status": "UNKNOWN"
    }
}

output object

タスクの出力を含みます。

プロパティ

task_id string

タスク ID です。クエリの有効期間は 24 時間です。

task_status string

タスクのステータスです。

列挙値

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN:タスクが存在しない、またはステータスが不明です。

ポーリング中の状態遷移:

  • PENDING → RUNNING → SUCCEEDED または FAILED。

  • 初期クエリのステータスは通常 PENDING または RUNNING です。

  • ステータスが SUCCEEDED に変化すると、レスポンスに生成されたビデオ URL が含まれます。

  • ステータスが FAILED の場合、エラーメッセージを確認してタスクを再試行してください。

submit_time string

タスクが送信された時刻です。時刻は UTC + 08:00 で、形式は YYYY-MM-DD HH:mm:ss.SSS です。

scheduled_time string

タスクが実行された時刻です。時刻は UTC + 08:00 で、形式は YYYY-MM-DD HH:mm:ss.SSS です。

end_time string

タスクが完了した時刻です。時刻は UTC + 08:00 で、形式は YYYY-MM-DD HH:mm:ss.SSS です。

video_url string

生成されたビデオの URL です。task_status が SUCCEEDED の場合にのみ返されます。

有効期間は 24 時間です。ビデオは H.264 エンコーディングの MP4 形式です。

orig_prompt string

元の入力プロンプトで、リクエストパラメーター prompt に対応します。

code string

エラーコードです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。

message string

詳細なエラーメッセージです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。

usage object

課金用の使用量統計です。成功したタスクに対してのみ課金されます。

プロパティ

input_video_duration float

入力ビデオの長さ(秒単位)です。

output_video_duration float

出力ビデオの長さ(秒単位)です。

duration float

課金に使用される合計ビデオ長さです。

課金式:duration=input_video_duration+output_video_duration

SR integer

出力ビデオの解像度階層です。例:720。

video_count integer

生成されたビデオの数です。この値は常に 1 です。

request_id string

トレースおよびトラブルシューティング用の一意なリクエスト識別子です。

DashScope SDK

SDK 内のパラメーター名はHTTP APIとほぼ一致していますが、パラメーター構造は各言語の規則に従います。

ビデオ編集には通常 1~5 分かかります。SDK は非同期 HTTP 呼び出しプロセスを内部で処理し、同期および非同期の両方の呼び出しをサポートしています。

実際の処理時間は、キュー内のタスク数およびサービスステータスによって異なります。結果が完了するまでお待ちください。

Python SDK

重要

DashScope Python SDK バージョン 1.25.16 以降を使用していることを確認してください。

古いバージョンを使用すると、「url error, please check url!」などのエラーが発生する可能性があります。バージョンを更新するには、「SDK のインストール」をご参照ください。

サービスリージョンに基づいて base_http_api_url を設定します。

シンガポール

dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

WorkspaceId は実際のワークスペース IDに置き換えてください。

中国 (北京)

dashscope.base_http_api_url = 'https://dashscope.aliyuncs.com/api/v1'

同期呼び出し

リクエスト例
import base64
import mimetypes
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 以下はシンガポールリージョンの URL です。URL はリージョン固有です。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# DASHSCOPE_API_KEY 環境変数が設定されていない場合は、ここに Model Studio API キーを指定します:api_key="sk-xxx"
# API キーはリージョン固有です。API キーの取得方法については、https://www.alibabacloud.com/help/ja/model-studio/get-api-key をご参照ください。
api_key = os.getenv("DASHSCOPE_API_KEY")

# 形式は data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
    mime_type, _ = mimetypes.guess_type(file_path)
    if not mime_type or not mime_type.startswith("image/"):
        raise ValueError("Unsupported or unrecognized image format.")
    with open(file_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
    return f"data:{mime_type};base64,{encoded_string}"

# reference_image_url パラメーターは以下の 3 つの入力方法をサポートしています。

# 方法 1:画像の公開 URL を使用。
reference_image_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png"

# 方法 2:ローカルファイルを使用(絶対パスおよび相対パスがサポートされています)。
# 形式:file:// + ファイルパス
# 例(絶対パス):
# reference_image_url = "file://" + "/path/to/image.png"     # Linux/macOS
# reference_image_url = "file://" + "C:/path/to/image.png"    # Windows
# 例(相対パス):
# reference_image_url = "file://" + "./image.png"             # 現在のスクリプトのパスからの相対パス。

# 方法 3:Base64 エンコード文字列。
# reference_image_url = encode_file("/path/to/image.png")

def sample_sync_call_videoedit():
    # 同期 API を呼び出し、結果を直接返します。
    print('Please wait...')
    rsp = VideoSynthesis.call(
        api_key=api_key,
        model='wan2.7-videoedit',
        prompt='Replace the clothes of the girl in the video with the clothes from the image.',
        media=[
            {
                "type": "video",
                "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4"
            },
            {
                "type": "reference_image",
                "url": reference_image_url
            }
        ],
        resolution='720P',
        prompt_extend=True,
        watermark=True)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

if __name__ == '__main__':
    sample_sync_call_videoedit()
レスポンス例
video_url の有効期間は 24 時間です。ビデオは速やかにダウンロードしてください。
{
    "status_code": 200,
    "request_id": "d6c3c865-34e9-98a9-a53d-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "1de7c853-755a-454a-91bc-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
        "submit_time": "2026-04-10 17:16:30.821",
        "scheduled_time": "2026-04-10 17:16:46.379",
        "end_time": "2026-04-10 17:24:59.352",
        "orig_prompt": "Replace the clothes of the girl in the video with the clothes from the image."
    },
    "usage": {
        "video_count": 1,
        "video_duration": 0,
        "video_ratio": "",
        "duration": 10.08,
        "input_video_duration": 5.04,
        "output_video_duration": 5.04,
        "SR": 720
    }
}

非同期呼び出し

リクエスト例
import base64
import mimetypes
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os

# 以下はシンガポールリージョンの URL です。URL はリージョン固有です。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'

# DASHSCOPE_API_KEY 環境変数が設定されていない場合は、ここに Model Studio API キーを指定します:api_key="sk-xxx"
# API キーはリージョン固有です。API キーの取得方法については、https://www.alibabacloud.com/help/ja/model-studio/get-api-key をご参照ください。
api_key = os.getenv("DASHSCOPE_API_KEY")

# 形式は data:{MIME_type};base64,{base64_data}
def encode_file(file_path):
    mime_type, _ = mimetypes.guess_type(file_path)
    if not mime_type or not mime_type.startswith("image/"):
        raise ValueError("Unsupported or unrecognized image format.")
    with open(file_path, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
    return f"data:{mime_type};base64,{encoded_string}"

# reference_image_url パラメーターは以下の 3 つの入力方法をサポートしています。

# 方法 1:画像の公開 URL を使用。
reference_image_url = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png"

# 方法 2:ローカルファイルを使用(絶対パスおよび相対パスがサポートされています)。
# 形式:file:// + ファイルパス
# 例(絶対パス):
# reference_image_url = "file://" + "/path/to/image.png"     # Linux/macOS
# reference_image_url = "file://" + "C:/path/to/image.png"    # Windows
# 例(相対パス):
# reference_image_url = "file://" + "./image.png"             # 現在のスクリプトのパスからの相対パス。

# 方法 3:Base64 エンコード文字列。
# reference_image_url = encode_file("/path/to/image.png")

def sample_async_call_videoedit():
    # 非同期 API を呼び出し、タスク情報を返します。
    # 返されたタスク ID を使用してタスクステータスを確認できます。
    rsp = VideoSynthesis.async_call(
        api_key=api_key,
        model='wan2.7-videoedit',
        prompt='Replace the clothes of the girl in the video with the clothes from the image.',
        media=[
            {
                "type": "video",
                "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4"
            },
            {
                "type": "reference_image",
                "url": reference_image_url
            }
        ],
        resolution='720P',
        prompt_extend=True,
        watermark=True)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print("task_id: %s" % rsp.output.task_id)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

    # タスク情報を取得します(タスクステータスを含む)。
    status = VideoSynthesis.fetch(task=rsp, api_key=api_key)
    if status.status_code == HTTPStatus.OK:
        print(status.output.task_status)  # タスクステータスを確認します。
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (status.status_code, status.code, status.message))

    # タスクが完了するまで待ちます。このメソッドはタスクが完了するまで一定間隔でポーリングします。
    rsp = VideoSynthesis.wait(task=rsp, api_key=api_key)
    print(rsp)
    if rsp.status_code == HTTPStatus.OK:
        print(rsp.output.video_url)
    else:
        print('Failed, status_code: %s, code: %s, message: %s' %
              (rsp.status_code, rsp.code, rsp.message))

if __name__ == '__main__':
    sample_async_call_videoedit()
レスポンス例
  1. タスク作成時のレスポンス

    {
        "status_code": 200,
        "request_id": "f16ae7e9-d518-92f8-a02c-xxxxxx",
        "code": "",
        "message": "",
        "output": {
            "task_id": "05e68c7e-850c-49e4-b866-xxxxxx",
            "task_status": "PENDING",
            "video_url": ""
        },
        "usage": null
    }
  2. タスククエリ時のレスポンス

    video_url の有効期間は 24 時間です。ビデオは速やかにダウンロードしてください。
    {
        "status_code": 200,
        "request_id": "d6c3c865-34e9-98a9-a53d-xxxxxx",
        "code": null,
        "message": "",
        "output": {
            "task_id": "1de7c853-755a-454a-91bc-xxxxxx",
            "task_status": "SUCCEEDED",
            "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxxx",
            "submit_time": "2026-04-10 17:16:30.821",
            "scheduled_time": "2026-04-10 17:16:46.379",
            "end_time": "2026-04-10 17:24:59.352",
            "orig_prompt": "Replace the clothes of the girl in the video with the clothes from the image."
        },
        "usage": {
            "video_count": 1,
            "video_duration": 0,
            "video_ratio": "",
            "duration": 10.08,
            "input_video_duration": 5.04,
            "output_video_duration": 5.04,
            "SR": 720
        }
    }

Java SDK

重要

DashScope Java SDK バージョン 2.22.14 以降を使用していることを確認してください。

古いバージョンを使用すると、「url error, please check url!」などのエラーが発生する可能性があります。バージョンを更新するには、「SDK のインストール」をご参照ください。

サービスリージョンに基づいて Constants.baseHttpApiUrl を設定します。

シンガポール

Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";

WorkspaceId は実際のワークスペース IDに置き換えてください。

中国 (北京)

Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";

同期呼び出し

リクエスト例
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;

public class VideoEdit {

    static {
        // 以下はシンガポールリージョンの URL です。URL はリージョン固有です。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // DASHSCOPE_API_KEY 環境変数が設定されていない場合は、ここに Model Studio API キーを指定します:apiKey="sk-xxx"
    // API キーはリージョン固有です。API キーの取得方法については、https://www.alibabacloud.com/help/ja/model-studio/get-api-key をご参照ください。
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    // referenceImageUrl パラメーターは以下の 3 つの入力方法をサポートしています。

    // 方法 1:画像の公開 URL を使用。
    static String referenceImageUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png";

    // 方法 2:ローカルファイルを使用(絶対パスおよび相対パスがサポートされています)。
    // 形式:file:// + ファイルパス
    // 例(絶対パス):
    // static String referenceImageUrl = "file://" + "/path/to/image.png";     // Linux/macOS
    // static String referenceImageUrl = "file://" + "C:/path/to/image.png";   // Windows
    // 例(相対パス):
    // static String referenceImageUrl = "file://" + "./image.png";             // 現在の実行可能ファイルのパスからの相対パス。

    // 方法 3:Base64 エンコーディングを使用。
    // static String referenceImageUrl = encodeFile("/path/to/image.png");

    // 形式は data:{MIME_type};base64,{base64_data}
    public static String encodeFile(String filePath) {
        Path path = Paths.get(filePath);
        if (!Files.exists(path)) {
            throw new IllegalArgumentException("File does not exist: " + filePath);
        }
        String mimeType = null;
        try {
            mimeType = Files.probeContentType(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot detect file type: " + filePath);
        }
        if (mimeType == null || !mimeType.startsWith("image/")) {
            throw new IllegalArgumentException("Unsupported or unrecognized image format.");
        }
        byte[] fileBytes = null;
        try {
            fileBytes = Files.readAllBytes(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot read file content: " + filePath);
        }
        String encodedString = Base64.getEncoder().encodeToString(fileBytes);
        return "data:" + mimeType + ";base64," + encodedString;
    }

    public static void videoEdit() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4")
                    .type("video")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url(referenceImageUrl)
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("prompt_extend", true);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-videoedit")
                        .prompt("Replace the clothes of the girl in the video with the clothes from the image.")
                        .media(media)
                        .parameters(parameters)
                        .build();
        System.out.println("Please wait...");
        VideoSynthesisResult result = vs.call(param);
        System.out.println(JsonUtils.toJson(result));
    }

    public static void main(String[] args) {
        try {
            videoEdit();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
レスポンス例
video_url の有効期間は 24 時間です。ビデオは速やかにダウンロードしてください。
{
    "request_id": "0a15ad3c-cde7-9f7e-b8d2-xxxxxx",
    "output": {
        "task_id": "0025d1e1-009a-4f53-9c27-xxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "orig_prompt": "Replace the clothes of the girl in the video with the clothes from the image.",
        "submit_time": "2026-04-10 17:21:01.719",
        "scheduled_time": "2026-04-10 17:21:13.182",
        "end_time": "2026-04-10 17:31:41.286"
    },
    "usage": {
        "video_count": 1,
        "duration": 10.08,
        "input_video_duration": 5.04,
        "output_video_duration": 5.04,
        "SR": "720"
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

非同期呼び出し

リクエスト例
// Copyright (c) Alibaba, Inc. and its affiliates.

import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisParam;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisResult;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;

public class VideoEdit {

    static {
        // 以下はシンガポールリージョンの URL です。URL はリージョン固有です。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // DASHSCOPE_API_KEY 環境変数が設定されていない場合は、ここに Model Studio API キーを指定します:apiKey="sk-xxx"
    // API キーはリージョン固有です。API キーの取得方法については、https://www.alibabacloud.com/help/ja/model-studio/get-api-key をご参照ください。
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    // referenceImageUrl パラメーターは以下の 3 つの入力方法をサポートしています。

    // 方法 1:画像の公開 URL を使用。
    static String referenceImageUrl = "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260402/fwjpqf/wan2.7-videoedit-change-clothes.png";

    // 方法 2:ローカルファイルを使用(絶対パスおよび相対パスがサポートされています)。
    // 形式:file:// + ファイルパス
    // 例(絶対パス):
    // static String referenceImageUrl = "file://" + "/path/to/image.png";     // Linux/macOS
    // static String referenceImageUrl = "file://" + "C:/path/to/image.png";   // Windows
    // 例(相対パス):
    // static String referenceImageUrl = "file://" + "./image.png";             // 現在の実行可能ファイルのパスからの相対パス。

    // 方法 3:Base64 エンコーディングを使用。
    // static String referenceImageUrl = encodeFile("/path/to/image.png");

    // 形式は data:{MIME_type};base64,{base64_data}
    public static String encodeFile(String filePath) {
        Path path = Paths.get(filePath);
        if (!Files.exists(path)) {
            throw new IllegalArgumentException("File does not exist: " + filePath);
        }
        String mimeType = null;
        try {
            mimeType = Files.probeContentType(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot detect file type: " + filePath);
        }
        if (mimeType == null || !mimeType.startsWith("image/")) {
            throw new IllegalArgumentException("Unsupported or unrecognized image format.");
        }
        byte[] fileBytes = null;
        try {
            fileBytes = Files.readAllBytes(path);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot read file content: " + filePath);
        }
        String encodedString = Base64.getEncoder().encodeToString(fileBytes);
        return "data:" + mimeType + ";base64," + encodedString;
    }

    public static void videoEdit() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        List<VideoSynthesisParam.Media> media = new ArrayList<VideoSynthesisParam.Media>(){{
            add(VideoSynthesisParam.Media.builder()
                    .url("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260403/nlspwm/T2VA_22.mp4")
                    .type("video")
                    .build());
            add(VideoSynthesisParam.Media.builder()
                    .url(referenceImageUrl)
                    .type("reference_image")
                    .build());
        }};
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("resolution", "720P");
        parameters.put("prompt_extend", true);
        parameters.put("watermark", true);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.7-videoedit")
                        .prompt("Replace the clothes of the girl in the video with the clothes from the image.")
                        .media(media)
                        .parameters(parameters)
                        .build();

        // 非同期呼び出しを行います。
        VideoSynthesisResult task = vs.asyncCall(param);
        System.out.println(JsonUtils.toJson(task));
        System.out.println("Please wait...");

        // タスクが完了するまで待ち、最終結果を取得します。
        VideoSynthesisResult result = vs.wait(task, apiKey);
        System.out.println(JsonUtils.toJson(result));
    }

    // タスクリストを取得します。
    public static void listTask() throws ApiException, NoApiKeyException {
        VideoSynthesis is = new VideoSynthesis();
        AsyncTaskListParam param = AsyncTaskListParam.builder().build();
        param.setApiKey(apiKey);
        VideoSynthesisListResult result = is.list(param);
        System.out.println(result);
    }

    // 単一タスクの結果を取得します。
    public static void fetchTask(String taskId) throws ApiException, NoApiKeyException {
        VideoSynthesis is = new VideoSynthesis();
        // DASHSCOPE_API_KEY 環境変数が設定されている場合、apiKey は null にできます。
        VideoSynthesisResult result = is.fetch(taskId, apiKey);
        System.out.println(result.getOutput());
        System.out.println(result.getUsage());
    }

    public static void main(String[] args) {
        try {
            videoEdit();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
レスポンス例
  1. タスク作成時のレスポンス

    {
        "request_id": "f16ae7e9-d518-92f8-a02c-xxxxxx",
        "output": {
            "task_id": "05e68c7e-850c-49e4-b866-xxxxxx",
            "task_status": "PENDING",
            "video_url": ""
        },
        "usage": null,
        "status_code": 200,
        "code": "",
        "message": ""
    }
  2. タスククエリ時のレスポンス

    video_url の有効期間は 24 時間です。ビデオは速やかにダウンロードしてください。
    {
        "request_id": "0a15ad3c-cde7-9f7e-b8d2-xxxxxx",
        "output": {
            "task_id": "0025d1e1-009a-4f53-9c27-xxxxx",
            "task_status": "SUCCEEDED",
            "video_url": "https://dashscope-a717.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
            "orig_prompt": "Replace the clothes of the girl in the video with the clothes from the image.",
            "submit_time": "2026-04-10 17:21:01.719",
            "scheduled_time": "2026-04-10 17:21:13.182",
            "end_time": "2026-04-10 17:31:41.286"
        },
        "usage": {
            "video_count": 1,
            "duration": 10.08,
            "input_video_duration": 5.04,
            "output_video_duration": 5.04,
            "SR": "720"
        },
        "status_code": 200,
        "code": "",
        "message": ""
    }

エラーコード

モデル呼び出しが失敗した場合は、「エラーコード」を参照してトラブルシューティングを行ってください。