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

Alibaba Cloud Model Studio:Qwen-Image API リファレンス

最終更新日:Nov 14, 2025

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!」という補足テキストがあります。カラーパレットは、新鮮な緑と青を中心に、明るいピンクと黄色のトーンでアクセントをつけ、陽気で子供らしい雰囲気を強調しています。

image

前提条件

呼び出しを行う前に、お住まいのリージョンの 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

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "qwen-image-plus",
    "input": {
      "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."
            }
          ]
        }
      ]
    },
    "parameters": {
      "negative_prompt": "",
      "prompt_extend": true,
      "watermark": false,
      "size": "1328*1328"
    }
}'
リクエストヘッダー

Content-Type string (必須)

リクエストのコンテンツタイプ。このパラメーターを application/json に設定します。

Authorization string (必須)

リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例: Bearer sk-xxxx。

リクエスト本文

model string (必須)

モデル名。このパラメーターを qwen-image-plus または qwen-image に設定します。両方のモデルは同じ機能を持ちます。qwen-image-plus はより費用対効果が高いため、使用することをお勧めします。

input object (必須)

基本情報を入力します。

プロパティ

messages array (必須)

リクエストコンテンツの配列。現在、シングルターンの会話のみがサポートされています。配列には正確に 1 つの要素が含まれている必要があります。

プロパティ

role string (必須)

メッセージのロール。このパラメーターは user に設定する必要があります。

content array (必須)

メッセージコンテンツの配列。

プロパティ

text string (必須)

生成される画像の望ましいコンテンツ、スタイル、構成を記述するポジティブプロンプト。

最大長は 800 文字です。このパラメーターは中国語と英語の両方をサポートしています。各漢字、文字、数字、または記号は 1 文字としてカウントされます。超過した文字は自動的に切り捨てられます。

例: 幸せそうな表情で座っているオレンジ色の猫、生き生きとしていてかわいい、リアルで正確。

: 正確に 1 つのテキスト要素を渡す必要があります。そうしないと、呼び出しは失敗します。

parameters object (オプション)

画像処理パラメーター。

プロパティ

negative_prompt string (オプション)

画像で見たくないコンテンツを記述するネガティブプロンプト。画像に制約をかけるために使用できます。

最大長は 500 文字です。このパラメーターは中国語と英語の両方をサポートしています。超過した文字は自動的に切り捨てられます。

例: 低解像度、エラー、最悪の品質、低品質、変形、余分な指、悪いプロポーション。

size string (オプション)

出力画像の解像度。幅 × 高さの形式です。デフォルトの解像度は 1328 × 1328 です。

利用可能な解像度とそれに対応する縦横比は次のとおりです。

  • 1664 × 928: 16:9。

  • 1472 × 1140: 4:3。

  • 1328 × 1328 (デフォルト): 1:1。

  • 1140 × 1472: 3:4。

  • 928 × 1664: 9:16。

n integer (オプション)

生成する画像の数。このパラメーターは現在 1 に固定されています。他の値を設定するとエラーが発生します。

prompt_extend bool (オプション)

プロンプトの書き換えを有効にするかどうかを指定します。有効にすると、モデルはポジティブプロンプトを最適化します。これにより、短いまたは単純なプロンプトの結果が大幅に向上しますが、処理時間が 3〜4 秒増加します。

  • true

  • false

watermark bool (オプション)

画像の右下隅に「Qwen-Image」のウォーターマークを追加するかどうかを指定します。デフォルト値は false です。ウォーターマーク:

1

seed integer (オプション)

乱数シードは、モデルによって生成されるコンテンツのランダム性を制御するために使用され、値の範囲は [0, 2147483647] です。

同じ seed 値を使用すると、より一貫した結果が生成されます。シードを指定しない場合、アルゴリズムは乱数を使用します。

: モデルの生成プロセスは確率的です。同じ seed を使用しても、呼び出しごとに結果が同一であることが保証されるわけではありません。

応答パラメーター

タスク成功

タスクのステータスや画像 URL などのタスクデータは 24 時間のみ保持され、この期間が過ぎると自動的にパージされます。生成された画像は速やかに保存する必要があります。

{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/xxx.png?Expires=xxxx"
                        }
                    ]
                }
            }
        ],
        "task_metric": {
            "TOTAL": 1,
            "FAILED": 0,
            "SUCCEEDED": 1
        }
    },
    "usage": {
        "width": 1328,
        "image_count": 1,
        "height": 1328
    },
    "request_id": "7a270c86-db58-9faf-b403-xxxxxx"
}

タスク異常

タスクが失敗した場合、応答には失敗に関する情報が含まれます。`code` および `message` フィールドはエラーの原因を示します。問題の解決方法の詳細については、「エラーメッセージ」をご参照ください。

{
    "request_id": "a4d78a5f-655f-9639-8437-xxxxxx",
    "code": "InvalidParameter",
    "message": "num_images_per_prompt must be 1"
}

output object

タスクの出力情報。

プロパティ

choices array

モデルによって生成された出力コンテンツ。この配列には 1 つの要素のみが含まれます。

プロパティ

finish_reason string

タスクが停止した理由。stop の値は正常な完了を示します。

messages object

モデルから返されたメッセージ。

プロパティ

role string

メッセージのロール。これは assistant に固定されています。

content array

プロパティ

image string

生成された画像の URL (PNG 形式)。リンクは 24 時間有効です。画像を速やかにダウンロードして保存してください。

task_metric object

タスク結果の統計。

プロパティ

TOTAL integer

タスクの総数。

SUCCEEDED integer

成功したタスクの数。

FAILED integer

失敗したタスクの数。

usage object

出力の使用状況統計。成功した結果のみがカウントされます。

プロパティ

image_count integer

モデルによって生成された画像の数。これは現在 1 に固定されています。

width integer

生成された画像の幅 (ピクセル単位)。

height integer

生成された画像の高さ (ピクセル単位)。

request_id string

一意のリクエスト ID。この ID を使用して問題を追跡およびトラブルシューティングできます。

code string

失敗したリクエストのエラーコード。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。

message string

失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。


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 つのステップで構成されます:

  1. タスクを作成してタスク ID を取得する: タスクを作成するリクエストを送信します。応答でタスク ID (task_id) が返されます。

  2. タスク 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 時間有効です。重複したタスクを作成しないでください。ポーリングを使用して結果を取得してください。

リクエストパラメーター

テキストからイメージへ

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": "緑豊かな芝生の上でボールで遊ぶ 3 匹の子犬をフィーチャーした、癒し系の手描きポスター。鳥や星などの装飾的な要素で飾られています。メインタイトル「Come Play Ball!」は、太字の青い漫画風フォントで上部に目立つように表示されています。その下には、サブタイトル「Come [Show Off Your Skills]!」が緑色のフォントで表示されています。吹き出しには「へへ、次は僕の技で友達を驚かせてやる!」というテキストがあり、遊び心のある魅力を加えています。下部には、「また友達とボールで遊べるね!」という補足テキストがあります。カラーパレットは、新鮮な緑と青を中心に、明るいピンクと黄色のトーンでアクセントをつけ、陽気で子供らしい雰囲気を強調しています。"
    },
    "parameters": {
        "size": "1328*1328",
        "n": 1,
        "prompt_extend": true,
        "watermark": false
    }
}'        

リクエストヘッダー

Content-Type string (必須)

リクエストのコンテンツタイプ。このパラメーターを application/json に設定します。

Authorization string (必須)

リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例: Bearer sk-xxxx。

X-DashScope-Async string (必須)

非同期処理の構成パラメーター。HTTP リクエストは非同期処理のみをサポートします。このパラメーターを enable に設定する必要があります。

重要

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

リクエスト本文

model string (必須)

モデル名。このパラメーターを qwen-image-plus または qwen-image に設定します。両方のモデルは同じ機能を持ちます。qwen-image-plus はより費用対効果が高いため、使用することをお勧めします。

input object (必須)

プロンプトなどの基本的な入力情報。

プロパティ

prompt string (必須)

生成されるイメージに含めたい要素や視覚的特徴を記述するポジティブプロンプト。

最大長は 800 文字です。このパラメーターは中国語と英語の両方をサポートします。各中国語の文字、英字、数字、または記号は 1 文字としてカウントされます。超過した文字は自動的に切り捨てられます。

例: 幸せそうな表情で座っているオレンジ色の猫、活発でかわいい、リアルで正確。

negative_prompt string (任意)

イメージに表示したくないコンテンツを記述するネガティブプロンプト。イメージを制約するために使用できます。

最大長は 500 文字です。このパラメーターは中国語と英語の両方をサポートします。超過した文字は自動的に切り捨てられます。

例: 低解像度、エラー、最低品質、低品質、変形、余分な指、悪いプロポーション。

parameters object (任意)

イメージ処理パラメーター。

プロパティ

size string (任意)

出力イメージの解像度。width × height のフォーマットです。デフォルトの解像度は 1328 × 1328 です。

利用可能な解像度とそれに対応する縦横比は次のとおりです:

  • 1664 × 928: 16:9。

  • 1472 × 1140: 4:3。

  • 1328 × 1328 (デフォルト): 1:1。

  • 1140 × 1472: 3:4。

  • 928 × 1664: 9:16。

n integer (任意)

生成するイメージの数。このパラメーターは現在 1 に固定されています。他の値を設定するとエラーが発生します。

prompt_extend bool (任意)

プロンプトの書き換えを有効にするかどうかを指定します。有効にすると、モデルはポジティブプロンプトを最適化します。これにより、短いまたは単純なプロンプトの結果が大幅に向上しますが、処理時間が 3〜4 秒増加します。

  • true

  • false

watermark bool (任意)

イメージの右下隅に「Qwen-Image」のウォーターマークを追加するかどうかを指定します。デフォルト値は false です。ウォーターマーク:

1

seed integer (任意)

乱数シードは、モデルによって生成されるコンテンツのランダム性を制御するために使用され、値の範囲は [0, 2147483647] です。

同じ seed 値を使用すると、より一貫した結果が生成されます。シードを指定しない場合、アルゴリズムは乱数を使用します。

: モデルの生成プロセスは確率的です。同じ seed を使用しても、呼び出しごとに結果が同一であることは保証されません。

応答パラメーター

成功した応答

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

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

エラー応答

タスクの作成に失敗しました。詳細については、「エラーメッセージ」をご参照ください。問題を解決してください。

{
    "code":"InvalidApiKey",
    "message":"Invalid API-key provided.",
    "request_id":"fb53c4ec-1c12-4fc4-a580-xxxxxx"
}

output object

タスクの出力情報。

プロパティ

task_id string

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

task_status string

タスクのステータス。

列挙

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN

request_id string

一意のリクエスト ID。この ID を使用して問題を追跡およびトラブルシューティングできます。

code string

失敗したリクエストのエラーコード。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。

message string

失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。

ステップ 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 などのストレージスペースに転送する必要があります。

リクエストパラメーター

タスク結果のクエリ

86ecf553-d340-4e21-xxxxxxxxx を実際のタスク ID に置き換えてください。

シンガポールリージョンと北京リージョンの API キーは異なります。「API キーを取得する」をご参照ください。
以下のコードはシンガポールリージョンの base_url を提供します。北京リージョンのモデルを使用する場合は、base_url を https://dashscope.aliyuncs.com/api/v1/tasks/{task_id} に置き換えてください
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
リクエストヘッダー

Authorization string (必須)

リクエストの身分認証情報。この API は、身分認証に Model Studio API キーを使用します。例: Bearer sk-xxxx。

URL パスパラメーター

task_id string (必須)

タスク ID。

応答パラメーター

タスク成功

タスクステータスやイメージ URL などのタスクデータは 24 時間のみ保持され、この期間が過ぎると自動的に消去されます。生成されたイメージは速やかに保存する必要があります。

{
    "request_id": "7434edb2-3cba-44e6-a772-xxxxxx",
    "output": {
        "task_id": "878f591e-ebdf-4e45-97eb-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-09-09 11:38:54.741",
        "scheduled_time": "2025-09-09 11:38:54.781",
        "end_time": "2025-09-09 11:39:19.484",
        "results": [
            {
                "orig_prompt": "緑豊かな芝生の上でボールで遊ぶ 3 匹の子犬をフィーチャーした、癒し系の手描きポスター。鳥や星などの装飾的な要素で飾られています。メインタイトル「Come Play Ball!」は、太字の青い漫画風フォントで上部に目立つように表示されています。その下には、サブタイトル「Come [Show Off Your Skills]!」が緑色のフォントで表示されています。吹き出しには「へへ、次は僕の技で友達を驚かせてやる!」というテキストがあり、遊び心のある魅力を加えています。下部には、「また友達とボールで遊べるね!」という補足テキストがあります。カラーパレットは、新鮮な緑と青を中心に、明るいピンクと黄色のトーンでアクセントをつけ、陽気で子供らしい雰囲気を強調しています。",
                "actual_prompt": "子供時代にインスパイアされた手描きポスターデザイン: 3 匹の遊び好きな子犬が、緑豊かな芝生の鮮やかな一角で、カラフルなボールと楽しそうに戯れています。舞い飛ぶ鳥やきらめく星など、繊細な装飾要素が全体に散りばめられています。上部中央には、太字で青い漫画風のタイトル「Come Play Ball!」が目立っています。その真下には、サブタイトル「Come [Show Off Your Skills]!」が陽気な緑色の文字で描かれています。子犬の 1 匹の近くにある気まぐれな吹き出しには、「へへ、次は僕の技で友達を驚かせてやる!」という遊び心のあるテキストが含まれています。下端には、「また友達とボールで遊べるね!」という小さな補足テキストがあります。カラーパレットは、新鮮な緑と空色を中心に、明るいピンクと太陽のような黄色のポップな色でアクセントをつけ、陽気で子供らしい雰囲気を高めています。スタイルは、柔らかいテクスチャ、優しい線画、そして気まぐれな絵本のような構成で、ノスタルジックな手描きのイラストを彷彿とさせます。",
                "url": "https://dashscope-result-sz.oss-cn-shenzhen.aliyuncs.com/7d/xxx.png?Expires=xxxx"
            }
        ]
    },
    "usage": {
        "image_count": 1
    }
}

タスク失敗

タスクが失敗した場合、task_status は FAILED に設定され、エラーコードとメッセージが提供されます。詳細については、「エラーメッセージ」をご参照ください。問題を解決してください。

{
    "request_id": "c61fe158-c0de-40f0-b4d9-964625119ba4",
    "output": {
        "task_id": "86ecf553-d340-4e21-xxxxxxxxx",
        "task_status": "FAILED",
        "submit_time": "2025-11-11 11:46:28.116",
        "scheduled_time": "2025-11-11 11:46:28.154",
        "end_time": "2025-11-11 11:46:28.255",
        "code": "InvalidParameter",
        "message": "xxxxxxxx"
    }
}

output object

タスクの出力情報。

プロパティ

task_id string

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

task_status string

タスクのステータス。

列挙

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN

submit_time string

タスクが送信された時間。フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。

scheduled_time string

タスクの実行が開始された時間。フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。

end_time string

タスクが完了した時間。フォーマットは YYYY-MM-DD HH:mm:ss.SSS です。

results array

タスク結果のリスト。結果には、イメージ URL、プロンプト、および失敗したサブタスクのエラーメッセージが含まれます。

データ構造

{
    "results": [
        {
            "orig_prompt": "",
            "actual_prompt": "",
            "url": ""
        },
        {
            "code": "",
            "message": ""
        }
    ]
}

プロパティ

orig_prompt string

元の入力プロンプト。

actual_prompt string

プロンプトの書き換えが有効になった後に使用される実際のプロンプト。プロンプトの書き換えが無効になっている場合、このフィールドは返されません。

url string

モデルによって生成されたイメージの URL。URL は 24 時間有効です。イメージを速やかにダウンロードして保存してください。

code string

失敗したリクエストのエラーコード。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。

message string

失敗したリクエストの詳細情報。リクエストが成功した場合、このパラメーターは返されません。詳細については、「エラーメッセージ」をご参照ください。

usage object

出力の使用状況統計。成功した結果のみがカウントされます。

プロパティ

image_count integer

モデルによって生成されたイメージの数。これは現在 1 に固定されています。

request_id string

一意のリクエスト ID。この ID を使用して問題を追跡およびトラブルシューティングできます。

DashScope SDK

DashScope SDK は現在、PythonJava をサポートしています。

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-imageqwen-image-plus
    これらのモデルは、テキスト記述から画像を生成します。両方のモデルは同じ機能を持ちますが、qwen-image-plus の方が費用対効果が高く、推奨されます。

  • 画像編集モデル: qwen-image-edit
    このモデルは、入力画像とテキスト命令に基づいて、画像から画像への生成や局所的な変更などの操作を実行します。詳細については、「Qwen - 画像編集」をご参照ください。