文搜圖工具使模型能夠根據文本描述從互連網搜尋相關圖片,並基於圖片內容進行描述和推理,適用於可視化問答、配圖推薦等情境。
使用方式
文搜圖功能通過 Responses API 呼叫,在 tools 中添加 web_search_image 工具。
# 匯入依賴與建立用戶端...
response = client.responses.create(
model="qwen3.5-plus",
input="幫我找一張適合做 PPT 封面的科技感背景圖",
tools=[{"type": "web_search_image"}]
)
print(response.output_text)支援的模型
千問 Plus:
qwen3.5-plus、qwen3.5-plus-2026-02-15千問 Flash:
qwen3.5-flash、qwen3.5-flash-2026-02-23千問開源:
qwen3.5-397b-a17b、qwen3.5-122b-a10b、qwen3.5-27b、qwen3.5-35b-a3b
僅支援通過 Responses API 呼叫。
快速開始
運行以下代碼,通過 Responses API 呼叫文搜圖工具,根據文本描述搜尋互連網圖片。
需要已擷取API Key並配置API Key到環境變數(準備下線,併入配置 API Key)。
import os
import json
from openai import OpenAI
client = OpenAI(
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx"(不建議),
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)
response = client.responses.create(
model="qwen3.5-plus",
input="幫我找一張適合做 PPT 封面的科技感背景圖",
tools=[
{
"type": "web_search_image"
}
]
)
for item in response.output:
if item.type == "web_search_image_call":
print(f"[工具調用] 文搜圖 (status: {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)
# 展示 Token 用量和工具調用統計
print(f"\n[Token 用量] 輸入: {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({
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey: "sk-xxx",
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});
async function main() {
const response = await openai.responses.create({
model: "qwen3.5-plus",
input: "幫我找一張適合做 PPT 封面的科技感背景圖",
tools: [
{ type: "web_search_image" }
]
});
for (const item of response.output) {
if (item.type === "web_search_image_call") {
console.log(`[工具調用] 文搜圖 (status: ${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);
}
}
// 展示 Token 用量和工具調用統計
console.log(`\n[Token 用量] 輸入: ${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();curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-plus",
"input": "幫我找一張適合做 PPT 封面的科技感背景圖",
"tools": [
{"type": "web_search_image"}
]
}'運行以上代碼可擷取如下回複:
[工具調用] 文搜圖 (status: completed)
搜尋到 30 張圖片:
[1] Best Free Information Technology Background S Google Slides Themes ...
https://image.slidesdocs.com/responsive-images/slides/0-technology-line-network-information-training-courseware-powerpoint-background_17825ea41f__960_540.jpg
[2] Data Technology Blue Abstract Business Glow Powerpoint Background ...
https://image.slidesdocs.com/responsive-images/background/data-technology-blue-abstract-business-glow-powerpoint-background_e667bfafcb__960_540.jpg
[3] PPT Technology Style Background Template Banner Backgrounds | PSD ...
https://img.pikbest.com/backgrounds/20190418/ppt-technology-style-background-template-banner_1889599.jpg!bw700
[4] Download Now! PowerPoint Background Design Technology
https://www.slideegg.com/image/catalog/89734-powerpoint-background-design-technology.png
[5] Powerpoint Template Technology Images ...
https://t4.ftcdn.net/jpg/07/53/21/13/360_F_753211329_cVkWkZdxs9tNEoS5q2d8ZH362YQnAH0p.jpg
... 共 30 張圖片
[模型回複]
為您找到幾張非常適合做PPT封面的科技感背景圖,您可以根據具體的主題風格進行選擇:
**1. 經典藍色電路板與晶片風格**
適合主題:硬體、晶片、電子工程、底層技術。

**2. 抽象粒子與網路連接風格**
適合主題:巨量資料、人工智慧、網路安全、雲端運算。

...
[Token 用量] 輸入: 4326, 輸出: 645, 合計: 4971
[工具統計] web_search_image 調用次數: 1流式輸出
文搜圖工具運行較慢,建議啟用流式輸出,即時擷取中間過程的輸出結果。
import os
import json
from openai import OpenAI
client = OpenAI(
# 若沒有配置環境變數,請用百鍊API Key將下行替換為:api_key="sk-xxx",
api_key=os.getenv("DASHSCOPE_API_KEY"),
base_url="https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
)
stream = client.responses.create(
model="qwen3.5-plus",
input="幫我找一張適合做 PPT 封面的科技感背景圖",
tools=[{"type": "web_search_image"}],
stream=True
)
for event in stream:
# 工具調用開始
if event.type == "response.output_item.added":
if event.item.type == "web_search_image_call":
print("[工具調用] 文搜圖搜尋中...")
# 工具調用完成,解析並展示搜尋到的圖片列表
elif event.type == "response.output_item.done":
if event.item.type == "web_search_image_call":
print(f"[工具調用] 文搜圖完成 (status: {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[Token 用量] 輸入: {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({
// 若沒有配置環境變數,請用百鍊API Key將下行替換為:apiKey: "sk-xxx",
apiKey: process.env.DASHSCOPE_API_KEY,
baseURL: "https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1"
});
async function main() {
const stream = await openai.responses.create({
model: "qwen3.5-plus",
input: "幫我找一張適合做 PPT 封面的科技感背景圖",
tools: [{ type: "web_search_image" }],
stream: true
});
for await (const event of stream) {
// 工具調用開始
if (event.type === "response.output_item.added") {
if (event.item && event.item.type === "web_search_image_call") {
console.log("[工具調用] 文搜圖搜尋中...");
}
}
// 工具調用完成,解析並展示搜尋到的圖片列表
else if (event.type === "response.output_item.done") {
if (event.item && event.item.type === "web_search_image_call") {
console.log(`[工具調用] 文搜圖完成 (status: ${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[Token 用量] 輸入: ${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();curl -X POST https://dashscope-intl.aliyuncs.com/api/v2/apps/protocols/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-plus",
"input": "幫我找一張適合做 PPT 封面的科技感背景圖",
"tools": [
{"type": "web_search_image"}
],
"stream": true
}'運行以上代碼可擷取如下輸出:
[工具調用] 文搜圖搜尋中...
[工具調用] 文搜圖完成 (status: completed)
搜尋到 30 張圖片:
[1] Free Technology Background PowerPoint & Google Slides Themes
https://slidechef.net/wp-content/uploads/2023/11/TECHNOLOGY-BACKGROUND.jpg
[2] Best Free Information Technology Background S Google Slides Themes ...
https://image.slidesdocs.com/responsive-images/slides/0-technology-line-network-information-training-courseware-powerpoint-background_17825ea41f__960_540.jpg
[3] PPT Technology Style Background Template Banner Backgrounds | PSD ...
https://img.pikbest.com/backgrounds/20190418/ppt-technology-style-background-template-banner_1889599.jpg!bw700
[4] Download Now! PowerPoint Background Design Technology
https://www.slideegg.com/image/catalog/89734-powerpoint-background-design-technology.png
[5] Powerpoint Template Technology Images ...
https://t4.ftcdn.net/jpg/07/53/21/13/360_F_753211329_cVkWkZdxs9tNEoS5q2d8ZH362YQnAH0p.jpg
... 共 30 張圖片
[模型回複]
為您找到幾張非常適合做PPT封面的科技感背景圖,您可以根據具體的主題風格進行選擇:
**1. 極簡網路連線風(適合巨量資料、串連、通訊主題)**
這張圖以深藍色為底,角落有簡潔的節點連線,中間留白非常多...

**2. 硬核電路與晶片風(適合人工智慧、硬體、底層技術主題)**
左側有複雜的電路板紋理和類似HUD的圓環設計...

...
[Token 用量] 輸入: 7180, 輸出: 558, 合計: 7738
[工具統計] web_search_image 調用次數: 1計費說明
計費涉及以下方面:
模型調用費用:圖片搜尋的結果資訊會拼接到提示詞中,增加模型的輸入 Token,按照模型的標準價格計費。價格詳情請參考模型列表。
工具調用費用:每1000次調用收費:國際為$8,中國內地為$3.440461。