画像検索ツールを使用すると、モデルは入力画像に基づいて、視覚的に類似した画像をインターネットで検索できます。その後、モデルは検索結果を分析し、推論を行うことができます。この機能は、類似商品の検索や視覚コンテンツの出所の追跡などのシナリオで役立ちます。
使用方法
画像検索機能は Responses API で呼び出すことができます。tools パラメーターに image_search ツールを追加し、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.7-plus",
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.7-max-2026-06-08
その他のモデル
次のモデルもこのツールをサポートしていますが、パフォーマンスは推奨モデルほど高くありません。
-
Qwen-Flash: Qwen3.6-Flash シリーズ、Qwen3.5-Flash シリーズ
-
Qwen3.6 オープンソースシリーズ (qwen3.6-27b を除く)
-
Qwen3.5 オープンソースシリーズ
この機能は 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.7-plus",
input=[{"role": "user", "content": input_content}],
tools=[
{
"type": "image_search"
}
]
)
# 出力を走査して各ステップを表示します
for item in response.output:
if item.type == "image_search_call":
print(f"[ツールコール] 画像検索 (ステータス: {item.status})")
# 検索された画像リストを解析して表示します
if item.output:
images = json.loads(item.output)
print(f" {len(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)} 件の画像")
elif item.type == "message":
print(f"\n[モデルレスポンス]")
print(response.output_text)
# トークン使用量とツールコール統計を表示します
print(f"\n[トークン使用量] 入力: {response.usage.input_tokens}, 出力: {response.usage.output_tokens}, 合計: {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_name} 呼び出し回数: {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.7-plus",
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(`[ツールコール] 画像検索 (ステータス: ${item.status})`);
// 検索された画像リストを解析して表示します
if (item.output) {
const images = JSON.parse(item.output);
console.log(` ${images.length} 件の画像が見つかりました:`);
images.slice(0, 5).forEach(img => {
console.log(` [${img.index}] ${img.title}`);
console.log(` ${img.url}`);
});
if (images.length > 5) {
console.log(` ... 合計 ${images.length} 件の画像`);
}
}
} else if (item.type === "message") {
console.log(`\n[モデルレスポンス]`);
console.log(response.output_text);
}
}
// トークン使用量とツールコール統計を表示します
console.log(`\n[トークン使用量] 入力: ${response.usage.input_tokens}, 出力: ${response.usage.output_tokens}, 合計: ${response.usage.total_tokens}`);
if (response.usage && response.usage.x_tools) {
for (const [toolName, info] of Object.entries(response.usage.x_tools)) {
console.log(`[ツール統計] ${toolName} 呼び出し回数: ${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.7-plus",
"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"}
]
}'コードを実行すると、次のようなレスポンスが返されます。
[ツールコール] 画像検索 (ステータス: completed)
2 件の画像が見つかりました:
[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
[モデルレスポンス]
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.
...
[トークン使用量] 入力: 2753, 出力: 181, 合計: 2934
[ツール統計] image_search 呼び出し回数: 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.7-plus",
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("[ツールコール] 画像を検索しています...")
# ツールコール完了。検索された画像リストを解析して表示します。
elif event.type == "response.output_item.done":
if event.item.type == "image_search_call":
print(f"[ツールコール] 画像検索完了 (ステータス: {event.item.status})")
if event.item.output:
images = json.loads(event.item.output)
print(f" {len(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)} 件の画像")
# モデルレスポンス開始
elif event.type == "response.content_part.added":
print(f"\n[モデルレスポンス]")
# ストリーミングテキスト出力
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[トークン使用量] 入力: {usage.input_tokens}, 出力: {usage.output_tokens}, 合計: {usage.total_tokens}")
if hasattr(usage, 'x_tools') and usage.x_tools:
for tool_name, info in usage.x_tools.items():
print(f"[ツール統計] {tool_name} 呼び出し回数: {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.7-plus",
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("[ツールコール] 画像を検索しています...");
}
}
// ツールコール完了。検索された画像リストを解析して表示します。
else if (event.type === "response.output_item.done") {
if (event.item && event.item.type === "image_search_call") {
console.log(`[ツールコール] 画像検索完了 (ステータス: ${event.item.status})`);
if (event.item.output) {
const images = JSON.parse(event.item.output);
console.log(` ${images.length} 件の画像が見つかりました:`);
images.slice(0, 5).forEach(img => {
console.log(` [${img.index}] ${img.title}`);
console.log(` ${img.url}`);
});
if (images.length > 5) {
console.log(` ... 合計 ${images.length} 件の画像`);
}
}
}
}
// モデルレスポンス開始
else if (event.type === "response.content_part.added") {
console.log(`\n[モデルレスポンス]`);
}
// ストリーミングテキスト出力
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[トークン使用量] 入力: ${usage.input_tokens}, 出力: ${usage.output_tokens}, 合計: ${usage.total_tokens}`);
if (usage && usage.x_tools) {
for (const [toolName, info] of Object.entries(usage.x_tools)) {
console.log(`[ツール統計] ${toolName} 呼び出し回数: ${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.7-plus",
"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
}'コードを実行すると、次のようなレスポンスが返されます。
[ツールコール] 画像を検索しています...
[ツールコール] 画像検索完了 (ステータス: completed)
3 件の画像が見つかりました:
[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] ...
[モデルレスポンス]
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...
[トークン使用量] 入力: 5339, 出力: 164, 合計: 5503
[ツール統計] image_search 呼び出し回数: 1
料金
課金対象は次のとおりです。
-
モデル呼び出し料金:画像検索の結果はプロンプトに追加されます。これにより、モデルの入力トークン数が増加します。モデルの標準レートに基づいて課金されます。料金の詳細については、Model Studio コンソールをご参照ください。
-
ツール呼び出し料金:1,000 回の呼び出しごとに課金されます。国際デプロイメントの料金は 8.00 ドルですが、中国本土およびグローバルでのデプロイメントの料金は 6.881 ドルです。
よくある質問
Q:サポートされている画像形式と入力方法は何ですか?
A:詳細については、画像の制限およびファイル入力方法をご参照ください。
OpenAI SDK は、ローカルファイルパスの受け渡しをサポートしていません。
Q:渡すことができる画像の数はいくつですか?
A:渡すことができる画像の数は、モデルの最大入力長によって制限されます。画像とテキストの両方の合計トークン数が、モデルがサポートする最大値を超えてはなりません。モデルは 1 回の呼び出しで 1 枚の画像のみを検索しますが、複数回呼び出すことで複数の画像を処理できます。
検索する画像の数はモデルが決定します。
Q:検索された画像はいくつ返りますか?
A:返される画像の数はモデルが決定します。枚数は固定されていませんが、最大で 100 枚です。