テキストからの画像生成 API を使用すると、テキスト記述から新しい画像を生成できます。Alibaba Cloud Model Studio は、主に 2 つのモデルシリーズを提供しています。
Qwen-Image:複雑な中国語と英語のテキストのレンダリングに優れています。
Wan シリーズ:リアルな画像と写真品質の視覚効果を生成します。
モデルのパフォーマンス
Qwen-Image
複雑なテキスト
| 長文
| 複雑なレイアウト
|
ポスター作成
| イラストデザイン
| リアルな写真
|
Wan
ポートレート写真
| リアルな写真
| 絵画スタイル
|
テキスト生成
| ポスターデザイン
| 画像セット生成
|
サポートされているモデル
モデルの選択
複雑なテキストレンダリング (ポスターや対聯など):
qwen-image-maxまたはwan2.6-t2iを使用します。リアルなシーンと写真スタイル (一般的なシナリオ):
wan2.6-t2iやwan2.5-t2i-previewなどの Wan モデルを使用します。カスタム出力画像の解像度:
wan2.2-t2i-flashなどの Wan モデルを使用します。512 から 1440 ピクセルの範囲内で、任意の幅と高さの組み合わせをサポートします。Qwen-Image は、1664*928 (16:9)、928*1664 (9:16)、1328*1328 (1:1)、1472*1104 (4:3)、1104*1472 (3:4) の 5 つの固定解像度のみをサポートします。
はじめに
前提条件
開始する前に、API キーを作成し、環境変数としてエクスポートしてください。DashScope SDK を使用する場合は、SDK をインストールしてください。
サンプルコード
呼び出しメソッド:Qwen-Image は同期呼び出しをサポートしています。qwen-image-plus および qwen-image モデルは非同期呼び出しもサポートしています。Wan は非同期呼び出しのみをサポートしています。
非同期呼び出し:両モデルの API は互換性があります。
modelパラメーターを変更するだけで切り替えることができます。たとえば、Wan モデルを使用するには、model を "wan2.2-t2i-flash" に設定します。同期呼び出し:Qwen-Image のみがこのメソッドをサポートしています。同期呼び出しを行う方法については、「Qwen-Image API リファレンス」をご参照ください。
以下の例では、非同期呼び出しメソッドを使用しています。サンプルコードでは qwen-image-plus を例としていますが、同じアプローチが Wan モデルにも適用されます。
SDK は非同期処理ロジックをカプセル化しているため、インターフェイスレベルでは同期呼び出しのように見えます。つまり、1 つのリクエストが最終結果を待機します。対照的に、curl の例では、タスクを送信するための API 呼び出しと、結果をクエリするための API 呼び出しの 2 つの別々の非同期 API 呼び出しを使用します。
Python
リクエスト例
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
import dashscope
# 次の URL はシンガポールリージョン用です。中国 (北京) リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
prompt = "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere."
# シンガポールリージョンと中国 (北京) リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/ja/model-studio/get-api-key をご参照ください
# 環境変数を設定していない場合は、次の行をご利用の Model Studio API キーに置き換えてください:api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")
print('----同期呼び出しです。しばらくお待ちください----')
rsp = ImageSynthesis.call(api_key=api_key,
model="qwen-image-plus", # 現在、非同期 API 呼び出しをサポートしているのは qwen-image-plus と qwen-image モデルのみです。
prompt=prompt,
negative_prompt=" ",
n=1,
size='1664*928',
prompt_extend=True,
watermark=False)
print(f'response: {rsp}')
if rsp.status_code == HTTPStatus.OK:
# 画像を現在のディレクトリに保存します。
for result in rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open('./%s' % file_name, 'wb+') as f:
f.write(requests.get(result.url).content)
else:
print(f'sync_call Failed, status_code: {rsp.status_code}, code: {rsp.code}, message: {rsp.message}')
レスポンス例
URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{
"status_code": 200,
"request_id": "a47b1a65-7041-4565-9068-xxxxxx",
"code": null,
"message": "",
"output": {
"task_id": "91093132-475e-43cf-b94e-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"url": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxxxxx",
"orig_prompt": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere.",
"actual_prompt": "Childhood-inspired hand-drawn poster design: Three playful puppies joyfully interact with a colorful ball on a vibrant patch of lush green grass. Delicate decorative elements including fluttering birds and twinkling stars are scattered throughout. At the top center, the bold, blue cartoon-style title “Come Play Ball!” stands out prominently. Directly beneath, the subtitle “Come [Show Off Your Skills]!” is rendered in cheerful green lettering. A whimsical speech bubble near one of the puppies contains the playful text: “Hehe, watch me amaze my little friends next!” At the bottom edge, smaller supplementary text reads: “We get to play ball with our friends again!” The color palette is centered on fresh greens and sky blues, accented with pops of bright pink and sunny yellow, enhancing the cheerful, childlike atmosphere. Style evokes nostalgic, hand-inked illustrations with soft textures, gentle linework, and a whimsical, storybook-like composition."
}
],
"submit_time": "2025-09-09 13:39:20.659",
"scheduled_time": "2025-09-09 13:39:20.717",
"end_time": "2025-09-09 13:39:45.233"
},
"usage": {
"image_count": 1
}
}Java
リクエスト例
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisListResult;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisParam;
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesisResult;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.task.AsyncTaskListParam;
import com.alibaba.dashscope.utils.Constants;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.HashMap;
import java.util.Map;
public class Text2Image {
static {
// 次の URL はシンガポールリージョン用です。中国 (北京) リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// シンガポールリージョンと中国 (北京) リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/ja/model-studio/get-api-key をご参照ください
// 環境変数を設定していない場合は、次の行をご利用の Model Studio API キーに置き換えてください:static String apiKey = "sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void basicCall() throws ApiException, NoApiKeyException {
String prompt = "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere.";
Map<String, Object> parameters = new HashMap<>();
parameters.put("prompt_extend", true);
parameters.put("watermark", false);
parameters.put("negative_prompt", " ");
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(apiKey)
// 現在、非同期 API 呼び出しをサポートしているのは qwen-image-plus と qwen-image モデルのみです。
.model("qwen-image-plus")
.prompt(prompt)
.n(1)
.size("1664*928")
.parameters(parameters)
.build();
ImageSynthesis imageSynthesis = new ImageSynthesis();
ImageSynthesisResult result = null;
try {
System.out.println("---同期呼び出しです。しばらくお待ちください----");
result = imageSynthesis.call(param);
} catch (ApiException | NoApiKeyException e){
throw new RuntimeException(e.getMessage());
}
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args){
try{
basicCall();
}catch(ApiException|NoApiKeyException e){
System.out.println(e.getMessage());
}
}
}
レスポンス例
URL は 24 時間有効です。速やかに画像をダウンロードしてください。
{
"request_id": "9f3044ba-528f-4606-8830-xxxxxx",
"output": {
"task_id": "fecf4c7f-3508-45f4-8454-xxxxxx",
"task_status": "SUCCEEDED",
"results": [
{
"orig_prompt": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere.",
"actual_prompt": "Childhood-inspired hand-drawn poster design: Three playful puppies joyfully interact with a colorful ball on a vibrant patch of lush green grass. Delicate decorative elements including fluttering birds and twinkling stars are scattered throughout. At the top center, the bold, blue cartoon-style title “Come Play Ball!” stands out prominently. Directly beneath, the subtitle “Come [Show Off Your Skills]!” is rendered in cheerful green lettering. A whimsical speech bubble near one of the puppies contains the playful text: “Hehe, watch me amaze my little friends next!” At the bottom edge, smaller supplementary text reads: “We get to play ball with our friends again!” The color palette is centered on fresh greens and sky blues, accented with pops of bright pink and sunny yellow, enhancing the cheerful, childlike atmosphere. Style evokes nostalgic, hand-inked illustrations with soft textures, gentle linework, and a whimsical, storybook-like composition.",
"url": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxxx"
}
]
},
"usage": {
"image_count": 1
}
}curl
非同期呼び出しの場合、ヘッダーパラメーター
X-DashScope-Asyncをenableに設定します。非同期タスクの
task_idは 24 時間有効です。有効期限が切れると、タスクのステータスはUNKNOWNに変わります。
ステップ 1:タスク作成リクエストの送信
このリクエストはタスク ID (task_id) を返します。
curl -X POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis \
-H 'X-DashScope-Async: enable' \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"model": "qwen-image-plus",
"input": {
"prompt": "Healing-style hand-drawn poster featuring three puppies playing with a ball on lush green grass, adorned with decorative elements such as birds and stars. The main title “Come Play Ball!” is prominently displayed at the top in bold, blue cartoon font. Below it, the subtitle “Come [Show Off Your Skills]!” appears in green font. A speech bubble adds playful charm with the text: “Hehe, watch me amaze my little friends next!” At the bottom, supplementary text reads: “We get to play ball with our friends again!” The color palette centers on fresh greens and blues, accented with bright pink and yellow tones to highlight a cheerful, childlike atmosphere."
},
"parameters": {
"negative_prompt":" ",
"size": "1664*928",
"n": 1,
"prompt_extend": true,
"watermark": false
}
}' ステップ 2:タスク ID による結果のクエリ
前のステップで取得した task_id を使用して、task_status が SUCCEEDED または FAILED になるまで API を通じてタスクのステータスをポーリングします。
86ecf553-d340-4e21-xxxxxxxxx を実際のタスク ID に置き換えてください。
API キーはリージョン固有です。API キーを取得してください。
北京リージョンのモデルの場合、base_url を https://dashscope.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx に置き換えてください
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"主な機能
1. 指示追従 (プロンプト)
パラメーター: input.prompt (必須)、input.negative_prompt (任意)。
prompt (ポジティブプロンプト):画像に表示したいコンテンツ、主題、シーン、スタイル、照明、構図を記述します。これは、テキストからの画像生成を制御するためのコアパラメーターです。
negative_prompt:画像に表示したくないコンテンツ (「ぼやけている」や「余分な指」など) を記述します。これは、生成品質の最適化を補助するためにのみ使用されます。
記述のヒント:構造化されたプロンプトは、通常、より良い結果を生み出します。記述のヒントについては、「テキストからの画像生成プロンプトガイド」をご参照ください。
2. プロンプトの再書き込みを有効化
パラメーター: parameters.prompt_extend (bool, デフォルトは true)。
この機能は、短いプロンプトを自動的に拡張および最適化して、画質を向上させます。この機能を有効にすると、大規模モデルを使用してプロンプトを再書き込みするため、3〜5 秒のレイテンシーが追加されます。
ベストプラクティス:
入力プロンプトが単純または広範な場合に有効にします。この機能は画質を大幅に向上させることができます。
細かいディテールを制御したい場合、すでに詳細な記述を提供している場合、または応答レイテンシーに敏感な場合は無効にします。無効にするには、
prompt_extendパラメーターを明示的にfalseに設定します。
3. 出力画像の解像度を設定
パラメーター: parameters.size (string)、フォーマットは "width*height"。
Qwen-Image:以下の 5 つの固定解像度のみをサポートします。
1664*928 (デフォルト):16:9。
1472*1104:4:3。
1328*1328:1:1。
1104*1472:3:4。
928*1664:9:16。
Wan V2 モデル (v2.0 以降):幅と高さが 512 から 1440 ピクセルの範囲で、総ピクセル数が 1440*1440 を超えない解像度をサポートします。一般的な解像度:
1024*1024 (デフォルト):1:1。
1440*810:16:9。
810*1440:9:16。
1440*1080:4:3。
1080*1440:3:4。
本番運用
フォールトトレランス戦略
レート制限への対応:API が
Throttlingエラーコードまたは HTTP 429 状態コードを返した場合、レート制限がトリガーされています。「レート制限」をご参照ください。非同期タスクのポーリング:非同期タスクの結果をポーリングする際は、最初の 30 秒間は 3 秒ごとにポーリングし、その後間隔を広げるなど、合理的なポーリング戦略を使用します。これにより、頻繁なリクエストによるレート制限のトリガーを回避できます。タスクに最終的なタイムアウト (例:2 分) を設定し、タイムアウトした場合はタスクが失敗したと見なします。
リスク防止
結果の永続化:API から返される画像 URL は 24 時間有効です。本番システムでは、URL を取得した直後に画像をダウンロードし、Alibaba Cloud Object Storage Service (OSS) などの独自の永続ストレージサービスに転送する必要があります。
コンテンツモデレーション:すべての
promptおよびnegative_prompt入力はコンテンツモデレーションを受けます。入力が非準拠の場合、リクエストはブロックされ、DataInspectionFailedエラーが返されます。生成されたコンテンツの著作権およびコンプライアンスリスク:プロンプトの内容が関連する法律および規制に準拠していることを確認してください。ブランドの商標、有名人の肖像、著作権のある IP 画像を含むコンテンツを生成すると、侵害リスクが生じる可能性があります。結果として生じるいかなる責任も、お客様が評価し、負担するものとします。
API リファレンス
課金とレート制限
モデルの無料クォータと単価については、「画像生成」をご参照ください。
課金ルール
課金項目:正常に生成された画像の数に対して、従量課金で課金されます。
課金計算式:料金 = 単価 × 画像数。
消費順序:無料クォータが最初に消費されます。無料クォータを使い切った後は、デフォルトで従量課金方式が使用されます。
「無料クォータのみ」オプションを有効にすると、無料クォータがなくなった後の課金を防ぐことができます。詳細については、「新規ユーザー向けの無料クォータ」をご参照ください。
失敗時の課金なし:モデル呼び出しの失敗や処理エラーは、料金が発生したり、無料クォータを消費したりすることはありません。
無料クォータ
無料クォータの請求、クエリ、使用方法の詳細については、「新規ユーザー向けの無料クォータ」をご参照ください。
使用状況のクエリ
モデル呼び出しが完了してから約 1 時間後に、モデル監視 (シンガポール) ページに移動して、使用状況、呼び出し回数、成功率などのメトリックを表示できます。
中国 (北京) リージョンのモデルを使用する場合は、中国 (北京) リージョンのモデル監視ページに移動してください。
レート制限
レート制限のルールとよくある質問については、「レート制限」をご参照ください。
エラーコード
呼び出しが失敗した場合は、「エラーメッセージ」でトラブルシューティングを行ってください。
よくある質問
Q:画像 URL の有効期間はどのくらいですか?画像を永続的に保存するにはどうすればよいですか?
A:画像 URL は 24 時間有効です。URL を取得した直後に画像をダウンロードし、ローカルサーバーや Object Storage Service (OSS) などの独自の永続ストレージに保存する必要があります。
Q:API 呼び出しで DataInspectionFailed エラーが返されます。どうすればよいですか?
A:このエラーは、入力テキストがコンテンツモデレーションをトリガーしたことを示します。prompt または negative_prompt のテキストを確認および修正して、潜在的に非準拠のコンテンツを削除してから、リクエストを再試行してください。
Q:prompt_extend パラメーターを有効にするべきですか、それとも無効にするべきですか?
A:プロンプトが単純な場合や、モデルに創造性を発揮させたい場合は、有効 (デフォルト) のままにしてください。プロンプトがすでに非常に詳細で専門的である場合や、API 応答レイテンシーに厳しい要件がある場合は、明示的に false に設定してください。
Q:画像に生成されるテキストの品質を向上させるにはどうすればよいですか?
A:ビジネスが画像内の明確で正確なテキストの生成に大きく依存している場合は、qwen-image-plus モデルを使用してください。このモデルは、そのようなシナリオ向けに特別にトレーニングされています。











