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

Alibaba Cloud Model Studio:画像による検索

最終更新日:Aug 26, 2026

画像検索ツールを使用すると、モデルは入力画像に基づいて、視覚的に類似した画像をインターネットで検索できます。その後、モデルは検索結果を分析し、推論を行うことができます。この機能は、類似製品の検索や視覚コンテンツの出所の追跡などのシナリオで役立ちます。

使用方法

画像検索機能は、Responses API を介して呼び出すことができます。 image_search ツールを tools パラメーターに追加し、マルチモーダル形式で input パラメーターに画像を渡します。

input パラメーターには画像コンテンツを含める必要があります。 input_image タイプを使用して画像 URL を渡します。 input_text タイプを使用してテキストを渡し、検索の追加情報を提供することもできます。

# 依存関係をインポートし、クライアントを作成します
input_content = [
    {"type": "input_text", "text": "Find landscape images with a style similar to this one"},
    {"type": "input_image", "image_url": "https://img.alicdn.com/imgextra/i4/O1CN01YbrnSS1qtmsAkw0Ud_!!6000000005554-2-tps-788-450.png"}
]
response = client.responses.create(
    model="qwen3.8-max",
    input=[{"role": "user", "content": input_content}],
    tools=[{"type": "image_search"}]
)

print(response.output_text)

サポートされているモデル

推奨モデル

ツール呼び出しのパフォーマンスを最適化するには、次のモデルを推奨します:

Qwen-Plus: Qwen3.7-Plus シリーズ、Qwen3.6-Plus シリーズ、Qwen3.5-Plus シリーズ

Qwen-Max: Qwen3.8-Max シリーズ、qwen3.7-max-2026-06-08

qwen3.8-27b

その他のモデル

次のモデルもこのツールをサポートしていますが、パフォーマンスは推奨モデルほど高くありません。

  • Qwen-Flash: Qwen3.7-Flash シリーズ、Qwen3.6-Flash シリーズ、Qwen3.5-Flash シリーズ

この機能は Responses API を介してのみ呼び出すことができます。

はじめに

次のコードを実行して、Responses API 経由で画像検索ツールを呼び出し、入力画像に基づいて類似または関連する画像を検索できます。

開始する前に、API キーを取得し、API キーを環境変数として設定してください。

サンプルコードの image_url を、一般公開されている画像の URL に置き換えてください。

import os
import json
from openai import OpenAI

client = OpenAI(
    # 環境変数を設定していない場合は、次の行を Model Studio の API キーに置き換えます: api_key="sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 次の URL は、シンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)

input_content = [
    {"type": "input_text", "text": "Find landscape images with a style similar to this one"},
    # image_url を実際の公開画像 URL に置き換えます
    {"type": "input_image", "image_url": "https://img.alicdn.com/imgextra/i4/O1CN01YbrnSS1qtmsAkw0Ud_!!6000000005554-2-tps-788-450.png"}
]

response = client.responses.create(
    model="qwen3.8-max",
    input=[{"role": "user", "content": input_content}],
    tools=[
        {
            "type": "image_search"
        }
    ]
)

# 出力を走査して各ステップを表示します
for item in response.output:
    if item.type == "image_search_call":
        print(f"[Tool Call] Search by image (status: {item.status})")
        # 検索された画像のリストを解析して表示します
        if item.output:
            images = json.loads(item.output)
            print(f"  Found {len(images)} images:")
            for img in images[:5]:  # 最初の 5 枚の画像を表示します
                print(f"  [{img['index']}] {img['title']}")
                print(f"      {img['url']}")
            if len(images) > 5:
                print(f"  ... {len(images)} images in total")
    elif item.type == "message":
        print(f"\n[Model Response]")
        print(response.output_text)

# トークン使用量とツール呼び出しの統計を表示します
print(f"\n[Token Usage] Input: {response.usage.input_tokens}, Output: {response.usage.output_tokens}, Total: {response.usage.total_tokens}")
if hasattr(response.usage, 'x_tools') and response.usage.x_tools:
    for tool_name, info in response.usage.x_tools.items():
        print(f"[Tool Statistics] {tool_name} call count: {info.get('count', 0)}")
import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    // 環境変数を設定していない場合は、次の行を Model Studio の API キーに置き換えます: apiKey: "sk-xxx",
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 次の URL は、シンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
});

async function main() {
    const response = await openai.responses.create({
        model: "qwen3.8-max",
        input: [
            {
                role: "user",
                content: [
                    { type: "input_text", text: "Find landscape images with a style similar to this one" },
                    // image_url を実際の公開画像 URL に置き換えます
                    { type: "input_image", image_url: "https://img.alicdn.com/imgextra/i4/O1CN01YbrnSS1qtmsAkw0Ud_!!6000000005554-2-tps-788-450.png" }
                ]
            }
        ],
        tools: [
            { type: "image_search" }
        ]
    });

    // 出力を走査して各ステップを表示します
    for (const item of response.output) {
        if (item.type === "image_search_call") {
            console.log(`[Tool Call] Search by image (status: ${item.status})`);
            // 検索された画像のリストを解析して表示します
            if (item.output) {
                const images = JSON.parse(item.output);
                console.log(`  Found ${images.length} images:`);
                images.slice(0, 5).forEach(img => {
                    console.log(`  [${img.index}] ${img.title}`);
                    console.log(`      ${img.url}`);
                });
                if (images.length > 5) {
                    console.log(`  ... ${images.length} images in total`);
                }
            }
        } else if (item.type === "message") {
            console.log(`\n[Model Response]`);
            console.log(response.output_text);
        }
    }

    // トークン使用量とツール呼び出しの統計を表示します
    console.log(`\n[Token Usage] Input: ${response.usage.input_tokens}, Output: ${response.usage.output_tokens}, Total: ${response.usage.total_tokens}`);
    if (response.usage && response.usage.x_tools) {
        for (const [toolName, info] of Object.entries(response.usage.x_tools)) {
            console.log(`[Tool Statistics] ${toolName} call count: ${info.count || 0}`);
        }
    }
}

main();
# 次の URL は、シンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.8-max",
    "input": [
        {
            "role": "user",
            "content": [
                {"type": "input_text", "text": "Find landscape images with a style similar to this one"},
                {"type": "input_image", "image_url": "https://img.alicdn.com/imgextra/i4/O1CN01YbrnSS1qtmsAkw0Ud_!!6000000005554-2-tps-788-450.png"}
            ]
        }
    ],
    "tools": [
        {"type": "image_search"}
    ]
}'

コードを実行すると、次のようなレスポンスが返されます:

[Tool Call] Search by image (status: completed)
  Found 2 images:
  [1] QingMing Festival Holiday Notice 2024
      https://www.healthcabin.net/blog/wp-content/uploads/2024/04/QingMing-Festival-Holiday-Notice-2024.jpg
  [2] Serene Asian Landscape Stone Bridge Reflecting in Misty Water
      https://thumbs.dreamstime.com/b/serene-asian-landscape-stone-bridge-reflecting-misty-water-tranquil-illustration-traditional-arch-spanning-lake-style-376972039.jpg

[Model Response]
OK. I have found several landscape images with a similar style.

These images all display the artistic conception of typical Chinese ink wash paintings or traditional landscape paintings, and they share the following common points:
*   **Traditional architecture**: such as pavilions, towers, and arch bridges.
*   **Natural elements**: such as distant mountains, lakes, weeping willows, and lotus flowers.
*   **Artistic style**: uses elegant colors and soft lines to create a quiet and serene atmosphere.

...

[Token Usage] Input: 2753, Output: 181, Total: 2934
[Tool Statistics] image_search call count: 1

ストリーミング出力

画像検索ツールは処理に時間がかかります。ストリーミング出力を有効にすると、中間結果をリアルタイムで取得できます。

import os
import json
from openai import OpenAI

client = OpenAI(
    # 環境変数を設定していない場合は、次の行を Model Studio の API キーに置き換えます: api_key="sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # 次の URL は、シンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)

input_content = [
    {"type": "input_text", "text": "Find landscape images with a style similar to this one"},
    # image_url を実際の公開画像 URL に置き換えます
    {"type": "input_image", "image_url": "https://img.alicdn.com/imgextra/i4/O1CN01YbrnSS1qtmsAkw0Ud_!!6000000005554-2-tps-788-450.png"}
]

stream = client.responses.create(
    model="qwen3.8-max",
    input=[{"role": "user", "content": input_content}],
    tools=[{"type": "image_search"}],
    stream=True
)

for event in stream:
    # ツール呼び出し開始
    if event.type == "response.output_item.added":
        if event.item.type == "image_search_call":
            print("[Tool Call] Searching by image...")
    # ツール呼び出し完了。検索された画像のリストを解析して表示します。
    elif event.type == "response.output_item.done":
        if event.item.type == "image_search_call":
            print(f"[Tool Call] Search by image complete (status: {event.item.status})")
            if event.item.output:
                images = json.loads(event.item.output)
                print(f"  Found {len(images)} images:")
                for img in images[:5]:  # 最初の 5 枚の画像を表示します
                    print(f"  [{img['index']}] {img['title']}")
                    print(f"      {img['url']}")
                if len(images) > 5:
                    print(f"  ... {len(images)} images in total")
    # モデルレスポンス開始
    elif event.type == "response.content_part.added":
        print(f"\n[Model Response]")
    # ストリーミングテキスト出力
    elif event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)
    # レスポンス完了。使用量を出力します。
    elif event.type == "response.completed":
        usage = event.response.usage
        print(f"\n\n[Token Usage] Input: {usage.input_tokens}, Output: {usage.output_tokens}, Total: {usage.total_tokens}")
        if hasattr(usage, 'x_tools') and usage.x_tools:
            for tool_name, info in usage.x_tools.items():
                print(f"[Tool Statistics] {tool_name} call count: {info.get('count', 0)}")
import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    // 環境変数を設定していない場合は、次の行を Model Studio の API キーに置き換えます: apiKey: "sk-xxx",
    apiKey: process.env.DASHSCOPE_API_KEY,
    // 次の URL は、シンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
});

async function main() {
    const stream = await openai.responses.create({
        model: "qwen3.8-max",
        input: [
            {
                role: "user",
                content: [
                    { type: "input_text", text: "Find landscape images with a style similar to this one" },
                    // image_url を実際の公開画像 URL に置き換えます
                    { type: "input_image", image_url: "https://img.alicdn.com/imgextra/i4/O1CN01YbrnSS1qtmsAkw0Ud_!!6000000005554-2-tps-788-450.png" }
                ]
            }
        ],
        tools: [{ type: "image_search" }],
        stream: true
    });

    for await (const event of stream) {
        // ツール呼び出し開始
        if (event.type === "response.output_item.added") {
            if (event.item.type === "image_search_call") {
                console.log("[Tool Call] Searching by image...");
            }
        }
        // ツール呼び出し完了。検索された画像のリストを解析して表示します。
        else if (event.type === "response.output_item.done") {
            if (event.item && event.item.type === "image_search_call") {
                console.log(`[Tool Call] Search by image complete (status: ${event.item.status})`);
                if (event.item.output) {
                    const images = JSON.parse(event.item.output);
                    console.log(`  Found ${images.length} images:`);
                    images.slice(0, 5).forEach(img => {
                        console.log(`  [${img.index}] ${img.title}`);
                        console.log(`      ${img.url}`);
                    });
                    if (images.length > 5) {
                        console.log(`  ... ${images.length} images in total`);
                    }
                }
            }
        }
        // モデルレスポンス開始
        else if (event.type === "response.content_part.added") {
            console.log(`\n[Model Response]`);
        }
        // ストリーミングテキスト出力
        else if (event.type === "response.output_text.delta") {
            process.stdout.write(event.delta);
        }
        // レスポンス完了。使用量を出力します。
        else if (event.type === "response.completed") {
            const usage = event.response.usage;
            console.log(`\n\n[Token Usage] Input: ${usage.input_tokens}, Output: ${usage.output_tokens}, Total: ${usage.total_tokens}`);
            if (usage && usage.x_tools) {
                for (const [toolName, info] of Object.entries(usage.x_tools)) {
                    console.log(`[Tool Statistics] ${toolName} call count: ${info.count || 0}`);
                }
            }
        }
    }
}

main();
# 次の URL は、シンガポールリージョン用です。{WorkspaceId} を実際のワークスペース ID に置き換えてください。URL はリージョンによって異なります。
curl -X POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.8-max",
    "input": [
        {
            "role": "user",
            "content": [
                {"type": "input_text", "text": "Find landscape images with a style similar to this one"},
                {"type": "input_image", "image_url": "https://img.alicdn.com/imgextra/i4/O1CN01YbrnSS1qtmsAkw0Ud_!!6000000005554-2-tps-788-450.png"}
            ]
        }
    ],
    "tools": [
        {"type": "image_search"}
    ],
    "stream": true
}'

コードを実行すると、次のようなレスポンスが返されます:

[Tool Call] Searching by image...
[Tool Call] Search by image complete (status: completed)
  Found 3 images:
  [1] QingMing Festival Holiday Notice 2024
      https://www.healthcabin.net/blog/wp-content/uploads/2024/04/QingMing-Festival-Holiday-Notice-2024.jpg
  [2] Serene Asian Landscape Stone Bridge Reflecting in Misty Water
      https://thumbs.dreamstime.com/b/serene-asian-landscape-stone-bridge-reflecting-misty-water-...
  [3] ...

[Model Response]
OK. I have found several landscape images with a similar style. These images all display the style of typical Chinese ink wash or fine-brush paintings...

[Token Usage] Input: 5339, Output: 164, Total: 5503
[Tool Statistics] image_search call count: 1

課金

課金には、以下の項目が含まれます:

  • モデル呼び出し料金: 画像検索の結果はプロンプトに追加されます。これにより、モデルの入力トークン数が増加します。料金は、モデルの標準レートに基づいて請求されます。料金の詳細については、「Model Studio」コンソールをご参照ください。
  • ツール呼び出し料金: 1,000 コールごとに課金されます。 シンガポールリージョンでのデプロイメント料金は $8.00 ですが、華北 2 (北京) でのデプロイメント料金は $6.881 です。

よくある質問

Q: サポートされている画像形式と入力方法

A: 詳細については、「画像の制限」および「ファイルの入力方法」をご参照ください。

OpenAI SDK は、ローカルファイルパスの受け渡しをサポートしていません。

Q: 渡すことができる画像の数

A: 渡すことができる画像の数は、モデルの最大入力長によって制限されます。画像とテキストの両方の合計トークン数が、モデルがサポートする最大値を超えないようにする必要があります。モデルは 1 回の呼び出しで 1 枚の画像のみを検索しますが、複数回呼び出すことで複数の画像を処理できます。

モデルは検索する画像の数を決定します。

Q: 返される検索画像の数

A: 返す画像の数はモデルが決定します。数量は固定されていませんが、最大で 100 枚です。