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

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

最終更新日:Jun 04, 2026

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

モデル概要

モデル

説明

出力画像仕様

qwen-image-2.0-pro 推奨

qwen-image-2.0-pro-2026-04-22 と同じ機能

画像生成および編集用の Qwen Pro シリーズ。テキストレンダリング、リアルな質感、セマンティクスへの忠実度が強化されています。

画像編集については、「Qwen-Image 編集」をご参照ください。

解像度:幅と高さを自由に設定可能。総ピクセル数は 512×512 ~ 2048×2048 の範囲内である必要があります。デフォルト解像度は 2048*2048 です。

フォーマット:PNG

画像枚数:1~6 枚

qwen-image-2.0-pro-2026-04-22 推奨

qwen-image-2.0-pro-2026-03-03

qwen-image-2.0 推奨

qwen-image-2.0-2026-03-03 と同じ機能

画像生成および編集用の Qwen 高速化シリーズ。品質と応答速度のバランスを取っています。

画像編集については、「Qwen-Image 編集」をご参照ください。

qwen-image-2.0-2026-03-03 推奨

qwen-image-max

qwen-image-max-2025-12-30 と同じ機能

画像生成用の Qwen Max シリーズ。より高いリアリズムと自然さを実現し、AI 生成特有のアーティファクトが少ないです。

解像度:サイズパラメータ設定でサポートされる解像度と縦横比をご確認ください。

フォーマット:PNG

画像枚数:1 枚固定

qwen-image-max-2025-12-30

qwen-image-plus

qwen-image と同じ機能

画像生成用の Qwen Plus シリーズ。多様なアートスタイルとテキストレンダリングに優れています。

qwen-image-plus-2026-01-09

qwen-image

qwen-image-plus および qwen-image のみが非同期呼び出しをサポートしています。
説明

API を呼び出す前に、ご利用のリージョンでサポートされているモデル一覧をご確認ください。

前提条件

呼び出しを行う前に、API キーを取得し、API キーを環境変数としてエクスポートしてください。SDK を使用して呼び出す場合は、DashScope SDK をインストールしてください。

重要

中国 (北京) リージョンとシンガポールリージョンでは、それぞれ別々の API キー および リクエストエンドポイント を使用します。これらは相互に使用できません。リージョンをまたいだ呼び出しは認証エラーまたはサービスエラーを引き起こします。

同期 API(推奨)

HTTP

同期呼び出しは、1 回のリクエストで結果を返します。

シンガポール: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

呼び出し時に、WorkspaceId を実際のワークスペース IDに置き換えてください。

中国 (北京): POST https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation

リクエストパラメーター

Text-to-Image

curl --location 'https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--data '{
    "model": "qwen-image-2.0-pro",
    "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": "Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-figure appearance, lack of facial detail, excessive smoothness, AI-looking artifacts, chaotic composition, blurry or warped text.",
      "prompt_extend": true,
      "watermark": false,
      "size": "2048*2048"
    }
}'
リクエストヘッダー

Content-Type string (必須)

リクエストのコンテンツタイプ。必ず application/json にしてください。

Authorization string (必須)

Model Studio API キーを使用してリクエストを認証します。例:Bearer sk-xxxx。

リクエスト本文

model string (必須)

モデル名。例:qwen-image-2.0-pro

input object (必須)

入力情報。

プロパティ

messages array (必須)

メッセージオブジェクトの配列。単一ターンの会話のみサポートされているため、配列には必ず 1 つの要素のみを含めてください。

プロパティ

role string (必須)

メッセージのロール。user に設定します。

content array (必須)

メッセージ本文オブジェクトの配列。

プロパティ

text string (必須)

生成したい画像の内容、スタイル、構成を記述する肯定的なプロンプト。

中国語および英語をサポートします。qwen-image-2.0 シリーズは最大 1,300 トークン、その他のモデルは最大 800 トークンを受け付けます。超過したトークンは自動的に切り捨てられます。

注: text フィールドは 1 つだけ許可されます。省略または複数指定するとエラーになります。

parameters object (任意)

画像処理パラメーター。

プロパティ

negative_prompt string (任意)

画像に含めたくない内容を記述する否定的なプロンプト。

中国語および英語をサポートします。最大長は 500 文字です。超過した文字は自動的に切り捨てられます。

例:低解像度、低品質、歪んだ四肢、変形した指、彩度過多、蝋人形のような外観、顔のディテール不足、過剰な滑らかさ、AI 生成風の見た目、混沌とした構図、ぼやけたまたは歪んだテキスト。

size string (任意)

出力画像の解像度。width*height 形式で指定します。

qwen-image-2.0 シリーズモデル: 総ピクセル数は 512×5122048×2048 の範囲内である必要があります。デフォルト解像度は 2048*2048 です。推奨解像度:

  • 2688*1536: 16:9

  • 1536*2688: 9:16

  • 2048*2048 (デフォルト): 1:1

  • 2368*1728: 4:3

  • 1728*2368: 3:4

qwen-image-max および qwen-image-plus シリーズモデル: デフォルト解像度は 1664*928 です。サポートされる解像度と縦横比:

  • 1664*928 (デフォルト): 16:9

  • 1472*1104: 4:3

  • 1328*1328: 1:1

  • 1104*1472: 3:4

  • 928*1664: 9:16

n integer (任意)

出力画像の枚数。デフォルトは 1 です。

qwen-image-2.0 シリーズモデルの場合、1~6 枚を選択できます。

qwen-image-max および qwen-image-plus シリーズモデルの場合、この値は 1 枚に固定されています。他の値を設定するとエラーになります。

prompt_extend bool (任意)

スマートプロンプトリライトを有効にします。モデルが肯定的なプロンプトを最適化します。否定的なプロンプトには影響しません。

  • true: デフォルト。リライトを有効にします。より多様な画像コンテンツを生成する場合に使用し、モデルが詳細を追加します。

  • false: リライトを無効にします。画像の詳細を厳密に制御する場合に使用します。最適な結果を得るには、Text-to-Image プロンプトガイドに基づいてプロンプトを最適化してください。

リライトの例を表示

実際のリライトされたプロンプトが返されるのは、非同期呼び出しの場合のみです。

元のプロンプト (orig_prompt): 座っているジンジャーキャットで、喜びに満ちた表情をしており、生き生きとして可愛らしく、信じられないほどリアル。

実際のプロンプト (actual_prompt): フォトリアルな野生動物ポートレート:日差しに照らされた豊かな毛並みと、活気に満ちた喜びの表情を持つ座っているジンジャーキャット。目は好奇心と温かさにきらめき、頭はわずかに傾き、耳は前向きに立っています。口元は満足げで活発なポーズをしており、可愛らしさと信じられないほどのリアルさを放っています。自然光が柔らかく、各ヒゲや毛一本一本の質感を強調し、口や耳の内側に微妙なハイライトが入っています。背景:黄金色の時間帯のぼんやりとした秋の庭園—琥珀色の葉の暖かい色合い、木々の間から差し込む木漏れ日、苔むした石段のほのかな兆し。構図は猫を中央の焦点として、浅い被写界深度でシャープに捉えています。スタイル:超リアルな写真、ナショナルジオグラフィックレベルのディテール、8K 解像度、Canon EOS R5、f/1.2 絞り、映画的なライティング、忠実なカラーグレーディング、最小限の後処理。テキストやオーバーレイなし。

watermark bool (任意)

画像の右下隅に「Qwen-Image」ウォーターマークを追加します。デフォルト:false。ウォーターマークのスタイル:1

seed integer (任意)

乱数シード。有効範囲:[0,2147483647]

同じ seed を使用すると、類似した出力が得られます。省略した場合、アルゴリズムはランダムなシードを使用します。

注: 画像生成は確率的です。同じ seed を使用しても、結果が異なる場合があります。

レスポンスパラメーター

タスク成功

画像 URL の有効期限は 24 時間のみで、その後自動的に消去されます。生成された画像は速やかに保存してください。

{
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "content": [
                        {
                            "image": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ],
                    "role": "assistant"
                }
            }
        ]
    },
    "usage": {
        "height": 2048,
        "image_count": 1,
        "width": 2048
    },
    "request_id": "d0250a3d-b07f-49e1-bdc8-6793f4929xxx"
}

タスク失敗

タスクが失敗した場合、レスポンスにコードおよびメッセージフィールドでエラーの詳細が含まれます。「エラーコード」をご参照ください。

{
    "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 になります。

message object

モデルの応答メッセージ。

プロパティ

role string

メッセージのロール。固定値:assistant

content array

プロパティ

image string

生成された画像の URL(PNG 形式)。24 時間で有効期限切れになります。速やかにダウンロードして保存してください。

task_metric object

タスク結果の統計情報。qwen-image-2.0 シリーズモデルでは返されません。

プロパティ

TOTAL integer

タスクの総数。

SUCCEEDED integer

成功したタスク数。

FAILED integer

失敗したタスク数。

usage object

出力統計情報。成功した結果のみをカウントします。

プロパティ

image_count integer

生成された画像の枚数。1 枚に固定されています。

width integer

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

height integer

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

request_id string

トレースおよびトラブルシューティング用の一意のリクエスト識別子。

code string

エラーコード。失敗したリクエストの場合のみ返されます。「エラーコード」をご参照ください。

message string

詳細なエラーメッセージ。失敗したリクエストの場合のみ返されます。「エラーコード」をご参照ください。

DashScope SDK 呼び出し

DashScope SDK は Python および Java をサポートしています。

SDK のパラメーター名は HTTP パラメーターとほぼ一致し、パラメーター構造は言語固有の規則に従います。同期呼び出しのパラメーターについては、「HTTP」をご参照ください。

Python

説明

実行時エラーを回避するため、最新の DashScope Python SDK をインストールしてください:SDK のインストール

リクエスト例
import json
import os
import dashscope
from dashscope import MultiModalConversation

# シンガポールリージョン用の URL を使用します。中国 (北京) リージョンの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.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
# 環境変数を設定していない場合は、以下の行を api_key="sk-xxx" に置き換えてください。
api_key = os.getenv("DASHSCOPE_API_KEY")

response = MultiModalConversation.call(
    api_key=api_key,
    model="qwen-image-2.0-pro",
    messages=messages,
    result_format='message',
    stream=False,
    watermark=False,
    prompt_extend=True,
    negative_prompt="Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-figure appearance, lack of facial detail, excessive smoothness, AI-looking artifacts, chaotic composition, blurry or warped text.",
    size='2048*2048'
)

if response.status_code == 200:
    print(json.dumps(response, ensure_ascii=False))
else:
    print(f"HTTP ステータスコード: {response.status_code}")
    print(f"エラーコード: {response.code}")
    print(f"エラーメッセージ: {response.message}")
    print("ドキュメントを参照: 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"
                        }
                    ]
                }
            }
        ]
    },
    "usage": {
        "input_tokens": 0,
        "output_tokens": 0,
        "width": 2048,
        "image_count": 1,
        "height": 2048
    }
}

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 {
        // シンガポールリージョン用の URL を使用します。中国 (北京) リージョンの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // 中国 (北京) リージョンとシンガポールリージョンでは API キーが異なります。API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    // 環境変数を設定していない場合は、以下の行を 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", "Low resolution, low quality, distorted limbs, malformed fingers, oversaturated colors, wax-figure appearance, lack of facial detail, excessive smoothness, AI-looking artifacts, chaotic composition, blurry or warped text.");
        parameters.put("size", "2048*2048");

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .apiKey(apiKey)
                .model("qwen-image-2.0-pro")
                .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": 2048,
        "height": 2048
    },
    "output": {
        "choices": [
            {
                "finish_reason": "stop",
                "message": {
                    "role": "assistant",
                    "content": [
                        {
                            "image": "https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/xxx.png?Expires=xxx"
                        }
                    ]
                }
            }
        ]
    }
}

非同期 API

重要

非同期呼び出しをサポートするのは、qwen-image-plus および qwen-image のみです。

HTTP

非同期呼び出しは、2 ステップの HTTP ワークフローを使用します。

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

  2. タスク ID を使用して結果をポーリング: task_id を使用してタスクのステータスを完了するまでポーリングし、画像 URL を取得します。

ステップ 1: タスクを作成してタスク ID を取得

シンガポール: POST https://{WorkspaceId}.ap-southeast-1.maas.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 時間です。重複タスクを作成しないでください。代わりにポーリングを使用して結果を取得してください。

  • 初心者向けのガイドについては、「Postman」をご参照ください。

リクエストパラメーター

Text-to-Image

qwen-image-plus および qwen-image のみが非同期呼び出しをサポートします。

curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.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
    }
}'        

リクエストヘッダー

Content-Type string (必須)

リクエストのコンテンツタイプ。必ず application/json にしてください。

Authorization string (必須)

Model Studio API キーを使用してリクエストを認証します。例:Bearer sk-xxxx。

X-DashScope-Async string (必須)

非同期処理を有効にします。HTTP リクエストでは非同期呼び出しのみサポートされます。必ず enable にしてください。

重要

このリクエストヘッダーが欠落している場合、「current user api does not support synchronous calls」というエラーが返されます。

リクエスト本文

model string (必須)

モデル名。qwen-image-plus および qwen-image のみが非同期呼び出しをサポートします。

例:qwen-image-plus

input object (必須)

入力情報。

プロパティ

prompt string (必須)

生成された画像に含めたい視覚的要素および特性を記述する肯定的なプロンプト。

中国語および英語をサポートします。最大長は 800 文字です。中国語の文字、英字、数字、記号はそれぞれ 1 文字としてカウントされます。超過した文字は自動的に切り捨てられます。

例:座っているオレンジ色の猫で、喜びに満ちた表情をしており、生き生きとして可愛らしく、非常にリアル。

negative_prompt string (任意)

画像に含めたくない内容を記述する否定的なプロンプト。

中国語および英語をサポートします。最大長は 500 文字です。超過した文字は自動的に切り捨てられます。

例:低解像度、低品質、歪んだ四肢、変形した指、彩度過多、蝋人形のような外観、顔のディテール不足、過剰な滑らかさ、AI 生成風の見た目、混沌とした構図、ぼやけたまたは歪んだテキスト。

parameters object (任意)

画像処理パラメーター。

プロパティ

size string (任意)

出力画像の解像度。width*height 形式で指定します。

qwen-image-2.0 シリーズモデル: 総ピクセル数は 512×5122048×2048 の範囲内である必要があります。デフォルト解像度は 2048*2048 です。推奨解像度:

  • 2688*1536: 16:9

  • 1536*2688: 9:16

  • 2048*2048 (デフォルト): 1:1

  • 2368*1728: 4:3

  • 1728*2368: 3:4

qwen-image-max および qwen-image-plus シリーズモデル: デフォルト解像度は 1664*928 です。サポートされる解像度と縦横比:

  • 1664*928 (デフォルト): 16:9

  • 1472*1104: 4:3

  • 1328*1328: 1:1

  • 1104*1472: 3:4

  • 928*1664: 9:16

n integer (任意)

生成された画像の枚数。この値は 1 枚に固定されています。他の値を設定するとエラーになります。

prompt_extend bool (任意)

スマートプロンプトリライトを有効にします。モデルが肯定的なプロンプトを最適化します。否定的なプロンプトには影響しません。

  • true: デフォルト。リライトを有効にします。より多様な画像コンテンツを生成する場合に使用し、モデルが詳細を追加します。

  • false: リライトを無効にします。画像の詳細を厳密に制御する場合に使用します。最適な結果を得るには、Text-to-Image プロンプトガイドに基づいてプロンプトを最適化してください。

リライトの例を表示

実際のリライトされたプロンプトが返されるのは、非同期呼び出しの場合のみです。

元のプロンプト (orig_prompt): 座っているジンジャーキャットで、喜びに満ちた表情をしており、生き生きとして可愛らしく、信じられないほどリアル。

実際のプロンプト (actual_prompt): フォトリアルな野生動物ポートレート:日差しに照らされた豊かな毛並みと、活気に満ちた喜びの表情を持つ座っているジンジャーキャット。目は好奇心と温かさにきらめき、頭はわずかに傾き、耳は前向きに立っています。口元は満足げで活発なポーズをしており、可愛らしさと信じられないほどのリアルさを放っています。自然光が柔らかく、各ヒゲや毛一本一本の質感を強調し、口や耳の内側に微妙なハイライトが入っています。背景:黄金色の時間帯のぼんやりとした秋の庭園—琥珀色の葉の暖かい色合い、木々の間から差し込む木漏れ日、苔むした石段のほのかな兆し。構図は猫を中央の焦点として、浅い被写界深度でシャープに捉えています。スタイル:超リアルな写真、ナショナルジオグラフィックレベルのディテール、8K 解像度、Canon EOS R5、f/1.2 絞り、映画的なライティング、忠実なカラーグレーディング、最小限の後処理。テキストやオーバーレイなし。

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": "No API-key provided.",
    "request_id": "7438d53d-6eb8-4596-8835-xxxxxx"
}

output object

タスク出力情報。

プロパティ

task_id string

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

task_status string

タスクのステータス。

列挙値

  • PENDING

  • RUNNING

  • SUCCEEDED

  • FAILED

  • CANCELED

  • UNKNOWN: タスクが存在しない、またはステータスが不明です。

request_id string

トレースおよびトラブルシューティング用の一意のリクエスト識別子。

code string

エラーコード。失敗したリクエストの場合のみ返されます。「エラーコード」をご参照ください。

message string

詳細なエラーメッセージ。失敗したリクエストの場合のみ返されます。「エラーコード」をご参照ください。

ステップ 2: タスク ID を使用して結果をポーリング

シンガポール

GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id}

呼び出し時に、WorkspaceId を実際のワークスペース IDに置き換えてください。

中国 (北京)

GET https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}

説明
  • ポーリングの推奨事項: 画像生成は時間がかかります。10 秒間隔など、適切な間隔でポーリングメカニズムを使用してください。

  • タスクの状態遷移: PENDING → RUNNING → SUCCEEDED または FAILED。

  • 結果リンク: タスクが成功すると、24 時間有効の画像 URL が返されます。画像を OSS などの永続ストレージにダウンロードして保存してください。

リクエストパラメーター

タスク結果のポーリング

{task_id} を前の API 呼び出しで返された task_id の値に置き換えてください。task_id のクエリ有効期限は 24 時間です。

curl -X GET https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1/tasks/{task_id} \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
リクエストヘッダー

Authorization string (必須)

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": "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/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

タスクが送信された時刻。時刻は UTC + 08:00 で、形式は YYYY-MM-DD HH:mm:ss.SSS です。

scheduled_time string

タスクが実行された時刻。時刻は UTC + 08:00 で、形式は YYYY-MM-DD HH:mm:ss.SSS です。

end_time string

タスクが完了した時刻。時刻は UTC + 08:00 で、形式は YYYY-MM-DD HH:mm:ss.SSS です。

results array

タスク結果のリスト。画像 URL、プロンプト、失敗したタスクのエラーメッセージを含みます。

プロパティ

orig_prompt string

元の入力プロンプト。リクエストパラメーター prompt に対応します。

actual_prompt string

プロンプトリライトが有効な場合に使用される最適化されたプロンプト。無効な場合は返されません。

url string

生成された画像の URL。24 時間で有効期限切れになります。画像は速やかにダウンロードして保存してください。

code string

エラーコード。失敗したリクエストの場合のみ返されます。「エラーコード」をご参照ください。

message string

詳細なエラーメッセージ。失敗したリクエストの場合のみ返されます。「エラーコード」をご参照ください。

usage object

出力統計情報。成功した結果のみをカウントします。

プロパティ

image_count integer

生成された画像の枚数。1 枚に固定されています。

request_id string

トレースおよびトラブルシューティング用の一意のリクエスト識別子。

DashScope SDK

DashScope SDK は Python および Java をサポートしています。

SDK のパラメーター名は HTTP のものとほぼ一致します。パラメーター構造は言語固有の規則に従います。非同期呼び出しのパラメーターについては、「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 を使用します。中国 (北京) リージョンの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.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
# 環境変数を設定していない場合は、以下の行を api_key="sk-xxx" に置き換えてください。
api_key = os.getenv("DASHSCOPE_API_KEY")

print('----同期呼び出し、少々お待ちください----')
rsp = ImageSynthesis.call(api_key=api_key,
                          model="qwen-image-plus", # 非同期呼び出しをサポートするのは 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'同期呼び出しに失敗しました。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 を使用します。中国 (北京) リージョンの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
dashscope.base_http_api_url = 'https://{WorkspaceId}.ap-southeast-1.maas.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
# 環境変数を設定していない場合は、以下の行を 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", # 非同期呼び出しをサポートするのは qwen-image-plus および qwen-image のみ
                                    prompt=prompt,
                                    negative_prompt=" ",
                                    n=1,
                                    size='1664*928',
                                    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'タスクの実行に失敗しました。ステータス: {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 を使用します。中国 (北京) リージョンの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // 中国 (北京) リージョンとシンガポールリージョンでは API キーが異なります。API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    // 環境変数を設定していない場合は、以下の行を 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)
                        // 非同期呼び出しをサポートするのは 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
    }
}

非同期

リクエスト例
// 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 を使用します。中国 (北京) リージョンの場合は、https://dashscope.aliyuncs.com/api/v1 に置き換えてください。
        Constants.baseHttpApiUrl = "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/api/v1";
    }

    // 中国 (北京) リージョンとシンガポールリージョンでは API キーが異なります。API キーの取得: https://www.alibabacloud.com/help/en/model-studio/get-api-key
    // 環境変数を設定していない場合は、以下の行を 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);
    }

    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);
        parameters.put("negative_prompt", " ");
        ImageSynthesisParam param =
                ImageSynthesisParam.builder()
                        .apiKey(apiKey)
                        // 非同期呼び出しをサポートするのは qwen-image-plus および qwen-image のみ
                        .model("qwen-image-plus")
                        .prompt(prompt)
                        .n(1)
                        .size("1664*928")
                        .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());
        }
    }

    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("タスクの実行に失敗しました。ステータス: " + 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 (Qwen-Image)」をご参照ください。

  • 課金の詳細: 正常に生成された画像 ごとに課金されます。失敗した呼び出しや処理エラーは、課金対象にならず、新規ユーザー無料クォータも消費しません。

エラーコード

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

よくある質問

Q: prompt_extend パラメーターを有効にするべきですか、それとも無効にするべきですか?

A: より多様な画像コンテンツを生成し、モデルに詳細を追加させたい場合は、このオプションを有効にしてください(デフォルト)。画像の詳細を厳密に制御する必要がある場合は無効にして、Text-to-Image プロンプトガイドに基づいてプロンプトを最適化してください。

Q: qwen-image、qwen-image-plus、qwen-image-max、qwen-image-2.0、qwen-image-edit の違いは何ですか?

A:

  • 画像生成および編集を統合したモデル: Text-to-Image および画像編集の両方をサポートします。

    • qwen-image-2.0-pro および qwen-image-2.0-pro-2026-03-03: 同じ機能。Pro シリーズは、より専門的なテキストレンダリング、より細かいリアルな質感、詳細なリアルなシーン、より強いセマンティクスへの忠実度を提供します。同期呼び出しのみをサポートします。

    • qwen-image-2.0 および qwen-image-2.0-2026-03-03: 同じ機能。高速化バージョンは、モデルのパフォーマンスと品質のバランスを取ります。同期呼び出しのみをサポートします。

  • Text-to-Image モデル: テキスト記述から画像を生成します。

    • qwen-image-max および qwen-image-max-2025-12-30: 同じ機能。qwen-image-plus と比較して、より高いリアリズムと自然さを実現し、キャラクターの質感、ディテール、テキストレンダリングの結果が向上しています。

    • qwen-image および qwen-image-plus: 同じ機能ですが、qwen-image-plus の方がコスト効率に優れています。

    • qwen-image-plus-2026-01-09: Qwen-Image の新しいスナップショットバージョン。qwen-image-max の蒸留および高速化バージョンで、高品質な画像を高速に生成できます。

  • 画像編集モデル:qwen-image-edit: 入力画像とテキスト命令に基づいて、画像間変換、インペインティングなどの操作を実行します。詳細については、「Qwen - 画像編集」をご参照ください。

Q: 画像ストレージのドメイン名ホワイトリストを取得するにはどうすればよいですか?

A: モデルによって生成された画像は OSS に保存されます。API は一時的な公開 URL を返します。このダウンロード URL のファイアウォールホワイトリストを設定する場合、以下の点にご注意ください。基盤となるストレージは動的に変更される可能性があります。このトピックでは、古い情報によるアクセス障害を防ぐため、固定の OSS ドメイン名ホワイトリストは提供していません。セキュリティ制御の要件がある場合は、アカウントマネージャーに連絡して、最新の OSS ドメイン名リストを取得してください。