Skip to main content

Wan - テキスト動画生成 API リファレンス (2.1-2.6)

Wan テキスト動画生成モデルは、 テキストプロンプト からスムーズな動画を生成します。

リファレンス: ユーザーガイド

利用可能リージョン

呼び出しを成功させるには、モデル、エンドポイント URL、API キーがすべて同じリージョンに属している必要があります。リージョン間の呼び出しは失敗します。
このトピックのサンプルコードは、シンガポールリージョンに適用されます。
Alibaba Cloud Model Studio は、中国 (北京) およびシンガポールリージョン向けにワークスペース専用ドメインをリリースしました。新しい専用ドメインは、推論リクエストに対して優れたパフォーマンスと高い安定性を提供します。新しいドメインへの移行を推奨します:
  • 中国 (北京): https://dashscope.aliyuncs.com から https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com へ
  • シンガポール: https://dashscope-intl.aliyuncs.com から https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com へ
{WorkspaceId} は、Alibaba Cloud Model Studio コンソールの [ワークスペース詳細] ページで確認できるワークスペース ID です。既存のドメインも引き続き完全に機能します。

HTTP

この API はレガシープロトコルを使用し、wan2.6 およびそれ以前のモデル (wan2.5/wan2.2/wan2.1) をサポートします。
テキスト動画生成タスクは時間がかかるため (通常 1〜5 分)、API は非同期呼び出しを使用します。プロセス全体には、タスクの作成 -> 結果のポーリングという 2 つのコアステップが含まれます。プロセスは次のとおりです:

ステップ 1:タスクを作成し、タスク ID を取得する

  • シンガポール
  • 米国 (バージニア)
  • フランクフルト
  • 北京
POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis{WorkspaceId} を実際のワークスペース ID に置き換えてください。
  • タスクが作成された後、返された task_id を使用して結果をクエリします。task_id は 24 時間有効です。重複したタスクを作成しないでください。代わりに、ポーリングを使用して結果を取得してください。
  • 初心者向けのガイダンスについては、「Postman または cURL を使用した API の呼び出し」をご参照ください。

リクエストパラメーター

リクエストヘッダー
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.6-t2v。input object (必須)プロンプトなどの基本的な入力情報を含みます。

プロパティ

prompt string (必須)テキストプロンプトです。生成される動画の望ましい要素と視覚的特徴を記述します。プロンプトは中国語または英語で指定できます。長さは文字数で測定され、各漢字またはアルファベットは 1 文字としてカウントされます。文字数制限を超えたテキストは自動的に切り捨てられます。文字数制限はモデルのバージョンによって異なります:
  • wan2.6 および wan2.5 シリーズモデル:最大 1,500 文字。
  • wan2.2 および wan2.1 シリーズモデル:最大 800 文字。
例:月明かりの下を走る子猫。詳細については、「テキスト動画生成/画像動画生成プロンプトガイド」をご参照ください。negative_prompt string (任意)動画から除外するコンテンツを記述するプロンプトです。これにより、生成されるコンテンツを洗練させることができます。プロンプトは中国語または英語で指定できます。最大長は 500 文字です。この制限を超えたテキストは自動的に切り捨てられます。例:低解像度、エラー、最低品質、低品質、変形、余分な指、悪いプロポーション。audio_url string (任意)サポートされているモデル:wan2.6 および wan2.5 シリーズモデル。音声ファイルの URL です。モデルはこの音声を使用して動画を生成します。サポートされている入力フォーマット:
  1. パブリック URL:
音声の制限:
  • フォーマット:wav、mp3。
  • 持続時間:3〜30 秒。
  • ファイルサイズ:最大 15 MB。
  • 指定された持続時間を超える音声の処理:音声が duration パラメーターで指定された値 (例:5 秒) よりも長い場合、音声は指定された持続時間に切り捨てられます。音声が動画の持続時間よりも短い場合、動画の残りの部分は無音になります。たとえば、音声が 3 秒で動画が 5 秒の場合、動画の最初の 3 秒には音声があり、最後の 2 秒は無音になります。
parameters object (任意)動画の解像度の設定、プロンプトリライトの有効化、ウォーターマークの追加など、動画処理パラメーターです。

プロパティ

size string (任意)
  • サイズは課金に直接影響します。呼び出しを行う前に、「モデルの料金」をご確認ください。
  • サイズは、1:1 のようなアスペクト比や 480P のような解像度ティアではなく、1280*720 のような特定の値に設定する必要があります。
生成される動画の解像度を 幅*高さ のフォーマットで指定します。このパラメーターのデフォルト値と有効な値は、以下のように model パラメーターに依存します:
  • wan2.6-t2v:デフォルト値は 1920*1080 (1080P) です。有効な解像度には、720P および 1080P ティアのすべての解像度が含まれます。
  • wan2.6-t2v-us:デフォルト値は 1920*1080 (1080P) です。有効な解像度には、720P および 1080P ティアのすべての解像度が含まれます。
  • wan2.5-t2v-preview:デフォルト値は 1920*1080 (1080P) です。有効な解像度には、480P、720P、1080P ティアのすべての解像度が含まれます。
  • wan2.2-t2v-plus:デフォルト値は 1920*1080 (1080P) です。有効な解像度には、480P および 1080P ティアのすべての解像度が含まれます。
  • wan2.1-t2v-turbo:デフォルト値は 1280*720 (720P) です。有効な解像度には、480P および 720P ティアのすべての解像度が含まれます。
  • wan2.1-t2v-plus:デフォルト値は 1280*720 (720P) です。有効な解像度には、720P ティアのすべての解像度が含まれます。
480P ティア:有効な動画解像度とそれに対応するアスペクト比は次のとおりです:
  • 832*480:16:9。
  • 480*832:9:16。
  • 624*624:1:1。
720P ティア:有効な動画解像度とそれに対応するアスペクト比は次のとおりです:
  • 1280*720:16:9。
  • 720*1280:9:16。
  • 960*960:1:1。
  • 1088*832:4:3。
  • 832*1088:3:4。
1080P ティア:有効な動画解像度とそれに対応するアスペクト比は次のとおりです:
  • 1920*1080:16:9。
  • 1080*1920:9:16。
  • 1440*1440:1:1。
  • 1632*1248:4:3。
  • 1248*1632:3:4。
duration integer (任意)
持続時間は課金に直接影響します。コスト = 単価 (解像度に基づく) × 持続時間 (秒単位)。呼び出しを行う前に、「モデルの料金」をご確認ください。
生成される動画の持続時間 (秒単位)。このパラメーターの有効な値は、model パラメーターに依存します:
  • wan2.6-t2v:2〜15 の整数。デフォルト値は 5 です。
  • wan2.6-t2v-us:有効な値は 5 と 10 です。デフォルト値は 5 です。
  • wan2.5-t2v-preview:有効な値は 5 と 10 です。デフォルト値は 5 です。
  • wan2.2-t2v-plus:5 秒に固定されており、変更できません。
  • wan2.1-t2v-plus:5 秒に固定されており、変更できません。
  • wan2.1-t2v-turbo:5 秒に固定されており、変更できません。
prompt_extendboolean (任意)プロンプトリライトを有効にするかどうかを指定します。有効にすると、モデルは入力プロンプトをインテリジェントに書き換えます。これにより、短いプロンプトで生成される動画の品質が大幅に向上しますが、実行時間は長くなります。
  • true (デフォルト)
  • false
shot_type string (任意)サポートされているモデル:wan2.6 モデル。生成される動画のショットタイプ、つまり動画が単一の連続したショットで構成されるか、複数の変化するショットで構成されるかを指定します。有効な値:
  • single:デフォルト値。シングルショット動画を出力します。
  • multi:マルチショット動画を出力します。
条件:このパラメーターは、"prompt_extend": true が設定されている場合にのみ有効です。パラメーターの優先度:shot_type > prompt。たとえば、shot_type が "single" に設定されている場合、プロンプトに "generate a multi-shot video" が含まれていても、モデルはシングルショット動画を出力します。watermark boolean (任意)ウォーターマークを追加するかどうかを指定します。ウォーターマークは動画の右下隅に配置され、固定テキスト「AI Generated」が表示されます。
  • false (デフォルト)
  • true
seed integer (任意)乱数シードは、[0, 2147483647] の範囲の整数である必要があります。指定しない場合、ランダムなシードが生成されます。固定シードは再現性を向上させます。モデルの生成は確率的であるため、同じシードでも同一の結果が保証されるわけではありません。
  • マルチショットナラティブ
  • 音声ファイルの提供
  • 自動吹き替え
  • 無音動画の生成
  • ネガティブプロンプトの使用
  • マルチショット動画の場合、shot_type は "multi" に設定する必要があります。
  • マルチショット動画の場合、ショット記述の最適化のためにプロンプトリライトを有効にするには、prompt_extend を true に設定する必要があります。

# シンガポールリージョンの URL。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
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.6-t2v",
    "input": {
        "prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: \"The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them \".",
        "audio_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3"
    },
    "parameters": {
        "size": "1280*720",
        "prompt_extend": true,
        "duration": 10,
        "shot_type":"multi"
    }
}'

レスポンスパラメーター

output objectタスクの出力情報を含みます。

プロパティ

task_id stringタスク ID です。24 時間クエリに有効です。task_status stringタスクのステータスです。

列挙値

  • PENDING
  • RUNNING
  • SUCCEEDED
  • FAILED
  • CANCELED
  • UNKNOWN:タスクが存在しないか、ステータスが不明です。
request_id stringトレースとトラブルシューティングのための一意のリクエスト識別子です。code stringエラーコードです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。message string詳細なエラーメッセージです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。
  • 成功レスポンス
  • エラーレスポンス
task_id を保存して、タスクのステータスと結果をクエリします。
{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}

ステップ 2:タスク ID で結果をクエリする

  • シンガポール
  • バージニア
  • フランクフルト
  • 北京
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}{WorkspaceId} を実際のワークスペース ID に置き換えてください。
  • ポーリングの推奨事項:動画の生成には数分かかります。15 秒などの適切な間隔でポーリングメカニズムを使用してください。
  • タスク状態の遷移:PENDING → RUNNING → SUCCEEDED または FAILED。
  • 結果リンク:タスクが成功すると、24 時間有効な動画 URL が返されます。動画をダウンロードして、OSS などの永続ストレージに保存してください。
  • task_idの有効期間:24 時間。この期間を過ぎると、クエリはタスクステータスを UNKNOWN として返します。

リクエストパラメーター

リクエストヘッダー
Authorization string (必須)Model Studio API キーでリクエストを認証します。例:Bearer sk-xxxx。
URL パスパラメーター
task_id string (必須)タスクの ID です。
  • タスク結果のクエリ
{task_id} を、前の API 呼び出しで返された task_id の値に置き換えてください。task_id は 24 時間クエリに有効です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。
curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"

レスポンスパラメーター

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

プロパティ

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+8 で、フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。scheduled_time stringタスクが実行された時刻です。時刻は UTC+8 で、フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。end_time stringタスクが完了した時刻です。時刻は UTC+8 で、フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。video_url string生成された動画の URL です。task_status が SUCCEEDED の場合にのみ返されます。24 時間有効です。動画は MP4 フォーマットで H.264 エンコーディングです。orig_prompt string元の入力プロンプトで、リクエストパラメーター prompt に対応します。actual_prompt stringprompt_extend=true の場合、システムは入力プロンプトを書き換えます。このフィールドは、生成に使用された最適化されたプロンプトを返します。
  • prompt_extend=false の場合、このフィールドは返されません。
  • 注意:wan2.6 モデルは、prompt_extend の値に関係なく、このフィールドを返しません。
code stringエラーコードです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。message string詳細なエラーメッセージです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。
usage object出力に関する統計情報を含みます。この情報は、成功したタスクに対してのみ提供されます。

プロパティ

video_duration integerwan2.5 およびそれ以前のモデルを使用している場合にのみ返されます。課金に使用されます。生成された動画の持続時間 (秒単位)。有効な値は 5 と 10 です。duration floatwan2.6 モデルを使用している場合にのみ返されます。課金に使用されます。合計動画持続時間を示します。ここで、duration = input_video_duration + output_video_duration です。input_video_duration integerwan2.6 モデルを使用している場合にのみ返されます。0 に固定されています。output_video_duration integerwan2.6 モデルを使用している場合にのみ返されます。出力動画の持続時間 (秒単位)。その値は input.duration の値と同じです。SR integerwan2.6 モデルを使用している場合にのみ返されます。生成された動画の解像度ティアです。例:720。size stringwan2.6 モデルを使用している場合にのみ返されます。生成された動画の解像度です。フォーマットは「幅高さ」です。例:19201080。video_ratio stringwan2.5 およびそれ以前のモデルを使用している場合にのみ返されます。生成された動画の解像度です。フォーマットは「幅高さ」です。例:832480。video_count integer生成された動画の数です。1 に固定されています。
request_id stringトレースとトラブルシューティングのための一意のリクエスト識別子です。
  • タスク成功
  • タスク失敗
  • タスククエリの期限切れ
動画 URL は 24 時間のみ有効で、その後自動的にパージされます。生成された動画は速やかに保存してください。
{
    "request_id": "abbf7aa3-9652-4785-a622-xxxxxx",
    "output": {
        "task_id": "38513c71-5190-48e1-9f3b-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-09-29 14:05:22.119",
        "scheduled_time": "2025-09-29 14:05:28.278",
        "end_time": "2025-09-29 14:10:00.437",
        "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx"
    },
    "usage": {
        "duration": 10,
        "size": "1280*720",
        "input_video_duration": 0,
        "output_video_duration": 10,
        "video_count": 1,
        "SR": 720
    }
}

DashScope SDK

SDK のパラメーター名は、ほとんどが HTTP API と一致しており、パラメーター構造はプログラミング言語の機能に合わせてカプセル化されています。 テキスト動画生成タスクは完了までに時間がかかるため (通常 1〜5 分)、SDK は HTTP 非同期呼び出しプロセスをカプセル化し、同期と非同期の両方の呼び出しメソッドをサポートしています。
実際の処理時間は、キュー内のタスク数とサービスステータスによって異なります。結果をお待ちください。

Python

以下のコードを実行する前に、DashScope Python SDK のバージョンが少なくとも2.0.1 であることを確認してください。古いバージョンを使用すると、「url error, please check url!」などのエラーが発生する可能性があります。SDK を更新するには、「SDK のインストール」をご参照ください。
モデルのリージョンに応じて region を設定します(Client 構築時に渡します。リージョンによって region の値は異なります):
  • シンガポール
  • バージニア
  • 北京
  • フランクフルト
region="ap-southeast-1"{WorkspaceId} を実際のワークスペース ID に置き換えてください。
  • 同期呼び出し
  • 非同期呼び出し
リクエストの例
import dashscope
import os
from dashscope.v2 import DashScopeError

# 以下はシンガポールリージョンの設定です。リージョンによって region の値は異なります。呼び出し時は、{WorkspaceId} をお使いのワークスペース ID に置き換えてください。
client = dashscope.Client(
    # 環境変数が設定されていない場合は、api_key = "sk-xxx" に置き換えてください
    # API キーはリージョンによって異なります。詳細については、https://www.alibabacloud.com/help/model-studio/get-api-key をご参照ください。
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    workspace="{WorkspaceId}",
    region="ap-southeast-1",
)

def sample_sync_call_t2v():
    # generate はワンステップ呼び出し(タスクを送信して完了を待機)で、完了済みの Job を返します。
    print('please wait...')
    # audio_url / negative_prompt は input セクションのフィールドで、名前付きシグネチャに含まれないため、extra_input 経由で渡します。
    try:
        job = client.videos.generate(model='wan2.6-t2v',
                                     prompt="Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them.'",
                                     extra_input={'audio_url': 'https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
                                                  'negative_prompt': ""},
                                     size='1280*720',
                                     duration=10,
                                     prompt_extend=True,
                                     watermark=False,
                                     seed=12345)
        print(job)
        print(job.video_url)
    except DashScopeError as e:
        print(f"HTTP status code: {e.status_code}")
        print(f"Error code: {e.code}")
        print(f"Error message: {e.message}")
        print("See the documentation: https://www.alibabacloud.com/help/ja/model-studio/developer-reference/error-code")

if __name__ == '__main__':
    sample_sync_call_t2v()
レスポンスの例
video_url は 24 時間有効です。速やかにダウンロードしてください。
{
    "status_code": 200,
    "request_id": "167f3beb-3dd0-47fe-a83c-xxxxxx",
    "code": null,
    "message": "",
    "output": {
        "task_id": "5b65411f-d946-4e29-859e-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-bj.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "submit_time": "2025-10-23 11:47:23.879",
        "scheduled_time": "2025-10-23 11:47:34.351",
        "end_time": "2025-10-23 11:52:35.323",
        "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective's office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '."
    },
    "usage": {
        "video_count": 1,
        "duration": 10,
        "size": "1280*720",
        "input_video_duration": 0,
        "output_video_duration": 10,
        "SR": 720
    }
}

Java

以下のコードを実行する前に、DashScope Java ソフトウェア開発キット (SDK) のバージョンが少なくとも2.22.14 であることを確認してください。古いバージョンを使用すると、「url error, please check url!」などのエラーが発生する可能性があります。SDK を更新するには、「SDK のインストール」をご参照ください。
モデルが配置されているリージョンに基づいて Constants.baseHttpApiUrl を設定します:
  • シンガポール
  • バージニア
  • 北京
  • フランクフルト
Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";{WorkspaceId} を実際のワークスペース ID に置き換えてください。
  • 同期呼び出し
  • 非同期呼び出し
リクエストの例
// Copyright (c) Alibaba, Inc. and its affiliates.

// dashscope SDK バージョン 2.18.2 以降
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.HashMap;
import java.util.Map;

public class Text2Video {

    static {
        // シンガポールリージョンの URL。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。詳細については、https://www.alibabacloud.com/help/model-studio/text-to-video-api-reference をご参照ください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // 環境変数が設定されていない場合は、値を Model Studio API キーに置き換えてください:apiKey = "sk-xxx"。
    // API キーはリージョンによって異なります。詳細については、https://www.alibabacloud.com/help/model-studio/get-api-key をご参照ください。
    public static String apiKey = System.getenv("DASHSCOPE_API_KEY");

    public static void text2Video() throws ApiException, NoApiKeyException, InputRequiredException {
        VideoSynthesis vs = new VideoSynthesis();
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("prompt_extend", true);
        parameters.put("watermark", false);
        parameters.put("seed", 12345);

        VideoSynthesisParam param =
                VideoSynthesisParam.builder()
                        .apiKey(apiKey)
                        .model("wan2.6-t2v")
                        .prompt("Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them'.")
                        .audioUrl("https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3")
                        .negativePrompt("")
                        .size("1280*720")
                        .duration(10)
                        .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 {
            text2Video();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.println(e.getMessage());
        }
        System.exit(0);
    }
}
レスポンスの例
video_url は 24 時間有効です。速やかにダウンロードしてください。
{
    "request_id": "c1209113-8437-424f-a386-xxxxxx",
    "output": {
        "task_id": "966cebcd-dedc-4962-af88-xxxxxx",
        "task_status": "SUCCEEDED",
        "video_url": "https://dashscope-result-sh.oss-accelerate.aliyuncs.com/xxx.mp4?Expires=xxx",
        "orig_prompt": "Shot from a low angle, in a medium close-up, with warm tones, mixed lighting (the practical light from the desk lamp blends with the overcast light from the window), side lighting, and a central composition. In a classic detective office, wooden bookshelves are filled with old case files and ashtrays. A green desk lamp illuminates a case file spread out in the center of the desk. A fox, wearing a dark brown trench coat and a light gray fedora, sits in a leather chair, its fur crimson, its tail resting lightly on the edge, its fingers slowly turning yellowed pages. Outside, a steady drizzle falls beneath a blue sky, streaking the glass with meandering streaks. It slowly raises its head, its ears twitching slightly, its amber eyes gazing directly at the camera, its mouth clearly moving as it speaks in a smooth, cynical voice: 'The case was cold, colder than a fish in winter. But every chicken has its secrets, and I, for one, intended to find them '",
        "submit_time": "2026-01-22 23:13:40.553",
        "scheduled_time": "2026-01-22 23:13:49.415",
        "end_time": "2026-01-22 23:17:56.380"
    },
    "usage": {
        "video_count": 1,
        "duration": 10.0,
        "size": "1280*720",
        "input_video_duration": 0,
        "output_video_duration": 10,
        "SR": 720
    },
    "status_code": 200,
    "code": "",
    "message": ""
}

エラーコード

モデルの呼び出しが失敗し、エラーメッセージが返された場合は、「エラーコード」で解決策をご参照ください。

よくある質問

Q:一時的な動画リンクを永続的なリンクに変換するにはどうすればよいですか?

A:リンクを直接変換することはできません。正しい手順は、バックエンドサービスで URL を取得し、動画ファイルをダウンロードしてから、Alibaba Cloud Object Storage Service (OSS) などの永続的なオブジェクトストレージサービスにアップロードして、新しい永続的なアクセスリンクを生成することです。
import requests

def download_and_save_video(video_url, save_path):
    try:
        response = requests.get(video_url, stream=True, timeout=300) # タイムアウトを設定
        response.raise_for_status() # HTTP ステータスコードが 200 でない場合に例外を発生させる
        with open(save_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        print(f"Video successfully downloaded to: {save_path}")
        # ここに永続ストレージへのアップロードロジックを追加
    except requests.exceptions.RequestException as e:
        print(f"Failed to download the video: {e}")

if __name__ == '__main__':
    video_url = "http://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxxx"
    save_path = "video.mp4"
    download_and_save_video(video_url, save_path)

Q:返された動画リンクはブラウザで直接再生できますか?

A:いいえ。リンクは 24 時間後に期限切れになるため、ブラウザで直接再生しないでください。代わりに、動画をダウンロードして保存し、再生には永続的なリンクを使用してください。