Qwen-Image は、汎用の画像生成モデルです。複数の芸術的なスタイルをサポートし、複雑なテキストレンダリングに優れています。このモデルは、複数行、段落レベルのテキスト生成、および詳細なディテールレンダリングをサポートしています。これにより、テキストと画像を組み合わせた複雑なデザインが可能になります。
クイックリンク: ユーザーガイド | オンラインで試す | 技術ブログ (その他の例) |
ショーケース
入力プロンプト | 出力画像 |
緑豊かな芝生の上でボールで遊ぶ 3 匹の子犬をフィーチャーした、癒し系の手描きポスター。鳥や星などの装飾要素で飾られています。メインタイトル「Come Play Ball!」は、太字の青いカートゥーンフォントで上部に目立つように表示されています。その下には、サブタイトル「Come [Show Off Your Skills]!」が緑色のフォントで表示されています。吹き出しは、「Hehe, watch me amaze my little friends next!」というテキストで遊び心のある魅力を加えています。下部には、「We get to play ball with our friends again!」という補足テキストがあります。カラーパレットは、新鮮な緑と青を中心に、明るいピンクと黄色のトーンでアクセントをつけ、陽気で子供らしい雰囲気を強調しています。 |
|
前提条件
呼び出しを行う前に、お住まいのリージョンの API キーを作成してください。次に、API キーを環境変数としてエクスポートします。
北京リージョンとシンガポールリージョンには、それぞれ別のAPI キーとリクエストエンドポイントがあります。これらを交換して使用しないでください。リージョンをまたいだ呼び出しは、認証の失敗やサービスエラーの原因となります。
同期 API (推奨)
HTTP 呼び出し
Qwen-Image は同期 API をサポートしており、1 回のリクエストで結果を取得できます。呼び出しプロセスが単純なため、この API はほとんどのシナリオで推奨されます。
シンガポールリージョン: POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
中国 (北京) リージョン: POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation
リクエストパラメーター | Text-to-image |
リクエストヘッダー | |
Content-Type リクエストのコンテンツタイプ。このパラメーターを | |
Authorization リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例: Bearer sk-xxxx。 | |
リクエスト本文 | |
model モデル名。このパラメーターを | |
input 基本情報を入力します。 | |
parameters 画像処理パラメーター。 |
応答パラメーター | タスク成功タスクのステータスや画像 URL などのタスクデータは 24 時間のみ保持され、この期間が過ぎると自動的にパージされます。生成された画像は速やかに保存する必要があります。 タスク異常タスクが失敗した場合、応答には失敗に関する情報が含まれます。`code` および `message` フィールドはエラーの原因を示します。問題の解決方法の詳細については、「エラーメッセージ」をご参照ください。 |
output タスクの出力情報。 | |
usage 出力の使用状況統計。成功した結果のみがカウントされます。 | |
request_id 一意のリクエスト ID。この ID を使用して問題を追跡およびトラブルシューティングできます。 | |
code 失敗したリクエストのエラーコード。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。 | |
message 失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。 |
DashScope SDK
DashScope SDK は現在、Python と Java をサポートしています。
SDK のパラメーター名は、HTTP API のパラメーター名とほぼ一致しています。パラメーター構造は、言語の機能に基づいてカプセル化されています。同期呼び出しのパラメーターの説明については、「HTTP 呼び出し」をご参照ください。
Python
DashScope Python SDK の最新バージョンがインストールされていることを確認してください。そうでない場合、実行時エラーが発生する可能性があります。詳細については、「SDK のインストール」をご参照ください。
リクエストの例
import json
import os
import dashscope
from dashscope import MultiModalConversation
# 次の URL はシンガポールリージョン用です。中国 (北京) リージョンのモデルを使用する場合は、URL を https://dashscope.aliyuncs.com/api/v1 に置き換えてください
dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
messages = [
{
"role": "user",
"content": [
{"text": "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/en/model-studio/get-api-key をご参照ください
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")
response = MultiModalConversation.call(
api_key=api_key,
model="qwen-image-plus",
messages=messages,
result_format='message',
stream=False,
watermark=False,
prompt_extend=True,
negative_prompt='',
size='1328*1328'
)
if response.status_code == 200:
print(json.dumps(response, ensure_ascii=False))
else:
print(f"HTTP status code: {response.status_code}")
print(f"Error code: {response.code}")
print(f"Error message: {response.message}")
print("For more information, see the documentation: https://www.alibabacloud.com/help/en/model-studio/error-code")応答の例
画像 URL は 24 時間有効です。画像を速やかにダウンロードしてください。
{
"status_code": 200,
"request_id": "d2d1a8c0-325f-9b9d-8b90-xxxxxx",
"code": "",
"message": "",
"output": {
"text": null,
"finish_reason": null,
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/xxx.png?Expires=xxx"
}
]
}
}
],
"task_metric": {
"TOTAL": 1,
"FAILED": 0,
"SUCCEEDED": 1
}
},
"usage": {
"input_tokens": 0,
"output_tokens": 0,
"width": 1328,
"image_count": 1,
"height": 1328
}
}Java
DashScope Java SDK の最新バージョンがインストールされていることを確認してください。そうでない場合、実行時エラーが発生する可能性があります。詳細については、「SDK のインストール」をご参照ください。
リクエストの例
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.alibaba.dashscope.utils.Constants;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class QwenImage {
static {
// 次はシンガポールリージョンの base_url です。中国 (北京) リージョンのモデルを使用する場合は、base_url を https://dashscope.aliyuncs.com/api/v1 に置き換えてください
Constants.baseHttpApiUrl = "https://dashscope-intl.aliyuncs.com/api/v1";
}
// シンガポールリージョンと中国 (北京) リージョンの API キーは異なります。API キーを取得するには、https://www.alibabacloud.com/help/en/model-studio/get-api-key をご参照ください
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: static String apiKey="sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public static void call() throws ApiException, NoApiKeyException, UploadFileException, IOException {
MultiModalConversation conv = new MultiModalConversation();
MultiModalMessage userMessage = MultiModalMessage.builder().role(Role.USER.getValue())
.content(Arrays.asList(
Collections.singletonMap("text", "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.")
)).build();
Map<String, Object> parameters = new HashMap<>();
parameters.put("watermark", false);
parameters.put("prompt_extend", true);
parameters.put("negative_prompt", "");
parameters.put("size", "1328*1328");
MultiModalConversationParam param = MultiModalConversationParam.builder()
.apiKey(apiKey)
.model("qwen-image-plus")
.messages(Collections.singletonList(userMessage))
.parameters(parameters)
.build();
MultiModalConversationResult result = conv.call(param);
System.out.println(JsonUtils.toJson(result));
}
public static void main(String[] args) {
try {
call();
} catch (ApiException | NoApiKeyException | UploadFileException | IOException e) {
System.out.println(e.getMessage());
}
System.exit(0);
}
応答の例
画像 URL は 24 時間有効です。画像を速やかにダウンロードしてください。
{
"requestId": "5b6f2d04-b019-40db-a5cc-xxxxxx",
"usage": {
"image_count": 1,
"width": 1328,
"height": 1328
},
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/xxx.png?Expires=xxx"
}
]
}
}
]
}
}非同期 API (2 ステップのプロセス)
HTTP 呼び出し
Qwen-Image は非同期 API もサポートしています。HTTP 呼び出しのフローは 2 つのステップで構成されます:
タスクを作成してタスク ID を取得する: タスクを作成するリクエストを送信します。応答でタスク ID (task_id) が返されます。
タスク ID を使用して結果をクエリする: `task_id` を使用してタスクのステータスをポーリングし、タスクが完了してイメージ URL を取得するまで続けます。
ステップ 1: タスクを作成してタスク ID を取得する
シンガポールリージョン: POST https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis
中国 (北京) リージョン: POST https://dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis
タスクが作成された後、返された
task_idを使用して結果をクエリします。task_id は 24 時間有効です。重複したタスクを作成しないでください。ポーリングを使用して結果を取得してください。
リクエストパラメーター | テキストからイメージへ |
リクエストヘッダー | |
Content-Type リクエストのコンテンツタイプ。このパラメーターを | |
Authorization リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例: Bearer sk-xxxx。 | |
X-DashScope-Async 非同期処理の構成パラメーター。HTTP リクエストは非同期処理のみをサポートします。このパラメーターを 重要 このリクエストヘッダーがない場合、「current user api does not support synchronous calls」というエラーメッセージが返されます。 | |
リクエスト本文 | |
model モデル名。このパラメーターを | |
input プロンプトなどの基本的な入力情報。 | |
parameters イメージ処理パラメーター。 |
応答パラメーター | 成功した応答task_id を保存して、タスクのステータスと結果をクエリします。 エラー応答タスクの作成に失敗しました。詳細については、「エラーメッセージ」をご参照ください。問題を解決してください。 |
output タスクの出力情報。 | |
request_id 一意のリクエスト ID。この ID を使用して問題を追跡およびトラブルシューティングできます。 | |
code 失敗したリクエストのエラーコード。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。 | |
message 失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。 |
ステップ 2: タスク ID を使用して結果をクエリする
シンガポールリージョン: GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/{task_id}
北京リージョン: GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}
ポーリングの推奨: モデルの実行には約 15 秒かかります。3 秒などの合理的なクエリ間隔でポーリングメカニズムを使用して結果を取得することをお勧めします。実際の時間は、キュー内のタスク数とネットワーク条件によって異なります。結果をお待ちください。
タスクステータスのフロー: PENDING -> RUNNING -> SUCCEEDED / FAILED。
結果リンク: タスクが成功すると、イメージリンクが返されます。リンクは 24 時間有効です。イメージを速やかにダウンロードし、Alibaba Cloud OSS などのストレージスペースに転送する必要があります。
リクエストパラメーター | タスク結果のクエリ
シンガポールリージョンと北京リージョンの API キーは異なります。「API キーを取得する」をご参照ください。 以下のコードはシンガポールリージョンの base_url を提供します。北京リージョンのモデルを使用する場合は、base_url を https://dashscope.aliyuncs.com/api/v1/tasks/{task_id} に置き換えてください |
リクエストヘッダー | |
Authorization リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例: Bearer sk-xxxx。 | |
URL パスパラメーター | |
task_id タスク ID。 |
応答パラメーター | タスク成功タスクステータスやイメージ URL などのタスクデータは 24 時間のみ保持され、この期間が過ぎると自動的に消去されます。生成されたイメージは速やかに保存する必要があります。 タスク失敗タスクが失敗した場合、task_status は FAILED に設定され、エラーコードとメッセージが提供されます。詳細については、「エラーメッセージ」をご参照ください。問題を解決してください。 |
output タスクの出力情報。 | |
usage 出力の使用状況統計。成功した結果のみがカウントされます。 | |
request_id 一意のリクエスト ID。この ID を使用して問題を追跡およびトラブルシューティングできます。 |
DashScope SDK
DashScope SDK は現在、Python と Java をサポートしています。
SDK のパラメーター名は、ほとんどが HTTP API のパラメーター名と一致しています。パラメーターの構造は、各言語の SDK のカプセル化に依存します。非同期呼び出しのパラメーターの説明については、「HTTP 呼び出し」をご参照ください。
イメージモデルは処理時間が長いため、基盤となるサービスは非同期です。SDK はこれを基盤として、次の 2 つの呼び出しモードを提供します。
同期呼び出し (ブロッキングモード): SDK はタスクが完了するのを自動的に待機し、最終結果を直接返します。呼び出しエクスペリエンスは、通常の同期呼び出しと同じです。
非同期呼び出し (非ブロッキングモード): 呼び出しはすぐにタスク ID を返します。この ID を使用して、タスクのステータスと最終結果をクエリする必要があります。
Python SDK
DashScope Python SDK の最新バージョンがインストールされていることを確認してください。そうしないと、実行時エラーが発生する可能性があります。詳細については、「SDK のインストール」をご参照ください。
同期呼び出し
リクエストの例
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/en/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",
prompt=prompt,
n=1,
size='1328*1328',
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 に失敗しました, 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
}
}非同期呼び出し
リクエストの例
from http import HTTPStatus
from urllib.parse import urlparse, unquote
from pathlib import PurePosixPath
import requests
from dashscope import ImageSynthesis
import os
import dashscope
import time
# 次の 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/en/model-studio/get-api-key をご参照ください
# 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: api_key="sk-xxx"
api_key = os.getenv("DASHSCOPE_API_KEY")
def async_call():
print('----タスクを作成しています----')
task_info = create_async_task()
print('----タスクのステータスをポーリングしています----')
poll_task_status(task_info)
# 非同期タスクを作成します。
def create_async_task():
rsp = ImageSynthesis.async_call(api_key=api_key,
model="qwen-image-plus",
prompt=prompt,
n=1,
size='1328*1328',
prompt_extend=True,
watermark=False)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output)
else:
print(f'タスクの作成に失敗しました, status_code: {rsp.status_code}, code: {rsp.code}, message: {rsp.message}')
return rsp
# 非同期タスクのステータスをポーリングします。5 秒ごとにクエリし、最大 1 分間ポーリングします。
def poll_task_status(task):
start_time = time.time()
timeout = 60 # 1 分間のタイムアウト
while True:
# タイムアウトを確認します。
if time.time() - start_time > timeout:
print('ポーリングがタイムアウトしました (1 分間)、タスクは完了しませんでした')
return
# タスクのステータスを取得します。
status_rsp = ImageSynthesis.fetch(task)
print(f'タスクステータスのクエリ結果: {status_rsp}')
if status_rsp.status_code != HTTPStatus.OK:
print(f'タスクステータスの取得に失敗しました, status_code: {status_rsp.status_code}, code: {status_rsp.code}, message: {status_rsp.message}')
return
task_status = status_rsp.output.task_status
print(f'現在のタスクステータス: {task_status}')
if task_status == 'SUCCEEDED':
print('タスクが完了しました。イメージをダウンロードしています...')
for result in status_rsp.output.results:
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
with open(f'./{file_name}', 'wb+') as f:
f.write(requests.get(result.url).content)
print(f'イメージは次の名前で保存されました: {file_name}')
break
elif task_status == 'FAILED':
print(f'タスクの実行に失敗しました, status: {task_status}, code: {status_rsp.code}, message: {status_rsp.message}')
break
elif task_status == 'PENDING' or task_status == 'RUNNING':
print('タスクは進行中です。5 秒後にもう一度クエリします...')
time.sleep(5)
else:
print(f'不明なタスクステータス: {task_status}、5 秒後にもう一度クエリします...')
time.sleep(5)
# 非同期タスクをキャンセルします。PENDING 状態のタスクのみキャンセルできます。
def cancel_task(task):
rsp = ImageSynthesis.cancel(task)
print(rsp)
if rsp.status_code == HTTPStatus.OK:
print(rsp.output.task_status)
else:
print(f'タスクのキャンセルに失敗しました, status_code: {rsp.status_code}, code: {rsp.code}, message: {rsp.message}')
if __name__ == '__main__':
async_call()
応答の例
1. タスク作成の応答例
{
"status_code": 200,
"request_id": "31b04171-011c-96bd-ac00-xxxxxx",
"code": "",
"message": "",
"output": {
"task_id": "4f90cf14-a34e-4eae-xxxxxxxx",
"task_status": "PENDING",
"results": []
},
"usage": null
}2. タスク結果のクエリ応答例
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 SDK
DashScope Java SDK の最新バージョンがインストールされていることを確認してください。そうしないと、実行時エラーが発生する可能性があります。詳細については、「SDK のインストール」をご参照ください。
同期呼び出し
リクエストの例
// 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/en/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);
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(apiKey)
.model("qwen-image-plus")
.prompt(prompt)
.n(1)
.size("1328*1328")
.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
}
}非同期呼び出し
リクエストの例
// Copyright (c) Alibaba, Inc. and its affiliates.
import com.alibaba.dashscope.aigc.imagesynthesis.ImageSynthesis;
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.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/en/model-studio/get-api-key をご参照ください
// 環境変数を設定していない場合は、次の行を Model Studio API キーに置き換えてください: static String apiKey = "sk-xxx"
static String apiKey = System.getenv("DASHSCOPE_API_KEY");
public void asyncCall() {
System.out.println("---タスクを作成しています----");
String taskId = this.createAsyncTask();
System.out.println("---タスクが完了し、イメージ URL が返されるのを待っています----");
this.waitAsyncTask(taskId);
}
/**
* 非同期タスクを作成します。
* @return taskId
*/
public String createAsyncTask() {
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);
ImageSynthesisParam param =
ImageSynthesisParam.builder()
.apiKey(apiKey)
.model("qwen-image-plus")
.prompt(prompt)
.n(1)
.size("1328*1328")
.parameters(parameters)
.build();
try {
ImageSynthesisResult result = new ImageSynthesis().asyncCall(param);
System.out.println(JsonUtils.toJson(result));
String taskId = result.getOutput().getTaskId();
System.out.println("task_id=" + taskId);
return taskId;
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
/**
* 非同期タスクが完了するのを待ちます。
* @param taskId タスク ID。
* */
public void waitAsyncTask(String taskId) {
ImageSynthesis imageSynthesis = new ImageSynthesis();
long startTime = System.currentTimeMillis();
int timeout = 60 * 1000; // 1 分間のタイムアウト
int interval = 5 * 1000; // 5 秒のポーリング間隔
while (true) {
if (System.currentTimeMillis() - startTime > timeout) {
System.out.println("ポーリングがタイムアウトしました (1 分間)、タスクは完了しませんでした");
return;
}
try {
ImageSynthesisResult result = imageSynthesis.fetch(taskId, apiKey);
System.out.println("タスクステータスのクエリ結果: " + JsonUtils.toJson(result));
if (result.getOutput() == null) {
System.out.println("タスクステータスの取得に失敗しました、出力は空です");
return;
}
String taskStatus = result.getOutput().getTaskStatus();
System.out.println("現在のタスクステータス: " + taskStatus);
switch (taskStatus) {
case "SUCCEEDED":
System.out.println("タスクが完了しました");
System.out.println(JsonUtils.toJson(result));
return;
case "FAILED":
System.out.println("タスクの実行に失敗しました, status: " + taskStatus);
return;
case "PENDING":
case "RUNNING":
System.out.println("タスクは進行中です。5 秒後にもう一度クエリします...");
Thread.sleep(interval);
break;
default:
System.out.println("不明なタスクステータス: " + taskStatus + "、5 秒後にもう一度クエリします...");
Thread.sleep(interval);
break;
}
} catch (ApiException | NoApiKeyException e) {
System.err.println("API 呼び出しの例外: " + e.getMessage());
return;
} catch (InterruptedException e) {
System.err.println("スレッド割り込み例外: " + e.getMessage());
Thread.currentThread().interrupt();
return;
}
}
}
public static void main(String[] args){
Text2Image text2Image = new Text2Image();
text2Image.asyncCall();
}
}応答の例
1. タスク作成の応答例
{
"request_id": "5dbf9dc5-4f4c-9605-85ea-542f97709ba8",
"output": {
"task_id": "7277e20e-aa01-4709-xxxxxxxx",
"task_status": "PENDING"
}
}2. タスク結果のクエリ応答例
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
}
}課金とレート制限
qwen-image-plus モデルと qwen-image モデルは同じ機能を持ちますが、qwen-image-plus の方が費用対効果が高く、推奨されます。
シンガポールリージョン
モデル | 単価 | レート制限 (Alibaba Cloud アカウントと RAM ユーザーで共有) | 無料クォータ | |
タスク送信の RPS 制限 | 同時タスク数 | |||
qwen-image-plus | $0.03/イメージ | 2 | 2 | 無料クォータ: 各モデル 100 イメージ 有効期間: Alibaba Cloud Model Studio を有効化してから 90 日以内。 |
qwen-image | $0.035/イメージ | 2 | 2 | |
中国 (北京) リージョン
モデル | 単価 | レート制限 (Alibaba Cloud アカウントと RAM ユーザーで共有) | 無料クォータ | |
タスク送信の RPS 制限 | 同時タスク数 | |||
qwen-image-plus | $0.028671/イメージ | 2 | 2 | 無料クォータなし |
qwen-image | $0.035/イメージ | 2 | 2 | |
課金ルール
課金対象: 正常に生成されたイメージの数に対して、従量課金で課金されます。
課金数式: 料金 = 単価 × イメージ数。
消費順序: 無料クォータが最初に消費されます。無料クォータを使い切ると、デフォルトで従量課金方法が使用されます。
「無料クォータのみ」オプションを有効にすると、無料クォータを使い切った後の課金を防ぐことができます。詳細については、「新規ユーザー向けの無料クォータ」をご参照ください。
失敗時の課金なし: モデルの呼び出しの失敗や処理エラーは、料金が発生したり、無料クータを消費したりすることはありません。
無料クォータ
無料クォータの申請、クエリ、使用方法の詳細については、「新規ユーザー向けの無料クォータ」をご参照ください。
使用状況のクエリ
モデルの呼び出しが完了してから約 1 時間後に、モデル観測 (シンガポール) ページに移動して、使用状況、呼び出し回数、成功率などのメトリックを表示できます。
中国 (北京) リージョンのモデルを使用する場合は、中国 (北京) リージョンの [モデル観測] ページに移動してください。
レート制限
レート制限のルールとよくある質問については、「レート制限」をご参照ください。
イメージのアクセス構成
生成されたイメージは Alibaba Cloud OSS に保存されます。各イメージには、https://dashscope-result-xx.oss-cn-xxxx.aliyuncs.com/xxx.png などの OSS リンクが割り当てられます。OSS リンクはパブリックアクセスを許可しており、イメージの表示やダウンロードに使用できます。リンクは 24 時間のみ有効です。
ビジネスで高いセキュリティ要件があり、Alibaba Cloud OSS リンクにアクセスできない場合は、パブリックアクセス用にホワイトリストを設定する必要があります。イメージリンクにアクセスするには、次のドメイン名をホワイトリストに追加してください。
# OSS ドメイン名リスト
dashscope-result-bj.oss-cn-beijing.aliyuncs.com
dashscope-result-hz.oss-cn-hangzhou.aliyuncs.com
dashscope-result-sh.oss-cn-shanghai.aliyuncs.com
dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com
dashscope-result-zjk.oss-cn-zhangjiakou.aliyuncs.com
dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com
dashscope-result-hy.oss-cn-heyuan.aliyuncs.com
dashscope-result-cd.oss-cn-chengdu.aliyuncs.com
dashscope-result-gz.oss-cn-guangzhou.aliyuncs.com
dashscope-result-wlcb-acdr-1.oss-cn-wulanchabu-acdr-1.aliyuncs.comエラーコード
呼び出しが失敗した場合、トラブルシューティングについては、「エラーメッセージ」をご参照ください。
よくある質問
Q: prompt_extend パラメーターは有効にすべきですか、それとも無効にすべきですか?
A: 入力プロンプトが単純な場合や、モデルの創造性を高めたい場合は、有効 (デフォルト) のままにしておくことをお勧めします。プロンプトがすでに詳細で専門的である場合や、API 応答レイテンシーに厳しい要件がある場合は、明示的に false に設定することをお勧めします。
Q: qwen-image、qwen-image-plus、qwen-image-edit モデルの違いは何ですか?
A:
テキストからの画像生成モデル:
qwen-imageとqwen-image-plus
これらのモデルは、テキスト記述から画像を生成します。両方のモデルは同じ機能を持ちますが、qwen-image-plusの方が費用対効果が高く、推奨されます。画像編集モデル:
qwen-image-edit
このモデルは、入力画像とテキスト命令に基づいて、画像から画像への生成や局所的な変更などの操作を実行します。詳細については、「Qwen - 画像編集」をご参照ください。
