Wan テキスト動画生成モデルは、 テキストプロンプト からスムーズな動画を生成します。
リファレンス: ユーザーガイド
利用可能リージョン
呼び出しを成功させるには、モデル、エンドポイント URL、API キーがすべて同じリージョンに属している必要があります。リージョン間の呼び出しは失敗します。
- モデルの選択:モデルのリージョンを確認します。
- URL の選択:対応するリージョンのエンドポイント URL を選択します。HTTP URL と DashScope SDK URL がサポートされています。
- API キーの設定:リージョンを選択し、API キーを取得してから、API キーを環境変数として設定します (非推奨となり、API キー設定に統合される予定です)。
- SDK のインストール:SDK を使用して呼び出しを行うには、DashScope SDK をインストールする必要があります。
注記このトピックのサンプルコードは、シンガポールリージョンに適用されます。
重要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 に置き換えてください。
米国 (バージニア)
POST https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
フランクフルト
POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
北京
POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
注記
- タスクが作成された後、返された
task_idを使用して結果をクエリします。task_idは 24 時間有効です。重複したタスクを作成しないでください。代わりに、ポーリングを使用して結果を取得してください。 - 初心者向けのガイダンスについては、「Postman または cURL を使用した API の呼び出し」をご参照ください。
リクエストパラメーターリクエストヘッダーContent-Type リクエストのコンテンツタイプです。 Authorization Model Studio API キーでリクエストを認証します。例:Bearer sk-xxxx。 X-DashScope-Async 非同期処理を有効にします。HTTP リクエストは非同期呼び出しのみをサポートします。 重要このリクエストヘッダーがない場合、「current user api does not support synchronous calls」というエラーが返されます。 リクエストボディmodel 使用するモデルの名前です。利用可能なモデルのリストについては、「モデルリスト」をご参照ください。 例:wan2.6-t2v。 input プロンプトなどの基本的な入力情報を含みます。 parameters 動画の解像度の設定、プロンプトリライトの有効化、ウォーターマークの追加など、動画処理パラメーターです。 | マルチショットナラティブ
音声ファイルの提供サポートされているモデル:wan2.6/wan2.5 シリーズモデル。
自動吹き替えサポートされているモデル:wan2.6/wan2.5 シリーズモデル。
無音動画の生成wan2.2 および wan2.1 シリーズモデルのみが無音動画生成をサポートしています。これらのモデルはデフォルトで無音動画を生成し、追加の設定は不要です。
ネガティブプロンプトの使用サポートされているモデル:すべてのモデル。 negative_prompt パラメーターを使用して「花」の要素を除外し、動画に表示されないようにします。 |
レスポンスパラメーターoutput タスクの出力情報を含みます。 request_id トレースとトラブルシューティングのための一意のリクエスト識別子です。 code エラーコードです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。 message 詳細なエラーメッセージです。失敗したリクエストに対してのみ返されます。「エラーコード」をご参照ください。 | 成功レスポンス
エラーレスポンスタスクの作成に失敗しました。「エラーコード」をご参照ください。 |
ステップ 2:タスク ID で結果をクエリする
シンガポール
GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
バージニア
GET https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
フランクフルト
GET https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1/tasks/{task_id}
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
北京
GET https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/tasks/{task_id}
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
注記
- ポーリングの推奨事項:動画の生成には数分かかります。15 秒などの適切な間隔でポーリングメカニズムを使用してください。
- タスク状態の遷移:PENDING → RUNNING → SUCCEEDED または FAILED。
- 結果リンク:タスクが成功すると、24 時間有効な動画 URL が返されます。動画をダウンロードして、OSS などの永続ストレージに保存してください。
task_idの有効期間:24 時間。この期間を過ぎると、クエリはタスクステータスをUNKNOWNとして返します。
リクエストパラメーターリクエストヘッダーAuthorization Model Studio API キーでリクエストを認証します。例:Bearer sk-xxxx。 URL パスパラメーターtask_id タスクの ID です。 | タスク結果のクエリ
|
レスポンスパラメーターoutput タスクの出力情報を含みます。 usage 出力に関する統計情報を含みます。この情報は、成功したタスクに対してのみ提供されます。 request_id トレースとトラブルシューティングのための一意のリクエスト識別子です。 | タスク成功動画 URL は 24 時間のみ有効で、その後自動的にパージされます。生成された動画は速やかに保存してください。 タスク失敗タスクが失敗すると、 タスククエリの期限切れ
|
DashScope SDK
SDK のパラメーター名は、ほとんどが HTTP API と一致しており、パラメーター構造はプログラミング言語の機能に合わせてカプセル化されています。
テキスト動画生成タスクは完了までに時間がかかるため (通常 1〜5 分)、SDK は HTTP 非同期呼び出しプロセスをカプセル化し、同期と非同期の両方の呼び出しメソッドをサポートしています。
実際の処理時間は、キュー内のタスク数とサービスステータスによって異なります。結果をお待ちください。
Python
重要以下のコードを実行する前に、DashScope Python SDK のバージョンが少なくとも1.25.16 であることを確認してください。
古いバージョンを使用すると、「url error, please check url!」などのエラーが発生する可能性があります。SDK を更新するには、「SDK のインストール」をご参照ください。
モデルが配置されているリージョンに基づいて dashscope.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://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1'
北京
dashscope.base_http_api_url = 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1'
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
フランクフルト
dashscope.base_http_api_url = 'https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/api/v1'
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
同期呼び出し
リクエストの例
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# シンガポールリージョンの URL。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。詳細については、https://www.alibabacloud.com/help/model-studio/text-to-video-api-reference をご参照ください。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 環境変数が設定されていない場合は、ご利用の Model Studio API キーに置き換えてください:api_key="sk-xxx"。
# API キーはリージョンによって異なります。詳細については、https://www.alibabacloud.com/help/model-studio/get-api-key をご参照ください。
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_sync_call_t2v():
# 同期 API を呼び出し、結果を返します。
print('Please wait...')
rsp = VideoSynthesis.call(api_key=api_key,
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.'",
audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
size='1280*720',
duration=10,
negative_prompt="",
prompt_extend=True,
watermark=False,
seed=12345)
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_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
}
}
非同期呼び出し
リクエストの例
from http import HTTPStatus
from dashscope import VideoSynthesis
import dashscope
import os
# これはシンガポールリージョンの URL です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。詳細については、https://www.alibabacloud.com/help/model-studio/text-to-video-api-reference をご参照ください。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1'
# 環境変数が設定されていない場合は、ご利用の Model Studio API キーに置き換えてください:api_key="sk-xxx"
# API キーはリージョンによって異なります。詳細については、https://www.alibabacloud.com/help/model-studio/get-api-key をご参照ください。
api_key = os.getenv("DASHSCOPE_API_KEY")
def sample_async_call_t2v():
# 非同期 API を呼び出し、タスク情報を返します。
# タスク ID を使用してステータスを確認します。
rsp = VideoSynthesis.async_call(api_key=api_key,
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 '.",
audio_url='https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250929/stjqnq/%E7%8B%90%E7%8B%B8.mp3',
size='1280*720',
duration=10,
negative_prompt="",
prompt_extend=True,
watermark=False,
seed=12345)
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))
# タスクが完了するのを待ちます。このメソッドは、一定間隔で fetch を呼び出し、タスクが完了状態にあるか確認します。
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_t2v()
レスポンスの例
- タスク作成リクエストへのレスポンスの例
{
"status_code": 200,
"request_id": "c86ff7ba-8377-917a-90ed-xxxxxx",
"code": "",
"message": "",
"output": {
"task_id": "721164c6-8619-4a35-a6d9-xxxxxx",
"task_status": "PENDING",
"video_url": ""
},
"usage": null
}
- タスククエリリクエストへのレスポンスの例
動画 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 に置き換えてください。
バージニア
Constants.baseHttpApiUrl = "https://{WorkspaceId}.us-east-1.maas.aliyuncs.com/api/v1";
北京
Constants.baseHttpApiUrl = "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1";
{WorkspaceId} を実際のワークスペース ID に置き換えてください。
フランクフルト
Constants.baseHttpApiUrl = "https://{WorkspaceId}.eu-central-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": ""
}
非同期呼び出し
リクエストの例
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesis;
import com.alibaba.dashscope.aigc.videosynthesis.VideoSynthesisListResult;
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.task.AsyncTaskListParam;
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();
// 非同期呼び出しを行います。
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 {
text2Video();
} catch (ApiException | NoApiKeyException | InputRequiredException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
}
レスポンスの例
- タスク作成リクエストへのレスポンスの例。
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-xxxxxxxx",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}
- タスククエリリクエストへのレスポンスの例
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 時間後に期限切れになるため、ブラウザで直接再生しないでください。代わりに、動画をダウンロードして保存し、再生には永続的なリンクを使用してください。