All Products
Search
Document Center

Alibaba Cloud Model Studio:Pencarian teks-ke-gambar

Last Updated:Jun 18, 2026

Alat pencarian teks-ke-gambar memungkinkan model mencari gambar yang relevan di Internet berdasarkan deskripsi teks, lalu menjelaskan konten gambar dan melakukan inferensi. Fitur ini berguna untuk skenario seperti tanya jawab visual dan rekomendasi gambar.

Penggunaan

Anda dapat memanggil fitur pencarian teks-ke-gambar melalui Responses API dengan menambahkan alat web_search_image ke parameter tools.

# Impor dependensi dan buat klien...
response = client.responses.create(
    model="qwen3.7-plus",
    input="Find a tech-style background image for a PPT cover",
    tools=[{"type": "web_search_image"}]
)

print(response.output_text)

Model yang didukung

Model yang direkomendasikan

Untuk hasil pemanggilan alat terbaik, gunakan model berikut:

Qwen-Plus: seri Qwen3.7-Plus, seri Qwen3.6-Plus, seri Qwen3.5-Plus

Qwen-Max: qwen3.7-max-2026-06-08

Model lainnya

Model berikut juga mendukung pemanggilan alat ini, tetapi performanya tidak sebaik model yang direkomendasikan.

  • Qwen-Flash: seri Qwen3.6-Flash, seri Qwen3.5-Flash

  • Seri open-source Qwen3.6 (kecuali qwen3.6-27b)

  • Seri open source Qwen3.5

Alat ini hanya dapat dipanggil melalui Responses API.

Mulai

Jalankan kode berikut untuk memanggil alat pencarian teks-ke-gambar menggunakan Responses API. Kode ini mencari gambar di Internet berdasarkan deskripsi teks.

Anda harus mendapatkan Kunci API dan mengonfigurasi Kunci API sebagai Variabel lingkungan.
import os
import json
from openai import OpenAI

client = OpenAI(
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan api_key="sk-xxx" (tidak disarankan), menggunakan Kunci API Model Studio Anda.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # URL berikut untuk wilayah Singapura. Saat memanggil, ganti WorkspaceId dengan ID ruang kerja aktual Anda. URL bervariasi berdasarkan wilayah.
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)

response = client.responses.create(
    model="qwen3.7-plus",
    input="Find a tech-style background image for a PPT cover",
    tools=[
        {
            "type": "web_search_image"
        }
    ]
)

for item in response.output:
    if item.type == "web_search_image_call":
        print(f"[Tool Call] Text-to-image search (status: {item.status})")
        # Urai dan tampilkan daftar gambar yang ditemukan
        if item.output:
            images = json.loads(item.output)
            print(f"  Found {len(images)} images:")
            for img in images[:5]:  # Tampilkan 5 gambar pertama
                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)

# Tampilkan penggunaan token dan statistik pemanggilan alat
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} calls: {info.get('count', 0)}")
import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan apiKey: "sk-xxx", menggunakan Kunci API Model Studio Anda.
    apiKey: process.env.DASHSCOPE_API_KEY,
    // URL berikut untuk wilayah Singapura. Saat memanggil, ganti WorkspaceId dengan ID ruang kerja aktual Anda. URL bervariasi berdasarkan wilayah.
    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: "Find a tech-style background image for a PPT cover",
        tools: [
            { type: "web_search_image" }
        ]
    });

    for (const item of response.output) {
        if (item.type === "web_search_image_call") {
            console.log(`[Tool Call] Text-to-image search (status: ${item.status})`);
            // Urai dan tampilkan daftar gambar yang ditemukan
            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);
        }
    }

    // Tampilkan penggunaan token dan statistik pemanggilan alat
    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} calls: ${info.count || 0}`);
        }
    }
}

main();
# URL berikut untuk wilayah Singapura. Saat memanggil, ganti WorkspaceId dengan ID ruang kerja aktual Anda. URL bervariasi berdasarkan wilayah.
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": "Find a tech-style background image for a PPT cover",
    "tools": [
        {"type": "web_search_image"}
    ]
}'

Kode di atas mengembalikan respons berikut:

[Tool Call] Text-to-image search (status: completed)
  Found 30 images:
  [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 images in total

[Model Response]
Here are a few tech-style background images that are perfect for a PPT cover. You can choose one based on your specific theme:

**1. Classic blue circuit board and chip style**
Suitable for topics: Hardware, chips, electronic engineering, low-level technology.
![Technology Background](https://www.slideegg.com/image/catalog/89734-powerpoint-background-design-technology.png)

**2. Abstract particles and network connection style**
Suitable for topics: Big data, artificial intelligence, network security, cloud computing.
![Technology Background](https://img.freepik.com/free-vector/gradient-technology-futuristic-background_23-2149115239.jpg)

...

[Token Usage] Input: 4326, Output: 645, Total: 4971
[Tool Statistics] web_search_image calls: 1

Keluaran streaming

Alat pencarian teks-ke-gambar dapat berjalan lambat. Anda dapat mengaktifkan keluaran streaming untuk menerima hasil antara secara real time.

import os
import json
from openai import OpenAI

client = OpenAI(
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan api_key="sk-xxx" (tidak disarankan), menggunakan Kunci API Model Studio Anda.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # URL berikut untuk wilayah Singapura. Saat memanggil, ganti WorkspaceId dengan ID ruang kerja aktual Anda. URL bervariasi berdasarkan wilayah.
    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
)

stream = client.responses.create(
    model="qwen3.7-plus",
    input="Find a tech-style background image for a PPT cover",
    tools=[{"type": "web_search_image"}],
    stream=True
)

for event in stream:
    # Pemanggilan alat dimulai
    if event.type == "response.output_item.added":
        if event.item.type == "web_search_image_call":
            print("[Tool Call] Text-to-image search in progress...")
    # Pemanggilan alat selesai. Urai dan tampilkan daftar gambar yang ditemukan.
    elif event.type == "response.output_item.done":
        if event.item.type == "web_search_image_call":
            print(f"[Tool Call] Text-to-image search 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]:  # Tampilkan 5 gambar pertama
                    print(f"  [{img['index']}] {img['title']}")
                    print(f"      {img['url']}")
                if len(images) > 5:
                    print(f"  ... {len(images)} images in total")
    # Respons model dimulai
    elif event.type == "response.content_part.added":
        print(f"\n[Model Response]")
    # Keluaran teks streaming
    elif event.type == "response.output_text.delta":
        print(event.delta, end="", flush=True)
    # Respons selesai. Tampilkan penggunaan.
    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} calls: {info.get('count', 0)}")
import OpenAI from "openai";
import process from 'process';

const openai = new OpenAI({
    // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan apiKey: "sk-xxx", menggunakan Kunci API Model Studio Anda.
    apiKey: process.env.DASHSCOPE_API_KEY,
    // URL berikut untuk wilayah Singapura. Saat memanggil, ganti WorkspaceId dengan ID ruang kerja aktual Anda. URL bervariasi berdasarkan wilayah.
    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: "Find a tech-style background image for a PPT cover",
        tools: [{ type: "web_search_image" }],
        stream: true
    });

    for await (const event of stream) {
        // Pemanggilan alat dimulai
        if (event.type === "response.output_item.added") {
            if (event.item && event.item.type === "web_search_image_call") {
                console.log("[Tool Call] Text-to-image search in progress...");
            }
        }
        // Pemanggilan alat selesai. Urai dan tampilkan daftar gambar yang ditemukan.
        else if (event.type === "response.output_item.done") {
            if (event.item && event.item.type === "web_search_image_call") {
                console.log(`[Tool Call] Text-to-image search 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`);
                    }
                }
            }
        }
        // Respons model dimulai
        else if (event.type === "response.content_part.added") {
            console.log(`\n[Model Response]`);
        }
        // Keluaran teks streaming
        else if (event.type === "response.output_text.delta") {
            process.stdout.write(event.delta);
        }
        // Respons selesai. Tampilkan penggunaan.
        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} calls: ${info.count || 0}`);
                }
            }
        }
    }
}

main();
# URL berikut untuk wilayah Singapura. Saat memanggil, ganti WorkspaceId dengan ID ruang kerja aktual Anda. URL bervariasi berdasarkan wilayah.
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": "Find a tech-style background image for a PPT cover",
    "tools": [
        {"type": "web_search_image"}
    ],
    "stream": true
}'

Kode di atas mengembalikan keluaran berikut:

[Tool Call] Text-to-image search in progress...
[Tool Call] Text-to-image search complete (status: completed)
  Found 30 images:
  [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 images in total

[Model Response]
Here are a few tech-style background images that are perfect for a PPT cover. You can choose one based on your specific theme:

**1. Minimalist network connector style (suitable for big data, connectivity, and communication topics)**
This image has a dark blue background with simple node connectors in the corner and a lot of white space in the middle...
![Technology Background](https://slidechef.net/wp-content/uploads/2023/11/TECHNOLOGY-BACKGROUND.jpg)

**2. Hardcore circuit and chip style (suitable for artificial intelligence, hardware, and low-level technology topics)**
The left side features complex circuit board textures and a HUD-like ring design...
![Circuit Technology Background](https://www.slideegg.com/image/catalog/89734-powerpoint-background-design-technology.png)

...

[Token Usage] Input: 7180, Output: 558, Total: 7738
[Tool Statistics] web_search_image calls: 1

Penagihan

Penagihan mencakup hal-hal berikut:

  • Biaya pemanggilan model: Hasil pencarian gambar ditambahkan ke prompt, sehingga meningkatkan jumlah token input untuk model. Anda dikenai biaya berdasarkan harga standar model tersebut. Untuk detail harga, lihat Konsol Model Studio.

  • Biaya pemanggilan alat: Biaya setiap 1.000 kali pemanggilan adalah: $8 untuk penerapan internasional, dan $3,44 untuk penerapan di Tiongkok daratan dan global.