All Products
Search
Document Center

Alibaba Cloud Model Studio:Buat respons

Last Updated:Jun 30, 2026

Gunakan API Responses yang kompatibel dengan OpenAI untuk memanggil model Qwen. Topik ini menjelaskan parameter input dan output serta menyediakan contoh pemanggilan.

Keunggulan dibandingkan OpenAI Chat Completions API:

  • Alat bawaan: Hasilkan performa lebih baik pada tugas kompleks dengan alat bawaan seperti pencarian web, scraping web, interpreter kode, teks-ke-gambar, gambar-ke-gambar, dan pencarian basis pengetahuan. Untuk informasi selengkapnya, lihat pemanggilan alat.

  • Input lebih fleksibel: Mendukung input berupa string langsung maupun array pesan dalam format chat.

  • Manajemen konteks yang disederhanakan: Hindari konstruksi manual array riwayat pesan dengan meneruskan previous_response_id dari respons terakhir.

  • Cache konteks yang praktis: Tambahkan x-dashscope-session-cache: enable ke header permintaan untuk mengaktifkan cache konteks percakapan secara otomatis di sisi server. Fitur ini mengurangi latensi inferensi dan biaya untuk percakapan multi-putaran tanpa perubahan kode. Untuk detailnya, lihat cache sesi.

Kompatibilitas dan keterbatasan

API ini kompatibel dengan OpenAI untuk mengurangi biaya migrasi pengembang, tetapi berbeda dalam parameter, fungsionalitas, dan perilakunya.

Prinsip Inti: Hanya parameter yang secara eksplisit tercantum dalam dokumen ini yang diproses. Parameter OpenAI yang tidak disebutkan akan diabaikan.

Perbedaan utama berikut akan membantu Anda beradaptasi dengan cepat:

  • Parameter yang Tidak Didukung: API ini tidak mendukung beberapa parameter API OpenAI, seperti parameter eksekusi asinkron background. API saat ini hanya mendukung panggilan sinkron.

  • Kontrol Upaya Reasoning: Gunakan parameter reasoning.effort untuk mengontrol upaya reasoning model. Untuk detail penggunaan, lihat deskripsi parameter ini.

Singapore

base_url untuk konfigurasi pemanggilan SDK adalah https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1.

Titik akhir permintaan HTTP: POST https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/responses

China (Beijing)

base_url untuk konfigurasi pemanggilan SDK: https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1

Titik akhir permintaan HTTP: POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses

AS (Virginia)

Konfigurasi pemanggilan SDK base_url: https://dashscope-us.aliyuncs.com/compatible-mode/v1

Titik akhir permintaan HTTP: POST https://dashscope-us.aliyuncs.com/compatible-mode/v1/responses

Jerman (Frankfurt)

Konfigurasi pemanggilan SDK base_url: https://{<u>WorkspaceId</u>}<u>.eu-central-1.maas.aliyuncs</u>.com/compatible-mode/v1/responses

Titik akhir permintaan HTTP: POST https://{WorkspaceId}.eu-central-1.maas.aliyuncs.com/compatible-mode/v1/responses

Tiongkok (Hong Kong)

Konfigurasi pemanggilan SDK base_url: https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1

Titik akhir permintaan HTTP: POST https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com/compatible-mode/v1/responses

Jepang (Tokyo)

Konfigurasi pemanggilan SDK base_url: https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1

Titik akhir permintaan HTTP: POST https://{WorkspaceId}.ap-northeast-1.maas.aliyuncs.com/compatible-mode/v1/responses

Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya.

Penting

Model Studio telah merilis domain khusus ruang kerja untuk wilayah Tiongkok (Beijing), Singapura, dan Tiongkok (Hong Kong). Domain khusus baru ini memberikan performa unggul dan stabilitas lebih tinggi untuk permintaan inferensi. Kami merekomendasikan migrasi ke domain baru:

  • Tiongkok (Beijing): dari https://dashscope.aliyuncs.com ke https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com

  • Singapura: dari https://dashscope-intl.aliyuncs.com ke https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com

  • Tiongkok (Hong Kong): dari https://cn-hongkong.dashscope.aliyuncs.com ke https://{WorkspaceId}.cn-hongkong.maas.aliyuncs.com

{WorkspaceId} adalah ID ruang kerja Anda, yang dapat ditemukan di halaman Detail Ruang Kerja di Konsol Model Studio. Domain lama tetap berfungsi penuh.

Penting

Jalur URL lama /api/v2/apps/protocols/compatible-mode/v1/responses untuk API Responses yang kompatibel dengan OpenAI akan segera ditinggalkan. Harap migrasi ke jalur baru /compatible-mode/v1/responses sesegera mungkin.

Badan permintaan

Panggilan dasar

Python

import os
from openai import OpenAI

client = OpenAI(
    # Jika variabel lingkungan tidak diatur, ganti dengan: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)

response = client.responses.create(
    model="qwen3.7-plus",
    input="What can you do?"
)

# Dapatkan respons model
print(response.output_text)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    // Jika variabel lingkungan tidak diatur, ganti dengan: apiKey: "sk-xxx"
    apiKey: process.env.DASHSCOPE_API_KEY,
    // Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda 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: "What can you do?"
    });

    // Dapatkan respons model
    console.log(response.output_text);
}

main();

curl

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": "What can you do?"
}'

Keluaran streaming

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)

stream = client.responses.create(
    model="qwen3.7-plus",
    input="Briefly introduce artificial intelligence.",
    stream=True
)

print("Menerima keluaran streaming:")
for event in stream:
    if event.type == 'response.output_text.delta':
        print(event.delta, end='', flush=True)
    elif event.type == 'response.completed':
        print("\nStreaming selesai")
        print(f"Total token: {event.response.usage.total_tokens}")

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda 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: "Briefly introduce artificial intelligence.",
        stream: true
    });

    console.log("Menerima keluaran streaming:");
    for await (const event of stream) {
        if (event.type === 'response.output_text.delta') {
            process.stdout.write(event.delta);
        } else if (event.type === 'response.completed') {
            console.log("\nStreaming selesai");
            console.log(`Total token: ${event.response.usage.total_tokens}`);
        }
    }
}

main();

curl

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" \
--no-buffer \
-d '{
    "model": "qwen3.7-plus",
    "input": "Briefly introduce artificial intelligence.",
    "stream": true
}'

Percakapan multi-putaran

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)

# Putaran pertama
response1 = client.responses.create(
    model="qwen3.7-plus",
    input="My name is John. Please remember it."
)
print(f"Respons pertama: {response1.output_text}")

# Putaran kedua - gunakan previous_response_id untuk menghubungkan konteks. ID respons berlaku selama 7 hari.
response2 = client.responses.create(
    model="qwen3.7-plus",
    input="Do you remember my name?",
    previous_response_id=response1.id
)
print(f"Respons kedua: {response2.output_text}")

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1"
});

async function main() {
    // Putaran pertama
    const response1 = await openai.responses.create({
        model: "qwen3.7-plus",
        input: "My name is John. Please remember it."
    });
    console.log(`Respons pertama: ${response1.output_text}`);

    // Putaran kedua - gunakan previous_response_id untuk menghubungkan konteks. ID respons berlaku selama 7 hari.
    const response2 = await openai.responses.create({
        model: "qwen3.7-plus",
        input: "Do you remember my name?",
        previous_response_id: response1.id
    });
    console.log(`Respons kedua: ${response2.output_text}`);
}

main();

Alat bawaan

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda 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 the Alibaba Cloud official website and extract key information from its homepage.",
    # Untuk hasil terbaik, kami merekomendasikan mengaktifkan alat bawaan.
    tools=[
        {"type": "web_search"},
        {"type": "code_interpreter"},
        {"type": "web_extractor"}
    ],
)

# Hapus komentar baris berikut untuk melihat keluaran antara.
# print(response.output)
print(response.output_text)

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda 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 the Alibaba Cloud official website and extract key information from its homepage.",
        tools: [
            { type: "web_search" },
            { type: "code_interpreter" },
            { type: "web_extractor" }
        ]
    });

    for (const item of response.output) {
        if (item.type === "reasoning") {
            console.log("Model sedang berpikir...");
        } else if (item.type === "web_search_call") {
            console.log(`Kueri pencarian: ${item.action.query}`);
        } else if (item.type === "web_extractor_call") {
            console.log("Mengekstraksi konten web...");
        } else if (item.type === "message") {
            console.log(`Konten respons: ${item.content[0].text}`);
        }
    }
}

main();

curl

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 the Alibaba Cloud official website and extract key information from its homepage.",
    "tools": [
        {
            "type": "web_search"
        },
        {
            "type": "code_interpreter"
        },
        {
            "type": "web_extractor"
        }
    ]
}'

Pemanggilan fungsi

Python

from openai import OpenAI
import json
import os
import random

# Inisialisasi klien.
client = OpenAI(
    # Jika variabel lingkungan tidak diatur, ganti dengan: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
)
# Simulasikan pertanyaan pengguna.
USER_QUESTION = "What's the weather like in Beijing?"
# Definisikan daftar alat.
tools = [
    {
        "type": "function",
        "name": "get_current_weather",
        "description": "Useful for getting the weather in a specific city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "The city or district, such as Beijing or Hangzhou.",
                }
            },
            "required": ["location"],
        },
    }
]


# Simulasikan alat kueri cuaca.
def get_current_weather(arguments):
    weather_conditions = ["sunny", "cloudy", "rainy"]
    random_weather = random.choice(weather_conditions)
    location = arguments["location"]
    return f"Today in {location} it is {random_weather}."


# Bungkus fungsi respons model.
def get_response(input_data):
    response = client.responses.create(
        model="qwen3.7-plus",
        input=input_data,
        tools=tools,
    )
    return response


# Pertahankan konteks percakapan.
conversation = [{"role": "user", "content": USER_QUESTION}]

response = get_response(conversation)
function_calls = [item for item in response.output if item.type == "function_call"]
# Jika tidak diperlukan pemanggilan alat, keluarkan konten langsung.
if not function_calls:
    print(f"Respons asisten akhir: {response.output_text}")
else:
    # Masuk ke loop pemanggilan alat.
    while function_calls:
        for fc in function_calls:
            func_name = fc.name
            arguments = json.loads(fc.arguments)
            print(f"Memanggil alat [{func_name}] dengan argumen: {arguments}")
            # Eksekusi alat.
            tool_result = get_current_weather(arguments)
            print(f"Alat mengembalikan: {tool_result}")
            # Tambahkan pemanggilan alat dan hasilnya ke konteks sebagai pasangan.
            conversation.append(
                {
                    "type": "function_call",
                    "name": fc.name,
                    "arguments": fc.arguments,
                    "call_id": fc.call_id,
                }
            )
            conversation.append(
                {
                    "type": "function_call_output",
                    "call_id": fc.call_id,
                    "output": tool_result,
                }
            )
        # Panggil model lagi dengan konteks lengkap.
        response = get_response(conversation)
        function_calls = [
            item for item in response.output if item.type == "function_call"
        ]
    print(f"Respons asisten akhir: {response.output_text}")

Node.js

import OpenAI from "openai";

// Inisialisasi klien.
const openai = new OpenAI({
  // Jika variabel lingkungan tidak diatur, ganti dengan: apiKey: "sk-xxx"
  apiKey: process.env.DASHSCOPE_API_KEY,
  // Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.
  baseURL:
    "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
});

// Definisikan daftar alat.
const tools = [
  {
    type: "function",
    name: "get_current_weather",
    description: "Useful for getting the weather in a specific city.",
    parameters: {
      type: "object",
      properties: {
        location: {
          type: "string",
          description: "The city or district, such as Beijing or Hangzhou.",
        },
      },
      required: ["location"],
    },
  },
];

// Simulasikan alat kueri cuaca.
const getCurrentWeather = (args) => {
  const weatherConditions = ["sunny", "cloudy", "rainy"];
  const randomWeather =
    weatherConditions[Math.floor(Math.random() * weatherConditions.length)];
  const location = args.location;
  return `Today in ${location} it is ${randomWeather}.`;
};

// Bungkus fungsi respons model.
const getResponse = async (inputData) => {
  const response = await openai.responses.create({
    model: "qwen3.7-plus",
    input: inputData,
    tools: tools,
  });
  return response;
};

const main = async () => {
  const userQuestion = "What's the weather like in Beijing?";

  // Pertahankan konteks percakapan.
  const conversation = [{ role: "user", content: userQuestion }];

  let response = await getResponse(conversation);
  let functionCalls = response.output.filter(
    (item) => item.type === "function_call"
  );
  // Jika tidak diperlukan pemanggilan alat, keluarkan konten langsung.
  if (functionCalls.length === 0) {
    console.log(`Respons asisten akhir: ${response.output_text}`);
  } else {
    // Masuk ke loop pemanggilan alat.
    while (functionCalls.length > 0) {
      for (const fc of functionCalls) {
        const funcName = fc.name;
        const args = JSON.parse(fc.arguments);
        console.log(`Memanggil alat [${funcName}] dengan argumen:`, args);
        // Eksekusi alat.
        const toolResult = getCurrentWeather(args);
        console.log(`Alat mengembalikan: ${toolResult}`);
        // Tambahkan pemanggilan alat dan hasilnya ke konteks sebagai pasangan.
        conversation.push({
          type: "function_call",
          name: fc.name,
          arguments: fc.arguments,
          call_id: fc.call_id,
        });
        conversation.push({
          type: "function_call_output",
          call_id: fc.call_id,
          output: toolResult,
        });
      }
      // Panggil model lagi dengan konteks lengkap.
      response = await getResponse(conversation);
      functionCalls = response.output.filter(
        (item) => item.type === "function_call"
      );
    }
    console.log(`Respons asisten akhir: ${response.output_text}`);
  }
};

// Jalankan program.
main().catch(console.error);

Pemahaman dokumen

Python

import os
from openai import OpenAI

client = OpenAI(
    # Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan: api_key="sk-xxx"
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
)

response = client.responses.create(
    model="qwen3.5-ocr",
    input=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_file",
                    "file_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260616/qmycjl/1506.02640v5.pdf",
                },
                {
                    "type": "input_text",
                    "text": "Read all the text in the file.",
                },
            ],
        }
    ],
    extra_body={
        "ocr_options": {}
    },
)

print(response.output_text)

Node.js

import OpenAI from 'openai';

const client = new OpenAI({
    // Jika Anda belum mengonfigurasi variabel lingkungan, ganti baris berikut dengan: apiKey: "sk-xxx"
    apiKey: process.env.DASHSCOPE_API_KEY,
    baseURL: "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
});

async function main() {
    const response = await client.responses.create({
        model: "qwen3.5-ocr",
        input: [{
            role: "user",
            content: [{
                type: "input_file",
                file_url: "https://example.com/your-document.pdf"
            }]
        }],
        ocr_options: { task: "document_parsing" }
    });

    // Dapatkan hasil tugas khusus
    console.log(response.output[0].content[0].ocr_result);
}

main();

curl

curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/compatible-mode/v1/responses \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
    "model": "qwen3.5-ocr",
    "input": [
        {
            "role": "user",
            "content": [
                {
                    "type": "input_file",
                    "file_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20260616/qmycjl/1506.02640v5.pdf"
                },
                {
                    "type": "input_text",
                    "text": "Read all the text in the file."
                }
            ]
        }
    ],
    "ocr_options": {}
}'

Cache sesi

Python

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    # Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.    base_url="https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
    # Aktifkan cache sesi melalui default_headers.
    default_headers={"x-dashscope-session-cache": "enable"}
)

# Buat teks panjang lebih dari 1024 token untuk memicu pembuatan cache.
# Jika tidak, caching dipicu ketika konteks kumulatif melebihi 1024 token.
long_context = "Artificial intelligence (AI) is a major branch of computer science, dedicated to researching and developing theories, methods, technologies, and application systems that can simulate, extend, and expand human intelligence." * 50

# Putaran pertama
response1 = client.responses.create(
    model="qwen3.7-plus",
    input=long_context + "\n\nBased on this context, briefly introduce the Random Forest algorithm in machine learning.",
)
print(f"Respons pertama: {response1.output_text}")

# Putaran kedua: Hubungkan konteks menggunakan previous_response_id. Cache ditangani secara otomatis oleh server.
response2 = client.responses.create(
    model="qwen3.7-plus",
    input="What are the main differences between it and GBDT?",
    previous_response_id=response1.id,
)
print(f"Respons kedua: {response2.output_text}")

# Periksa status cache hit.
usage = response2.usage
print(f"Token input: {usage.input_tokens}")
print(f"Token yang di-cache: {usage.input_tokens_details.cached_tokens}")

Node.js

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.DASHSCOPE_API_KEY,
    // Ganti {WorkspaceId} dengan ID ruang kerja Anda yang sebenarnya. URL berbeda berdasarkan wilayah.    baseURL: "https://{WorkspaceId}.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1",
    // Aktifkan cache sesi melalui defaultHeaders.
    defaultHeaders: {"x-dashscope-session-cache": "enable"}
});

// Buat teks panjang lebih dari 1024 token untuk memicu pembuatan cache.
// Jika tidak, caching dipicu ketika konteks kumulatif melebihi 1024 token.
const longContext = "Artificial intelligence (AI) is a major branch of computer science, dedicated to researching and developing theories, methods, technologies, and application systems that can simulate, extend, and expand human intelligence.".repeat(50);

async function main() {
    // Putaran pertama
    const response1 = await openai.responses.create({
        model: "qwen3.7-plus",
        input: longContext + "\n\nBased on this context, briefly introduce the Random Forest algorithm in machine learning, including its basic principles and applications."
    });
    console.log(`Respons pertama: ${response1.output_text}`);

    // Putaran kedua: Hubungkan konteks menggunakan previous_response_id. Cache ditangani secara otomatis oleh server.
    const response2 = await openai.responses.create({
        model: "qwen3.7-plus",
        input: "What are the main differences between it and GBDT?",
        previous_response_id: response1.id
    });
    console.log(`Respons kedua: ${response2.output_text}`);

    // Periksa status cache hit.
    console.log(`Token input: ${response2.usage.input_tokens}`);
    console.log(`Token yang di-cache: ${response2.usage.input_tokens_details.cached_tokens}`);
}

main();

curl

# Putaran pertama
# Ulangi teks panjang 50 kali untuk memastikan melebihi 1024 token dan memicu pembuatan cache.
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" \
-H "x-dashscope-session-cache: enable" \
-d '{
    "model": "qwen3.7-plus",
    "input": "Artificial intelligence (AI) is a major branch of computer science..."
}'

# Putaran kedua - gunakan ID dari respons sebelumnya sebagai previous_response_id.
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" \
-H "x-dashscope-session-cache: enable" \
-d '{
    "model": "qwen3.7-plus",
    "input": "What are the main differences between it and GBDT?",
    "previous_response_id": ""
}'

model string (wajib)

ID model yang akan digunakan.

Model yang didukung

Singapura

Lingkup penerapan internasional

qwen3.7-max, qwen3.7-max-2026-05-20, qwen3.7-max-2026-06-08, qwen3-max, qwen3-max-2026-01-23, qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.5-plus, qwen3.5-plus-2026-04-20, qwen3.5-plus-2026-02-15, qwen3.6-flash, qwen3.6-flash-2026-04-16, qwen3.5-flash, qwen3.5-flash-2026-02-23, qwen3.6-35b-a3b, qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b, qwen-plus, qwen-flash, qwen3-coder-plus, qwen3-coder-flash, qwen-plus-character, qwen-flash-character

AS (Virginia)

Lingkup penerapan global

qwen3.7-maxqwen3.7-max-2026-05-20qwen3.7-max-2026-06-08qwen3.7-plusqwen3.7-plus-2026-05-26qwen3.6-plusqwen3.6-plus-2026-04-02qwen3.5-plusqwen3.5-plus-2026-02-15qwen3.6-flashqwen3.6-flash-2026-04-16qwen3.5-flashqwen3.5-flash-2026-02-23qwen3.6-35b-a3bqwen3.5-122b-a10bqwen3.5-27bqwen3.5-35b-a3b

Jerman (Frankfurt)

Lingkup penerapan global

qwen3.7-maxqwen3.7-max-2026-05-20qwen3.7-max-2026-06-08qwen3.7-plusqwen3.7-plus-2026-05-26qwen3.5-397b-a17bqwen3.5-122b-a10bqwen3.5-35b-a3bqwen3.5-27b

Tiongkok (Beijing)

Lingkup penerapan Daratan Tiongkok

qwen3.7-max, qwen3.7-max-2026-05-20, qwen3.7-max-2026-06-08, qwen3-max, qwen3-max-2026-01-23, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.5-plus, qwen3.5-plus-2026-04-20, qwen3.5-plus-2026-02-15, qwen3.6-flash, qwen3.6-flash-2026-04-16, qwen3.5-flash, qwen3.5-flash-2026-02-23, qwen3.6-35b-a3b, qwen3.5-397b-a17b, qwen3.5-122b-a10b, qwen3.5-27b, qwen3.5-35b-a3b, qwen-plus, qwen-flash, qwen3-coder-plus, qwen3-coder-flash, qwen-plus-character, qwen-flash-character

Hong Kong (Tiongkok)

Lingkup penerapan global

qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.6-plus, qwen3.6-flash, qwen3.5-flash, qwen3.5-flash-2026-02-23

Lingkup penerapan Hong Kong (Tiongkok)

qwen3-max, qwen3-max-2026-01-23, qwen-plus, qwen3.5-flash, qwen3.5-flash-2026-02-23

Jepang (Tokyo)

Lingkup penerapan Jepang

qwen3.7-plus, qwen3.7-plus-2026-05-26

Lingkup penerapan global

qwen3.7-plus, qwen3.7-plus-2026-05-26, qwen3.7-max, qwen3.7-max-2026-05-20, qwen3.6-plus, qwen3.6-plus-2026-04-02, qwen3.6-flash, qwen3.6-flash-2026-04-16

input string atau array (wajib)

Input untuk model. Format berikut didukung:

  • string: Teks biasa, seperti "Hello".

  • array: Array pesan, diurutkan berdasarkan giliran percakapan.

Jenis elemen array

EasyInputMessage objek

Objek dengan role untuk penulis pesan dan content untuk muatan pesan.

Properti

role string (wajib)

Peran penulis pesan. Nilai yang valid: user, assistant, system, developer.

content string atau array (wajib)

Konten pesan. Konten berupa string jika input berupa teks biasa, atau array jika input berupa array konten terstruktur. Ketika role adalah system atau developer, jenis elemen array adalah input_text. Ketika role adalah user, jenis elemen array adalah input_text, input_image, atau input_file. Ketika role adalah assistant, jenis elemen array adalah output_text.

API Responses saat ini tidak mendukung input video atau audio. Untuk meneruskan jenis data ini, gunakan Chat Completions API atau DashScope API.

Item array konten

type string (wajib)

Menentukan jenis konten. Nilai yang valid adalah input_text, input_image (hanya untuk peran user), input_file (hanya untuk peran user, mendukung PDF dan gambar), dan output_text (hanya untuk peran assistant).

text string

Konten teks. Diperlukan ketika type adalah input_text atau output_text.

image_url string

URL publik gambar. Diperlukan ketika type adalah input_image.

file_url string

URL publik file. Diperlukan ketika type adalah input_file. Mendukung file PDF (hingga 50 halaman, 100 MB) dan file gambar (hingga 20 MB). Saat ini hanya didukung oleh qwen3.5-ocr.

type string (opsional)

Tetap sebagai message.

ResponseOutputMessage objek (opsional)

Pesan keluaran model. Untuk melanjutkan percakapan, Anda dapat meneruskan objek message dari array output respons sebelumnya kembali ke input. Berbeda dengan EasyInputMessage, objek ini mencakup struktur keluaran lengkap, dengan id, status, dan content terstruktur.

Properti

type string (wajib)

Tetap sebagai message.

id string (wajib)

Identifikasi unik pesan keluaran, dari respons sebelumnya.

role string (wajib)

Tetap sebagai assistant.

status string (wajib)

Status pesan. Nilai yang valid: in_progress, completed, incomplete.

content array (wajib)

Array konten, di mana elemennya adalah objek output_text.

Properti

type string (wajib)

Tetap sebagai output_text.

text string (wajib)

Teks respons.

annotations array (opsional)

Informasi anotasi.

Pemanggilan fungsi objek (opsional)

Instruksi terstruktur yang dihasilkan ketika model memutuskan untuk memanggil alat eksternal.

Properti

type string (wajib)

Tetap sebagai function_call.

id string (opsional)

Identifikasi unik untuk pemanggilan fungsi, dari respons sebelumnya.

name string (wajib)

Nama fungsi alat.

arguments string (wajib)

Argumen pemanggilan alat, dalam format string JSON.

call_id string (wajib)

Identifikasi untuk pemanggilan alat. Ini harus cocok dengan call_id yang dikembalikan oleh model.

status string (opsional)

Status. Nilai yang valid: in_progress, completed, incomplete.

Keluaran pemanggilan fungsi objek (opsional)

Keluaran dari pemanggilan alat. Dalam daftar pesan, objek ini harus segera mengikuti pesan function_call yang sesuai untuk mencegah kegagalan permintaan.

Properti

type string (wajib)

Tetap sebagai function_call_output.

id string (opsional)

Identifikasi unik untuk keluaran pemanggilan fungsi.

call_id string (wajib)

Identifikasi pemanggilan alat harus cocok dengan call_id yang dikembalikan oleh model.

output string (wajib)

Hasil eksekusi fungsi alat.

status string (opsional)

Status. Nilai yang valid: in_progress, completed, incomplete.

Reasoning objek (opsional)

Proses reasoning model. Anda dapat meneruskan item reasoning dari array output respons sebelumnya kembali ke input untuk melanjutkan proses ini di giliran berikutnya.

Properti

type string (wajib)

Tetap sebagai reasoning.

id string (wajib)

Identifikasi unik untuk konten reasoning, dari respons sebelumnya.

summary array (wajib)

Konten ringkasan reasoning.

Properti

type string (wajib)

Tetap sebagai summary_text.

text string (wajib)

Teks ringkasan.

status string (opsional)

Status. Nilai yang valid: in_progress, completed, incomplete.

instructions string (opsional)

Disisipkan di awal konteks sebagai instruksi sistem. Ketika previous_response_id digunakan, instructions yang ditentukan di giliran sebelumnya tidak diteruskan ke konteks giliran saat ini.

previous_response_id string (opsional)

ID unik dari respons sebelumnya. id respons berlaku selama 7 hari. Anda dapat menggunakan parameter ini untuk membuat percakapan multi-putaran. Server secara otomatis mengambil dan menggabungkan input dan output giliran tersebut sebagai konteks. Jika Anda menyediakan array pesan input dan previous_response_id, pesan baru dalam input ditambahkan ke konteks historis. Parameter ini tidak dapat digunakan bersamaan dengan conversation.

conversation string (opsional)

Percakapan tempat respons saat ini termasuk (lihat Conversations API). Riwayat percakapan secara otomatis disertakan sebagai konteks. Input dan output permintaan ini ditambahkan ke percakapan setelah selesai. Tidak dapat digunakan bersamaan dengan previous_response_id.

stream boolean (opsional) Default ke false

Mengaktifkan keluaran streaming. Jika diatur ke true, model mengalirkan respons secara real time.

store boolean (opsional) Default ke true

Menentukan apakah respons model yang dihasilkan untuk sesi ini disimpan.

  • false: Respons tidak disimpan dan tidak dapat dirujuk dalam pemanggilan berikutnya melalui previous_response_id.

  • true: Respons disimpan. Respons model saat ini dapat dirujuk oleh previous_response_id dan pemanggilan API berikutnya.

tools array (opsional)

Array alat yang dapat dipanggil model saat menghasilkan respons. Mendukung alat bawaan dan alat function kustom, yang dapat digunakan bersamaan.

Untuk hasil terbaik, aktifkan alat code_interpreter, web_search, dan web_extractor.

Properti

Pencarian web

Mencari informasi terbaru di internet. Dokumentasi terkait: Pencarian Web

Properti

type string (wajib)

Tetap sebagai web_search.

Contoh: [{"type": "web_search"}]

Ekstraktor web

Mengakses dan mengekstraksi konten dari halaman web. Harus digunakan bersama alat web_search. Untuk model qwen3-max dan qwen3-max-2026-01-23, mode reasoning juga harus diaktifkan. Dokumentasi terkait: Ekstraksi Web

Properti

type string (wajib)

Tetap sebagai web_extractor.

Contoh: [{"type": "web_search"}, {"type": "web_extractor"}]

Interpreter kode

Menjalankan kode dalam lingkungan sandbox untuk melakukan tugas seperti analisis data. Untuk model qwen3-max dan qwen3-max-2026-01-23, mode reasoning juga harus diaktifkan. Dokumentasi terkait: Interpreter Kode

Properti

type string (wajib)

Tetap sebagai code_interpreter.

Contoh: [{"type": "code_interpreter"}]

Web Search Image

Mencari gambar berdasarkan deskripsi teks. Dokumentasi terkait: Pencarian Teks-ke-Gambar

Properti

type string (wajib)

Tetap sebagai web_search_image.

Contoh: [{"type": "web_search_image"}]

Pencarian gambar

Mencari gambar serupa atau terkait berdasarkan gambar input. Input harus menyertakan URL gambar. Dokumentasi terkait: Pencarian Gambar-ke-Gambar

Properti

type string (wajib)

Tetap sebagai image_search.

Contoh: [{"type": "image_search"}]

Pencarian file

Menjalankan pengambilan pengetahuan dengan mencari basis pengetahuan tertentu. Dokumentasi terkait: Pengambilan Pengetahuan

Properti

type string (wajib)

Tetap sebagai file_search.

vector_store_ids array (wajib)

ID basis pengetahuan yang akan dicari. Saat ini, hanya satu ID basis pengetahuan yang dapat diberikan.

Contoh: [{"type": "file_search", "vector_store_ids": ["your_knowledge_base_id"]}]

Pemanggilan MCP

Memanggil layanan eksternal melalui Model Context Protocol (MCP). Dokumentasi terkait: MCP

Properti

type string (wajib)

Tetap sebagai mcp.

server_protocol string (wajib)

Protokol komunikasi dengan layanan MCP, seperti "sse".

server_label string (wajib)

Label yang digunakan untuk mengidentifikasi layanan MCP.

server_description string (opsional)

Deskripsi layanan. Membantu model memahami fungsinya dan kapan harus menggunakannya.

server_url string (wajib)

URL titik akhir layanan MCP.

headers objek (opsional)

Header permintaan, digunakan untuk membawa informasi seperti otentikasi (misalnya, Authorization).

Contoh:

mcp_tool = {
    "type": "mcp",
    "server_protocol": "sse",
    "server_label": "amap-maps",
    "server_description": "The AMap MCP Server provides a full suite of geographic information services, covering 15 core APIs. These include custom map generation, navigation, ride-hailing, geocoding, reverse geocoding, IP-based location, weather queries, and planning for cycling, walking, driving, and public transit routes, along with distance measurement and various search functions.",
    "server_url": "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1/mcps/amap-maps/sse",
    "headers": {
        "Authorization": "Bearer <your-mcp-server-token>"
    }
}

Alat Kustom Fungsi

Memungkinkan model memanggil fungsi yang ditentukan developer. Ketika model menentukan bahwa alat perlu dipanggil, respons mengembalikan item keluaran bertipe function_call. Dokumentasi terkait: Pemanggilan Fungsi

Properti

type string (wajib)

Harus diatur ke function.

name string (wajib)

Nama alat. Hanya boleh berisi huruf, angka, garis bawah (_), dan tanda hubung (-), dengan panjang maksimum 64 token.

description string (wajib)

Deskripsi alat, yang membantu model memutuskan kapan dan bagaimana memanggilnya.

parameters objek (opsional)

Definisi parameter untuk alat, yang harus merupakan objek JSON Schema yang valid. Jika parameters kosong, alat tidak memerlukan argumen (misalnya, alat kueri waktu).

Untuk meningkatkan akurasi pemanggilan alat, kami merekomendasikan mendefinisikan parameters.

Contoh:

[{
  "type": "function",
  "name": "get_weather",
  "description": "Get weather information for a specified city",
  "parameters": {
    "type": "object",
    "properties": {
      "city": {
        "type": "string",
        "description": "The name of the city"
      }
    },
    "required": ["city"]
  }
}]

tool_choice string atau objek (opsional) Default ke auto

Mengontrol cara model memilih dan memanggil alat. Parameter ini mendukung dua format: mode string dan mode objek.

String Mode

  • auto: Model memutuskan apakah akan memanggil alat.

  • none: Mencegah model memanggil alat apa pun.

  • required: Memaksa model memanggil alat. Ini hanya tersedia ketika daftar tools berisi tepat satu alat.

Mode objek

Membatasi model pada set alat tertentu untuk dipilih dan dipanggil.

Properti

mode string (wajib)

  • auto: Model secara otomatis memutuskan apakah akan memanggil alat dari daftar yang disediakan.

  • required: Memaksa model memanggil alat dari daftar yang disediakan. Ini hanya tersedia ketika daftar tools berisi tepat satu alat.

tools array(wajib)

Daftar definisi alat yang boleh dipanggil model.

[
  { "type": "function", "name": "get_weather" }
]

type string (wajib)

Jenis konfigurasi alat. Tetap sebagai allowed_tools.

suhu float (opsional)

Suhu sampling, yang mengontrol keragaman teks yang dihasilkan.

Nilai yang lebih tinggi membuat keluaran lebih acak dan beragam, sedangkan nilai yang lebih rendah membuatnya lebih fokus dan deterministik.

Kisaran nilai: [0, 2)

Baik suhu maupun top_p mengontrol keragaman teks yang dihasilkan. Kami merekomendasikan hanya menggunakan salah satu parameter ini dalam satu waktu. Untuk informasi lebih lanjut, lihat Ikhtisar.

top_p float (opsional)

Ambang batas probabilitas untuk pengambilan sampel top-p, yang mengontrol keragaman teks yang dihasilkan.

Nilai yang lebih tinggi membuat keluaran lebih acak dan beragam, sedangkan nilai yang lebih rendah membuatnya lebih fokus dan deterministik.

Kisaran nilai: (0, 1.0]

Baik suhu maupun top_p mengontrol keragaman teks yang dihasilkan. Kami merekomendasikan hanya menggunakan salah satu parameter ini dalam satu waktu. Untuk informasi lebih lanjut, lihat Ikhtisar.

enable_thinking boolean (opsional)

Mengaktifkan atau menonaktifkan mode reasoning. Ketika diaktifkan, model melakukan langkah reasoning sebelum merespons. Proses reasoning dikembalikan sebagai item keluaran bertipe reasoning. Ketika mengaktifkan mode reasoning, kami merekomendasikan juga mengaktifkan alat bawaan untuk mencapai hasil terbaik pada tugas kompleks.

Nilai yang valid:

  • true: Mengaktifkan mode reasoning.

  • false: Menonaktifkan mode reasoning.

Untuk nilai default berbagai model, lihat Model yang didukung.

Parameter ini bukan parameter OpenAI standar. Di SDK Python, teruskan menggunakan extra_body={"enable_thinking": True}. Di SDK Node.js dan curl, gunakan enable_thinking: true sebagai parameter tingkat atas. Kami merekomendasikan menggunakan reasoning.effort sebagai gantinya, karena enable_thinking akan ditinggalkan.

reasoning objek (opsional)

Mengontrol upaya reasoning model. Model melakukan langkah reasoning sebelum membalas, dan proses reasoning dikembalikan melalui item keluaran bertipe reasoning.

Properti

effort string (opsional): Tingkat upaya reasoning. Default ke medium.

  • none: Menonaktifkan reasoning dan memberikan jawaban langsung.

  • minimal: Meminimalkan reasoning untuk respons tercepat.

  • medium (default): Reasoning moderat, menyeimbangkan kecepatan dan kedalaman.

  • high: Reasoning mendalam, dioptimalkan untuk tugas kompleks dan profesional.

  • high: Analisis mendalam untuk masalah kompleks dan khusus.

reasoning.effort memiliki prioritas lebih tinggi daripada enable_thinking. Kami merekomendasikan menggunakan reasoning.effort, karena enable_thinking akan ditinggalkan.

ocr_options objek (opsional)

Parameter tugas bawaan OCR. Hanya berlaku untuk model qwen3.5-ocr. Gunakan parameter ini untuk memanggil tugas OCR bawaan (seperti ekstraksi informasi dan pelokalan teks). Hasil tugas bawaan dikembalikan dalam bidang ocr_result respons.

Parameter ini bukan parameter OpenAI standar. Di SDK Python, teruskan menggunakan extra_body={"ocr_options": {...}}. Di SDK Node.js dan curl, gunakan ocr_options sebagai parameter tingkat atas.

Objek respons (keluaran non-streaming)

{
    "created_at": 1771165900.0,
    "id": "f75c28fb-4064-48ed-90da-4d2cc4362xxx",
    "model": "qwen3.7-plus",
    "object": "response",
    "output": [
        {
            "content": [
                {
                    "annotations": [],
                    "text": "Hello! I am Qwen3.5, a large language model developed by Alibaba Cloud with knowledge up to 2026, designed to assist you with complex reasoning, creative tasks, and multilingual conversations.",
                    "type": "output_text"
                }
            ],
            "id": "msg_89ad23e6-f128-4d4c-b7a1-a786e7880xxx",
            "role": "assistant",
            "status": "completed",
            "type": "message"
        }
    ],
    "parallel_tool_calls": false,
    "status": "completed",
    "tool_choice": "auto",
    "tools": [],
    "usage": {
        "input_tokens": 57,
        "input_tokens_details": {
            "cached_tokens": 0
        },
        "output_tokens": 44,
        "output_tokens_details": {
            "reasoning_tokens": 0
        },
        "total_tokens": 101,
        "x_details": [
            {
                "input_tokens": 57,
                "output_tokens": 44,
                "total_tokens": 101,
                "x_billing_type": "response_api"
            }
        ]
    }
}

id string

Identifikasi unik untuk respons ini, berupa UUID. ID ini berlaku selama 7 hari dan dapat digunakan dalam parameter previous_response_id untuk membuat percakapan multi-putaran.

created_at integer

Timestamp Unix (dalam detik) untuk permintaan ini.

object string

Jenis objek, yang selalu response.

status string

Status generasi respons. Nilai yang valid:

  • completed: Generasi selesai.

  • failed: Generasi gagal.

  • in_progress: Generasi sedang berlangsung.

  • cancelled: Generasi dibatalkan.

  • queued: Permintaan dalam antrian.

  • incomplete: Generasi tidak lengkap.

model string

ID model yang digunakan untuk menghasilkan respons.

output array

Array item keluaran yang dihasilkan model. Jenis dan urutan elemen dalam array bergantung pada respons model.

Properti elemen array

type string

Jenis item keluaran. Nilai yang valid:

  • message: Item pesan yang berisi konten respons akhir model.

  • reasoning: Jenis reasoning. Parameter ini dikembalikan ketika reasoning.effort diatur ke nilai selain none atau ketika mode reasoning diaktifkan. Token reasoning dihitung dalam output_tokens_details.reasoning_tokens dan ditagih sebagai token reasoning.

  • function_call: Jenis pemanggilan fungsi. Ini dikembalikan ketika alat function kustom digunakan. Tangani pemanggilan fungsi dan kembalikan hasilnya.

  • web_search_call: Jenis pemanggilan pencarian. Ini dikembalikan ketika alat web_search digunakan.

  • code_interpreter_call: Jenis eksekusi kode yang dikembalikan ketika alat code_interpreter digunakan.

  • web_extractor_call: Jenis ekstraksi web. Ini dikembalikan ketika alat web_extractor digunakan. Harus digunakan bersama alat web_search.

  • web_search_image_call: Jenis pemanggilan untuk pencarian teks-ke-gambar. Ini dikembalikan ketika Anda menggunakan alat web_search_image. Berisi daftar gambar yang ditemukan.

  • image_search_call: Jenis pemanggilan untuk pencarian gambar-ke-gambar. Ini dikembalikan ketika alat image_search digunakan. Berisi daftar gambar serupa.

  • mcp_call: Jenis pemanggilan MCP. Ini dikembalikan ketika Anda menggunakan alat mcp. Berisi hasil pemanggilan layanan MCP.

  • file_search_call: Jenis pemanggilan untuk pencarian basis pengetahuan, yang dikembalikan ketika Anda menggunakan alat file_search. Berisi kueri pengambilan dan hasil untuk basis pengetahuan.

id string

Identifikasi unik item keluaran. Semua jenis item keluaran berisi bidang ini.

role string

Peran pesan selalu assistant. Parameter ini hanya ada ketika type adalah message.

status string

Status item keluaran. Nilai yang valid: completed dan in_progress. Parameter ini ada ketika parameter type tidak diatur ke reasoning.

name string

Nama alat atau fungsi. Parameter ini ada ketika type adalah function_call, web_search_image_call, image_search_call, atau mcp_call.

Untuk web_search_image_call dan image_search_call, nilainya tetap "web_search_image" dan "image_search", masing-masing.

Untuk mcp_call, nilainya adalah nama fungsi spesifik yang dipanggil dalam layanan MCP, seperti amap-maps-maps_geo.

arguments string

Parameter untuk pemanggilan alat, dalam format string JSON. Parameter ini ada ketika type adalah function_call, web_search_image_call, image_search_call, atau mcp_call. Uraikan string dengan menggunakan JSON.parse() sebelum digunakan. Konten argumen untuk berbagai jenis alat adalah sebagai berikut:

  • web_search_image_call: {"queries": ["Search Keyword 1", "Search Keyword 2"]}, di mana queries adalah daftar kata kunci pencarian yang dihasilkan model secara otomatis berdasarkan input pengguna.

  • image_search_call: {"img_idx": 0, "bbox": [0, 0, 1000, 1000]}, di mana img_idx adalah indeks gambar input (dimulai dari 0), dan bbox adalah koordinat kotak pembatas [x1, y1, x2, y2] untuk area pencarian. Nilai koordinat berkisar dari 0 hingga 1000.

  • function_call: Objek parameter yang dihasilkan dari skema parameter fungsi yang ditentukan pengguna.

  • mcp_call: Objek parameter untuk fungsi yang dipanggil dalam layanan MCP.

call_id string

ID unik untuk pemanggilan fungsi. Parameter ini hanya disertakan ketika type adalah function_call. ID ini harus disertakan dalam hasil pemanggilan fungsi untuk menghubungkan permintaan dengan respons.

content array

Array konten pesan. Parameter ini hanya ada jika type diatur ke message.

Properti elemen array

type string

Jenis konten. Nilainya tetap output_text.

text string

Konten teks yang dihasilkan model.

annotations array

Array anotasi teks. Biasanya berupa array kosong.

summary array

Array ringkasan reasoning. Bidang ini hanya ada ketika type adalah reasoning. Setiap elemen berisi bidang type (nilai: summary_text) dan bidang text (teks ringkasan).

action objek

Informasi tentang tindakan pencarian. Parameter ini hanya ada ketika type adalah web_search_call.

Properti

query string

Kata kunci kueri pencarian.

type string

Jenis pencarian. Nilainya selalu search.

sources array

Daftar sumber pencarian. Setiap elemen berisi bidang type dan url.

code string

Kode yang dihasilkan dan dieksekusi model. Ini hanya ada ketika type adalah code_interpreter_call.

outputs array

Array keluaran eksekusi kode. Ini hanya ada ketika type adalah code_interpreter_call. Setiap elemen memiliki bidang type (nilainya logs) dan bidang logs (log eksekusi kode).

container_id string

Identifikasi kontainer untuk interpreter kode. Parameter ini hanya ada ketika type adalah code_interpreter_call. Identifikasi ini mengasosiasikan beberapa eksekusi kode dalam sesi yang sama.

goal string

Deskripsi informasi yang akan diekstraksi dari halaman web. Parameter ini hanya tersedia ketika type adalah web_extractor_call.

output string

Keluaran pemanggilan alat. Keluaran berupa string.

  • Jika type adalah web_extractor_call, ini adalah ringkasan konten yang diekstraksi dari halaman web.

  • Jika type adalah web_search_image_call atau image_search_call, ini adalah string JSON yang berisi array hasil pencarian gambar. Setiap elemen mencakup bidang title, url, dan index.

  • Jika type adalah mcp_call, ini adalah string hasil JSON yang dikembalikan oleh layanan MCP.

urls array

Daftar URL untuk halaman web yang diekstraksi. Parameter ini hanya tersedia ketika type adalah web_extractor_call.

server_label string

Label untuk layanan MCP. Ini hanya muncul ketika type adalah mcp_call. Menunjukkan layanan MCP mana yang digunakan pemanggilan.

queries array

Daftar kueri untuk pengambilan basis pengetahuan. Parameter ini hanya ada ketika type adalah file_search_call. Array berisi string. Setiap string adalah kueri pencarian yang dihasilkan model.

results array

Array hasil pencarian dari basis pengetahuan. Parameter ini hanya ada ketika type adalah file_search_call.

Properti elemen array

file_id string

ID file dokumen yang cocok.

filename string

Nama file dokumen yang cocok.

score float

Skor relevansi kecocokan. Nilainya berkisar dari 0 hingga 1. Nilai yang lebih besar menunjukkan relevansi yang lebih tinggi.

text string

Cuplikan konten dari dokumen yang cocok.

usage objek

Informasi tentang konsumsi token untuk permintaan ini.

Properti

input_tokens integer

Jumlah token dalam input. Catatan Tambahan

output_tokens integer

Jumlah token dalam keluaran model.

total_tokens integer

Total jumlah token yang dikonsumsi adalah jumlah dari input_tokens dan output_tokens.

input_tokens_details objek

Klasifikasi rinci input token.

Properti

cached_tokens integer

Jumlah token yang mengenai cache. Untuk informasi lebih lanjut, lihat cache konteks.

output_tokens_details objek

Rincian rinci token keluaran.

Properti

reasoning_tokens integer

Jumlah token reasoning.

x_details array

Array detail penagihan untuk permintaan. Ini memberikan rincian lebih granular token multimodal daripada bidang usage tingkat atas.

Properti

input_tokens integer

Jumlah token dalam input. Catatan Tambahan

output_tokens integer

Jumlah token dalam keluaran model.

total_tokens integer

Total jumlah token yang dikonsumsi adalah jumlah dari input_tokens dan output_tokens.

x_billing_type string

Nilainya tetap response_api.

image_tokens integer

Jumlah token untuk input gambar. Bidang ini dikembalikan ketika input menyertakan gambar dan setara dengan input_tokens_details.image_tokens.

input_tokens_details objek

Rincian granular input token. Bidang ini dikembalikan untuk input multimodal. Saat ini hanya membedakan antara text_tokens dan image_tokens. Tidak memberikan rincian untuk token video atau audio.

Properti

text_tokens integer

Jumlah token untuk input teks.

image_tokens integer

Jumlah token untuk input gambar.

output_tokens_details objek

Rincian granular token keluaran. Bidang ini memiliki tambahan bidang text_tokens dibandingkan dengan output_tokens_details tingkat atas. Bidang text_tokens dikembalikan untuk input multimodal.

Properti

reasoning_tokens integer

Jumlah token untuk proses reasoning.

text_tokens integer

Jumlah token untuk keluaran teks. Bidang ini dikembalikan untuk input multimodal.

plugins objek

Statistik untuk pemanggilan alat bawaan. Bidang ini dikembalikan ketika alat bawaan seperti web_search digunakan. Isinya sama dengan bidang x_tools tingkat atas.

Properti

web_search objek

Statistik untuk pemanggilan pencarian web.

Properti

count integer

Jumlah kali pencarian web dipanggil dalam respons ini.

prompt_tokens_details objek

Rincian cache untuk token input. Bidang ini dikembalikan ketika cache sesi diaktifkan. Dapat mengembalikan objek kosong jika input menyertakan gambar tetapi menghasilkan cache miss.

Properti

cached_tokens integer

Jumlah token yang mengenai cache.

cache_creation_input_tokens integer

Jumlah token yang digunakan untuk membuat cache baru dalam permintaan ini.

cache_creation objek

Rincian pembuatan cache.

Properti

ephemeral_5m_input_tokens integer

Jumlah token yang digunakan untuk membuat cache ephemeral 5 menit baru.

cache_type string

Jenis cache. Nilainya tetap ephemeral.

x_tools objek

Statistik penggunaan alat. Ini berisi jumlah kali setiap alat bawaan dipanggil.

Contoh: {"web_search": {"count": 1}}

error objek

Objek error dikembalikan ketika model gagal menghasilkan respons. Jika tidak, nilainya null.

tools array

Menggemakan konten lengkap parameter tools dari permintaan, dengan struktur yang sama seperti parameter tools dalam badan permintaan.

tool_choice string

Menggemakan nilai parameter tool_choice dalam permintaan. Nilai yang valid adalah auto, none, dan required.

Objek potongan respons (keluaran streaming)

Panggilan dasar

// response.created: Respons dibuat dan dalam antrian.
{"response":{"id":"428c90e9-9cd6-90a6-9726-c02b08ebexxx","created_at":1769082930,"object":"response","status":"queued",...},"sequence_number":0,"type":"response.created"}

// response.in_progress: Pemrosesan dimulai.
{"response":{"id":"428c90e9-9cd6-90a6-9726-c02b08ebexxx","status":"in_progress",...},"sequence_number":1,"type":"response.in_progress"}

// response.output_item.added: Item keluaran baru ditambahkan.
{"item":{"id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","content":[],"role":"assistant","status":"in_progress","type":"message"},"output_index":0,"sequence_number":2,"type":"response.output_item.added"}

// response.content_part.added: Bagian konten baru ditambahkan.
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","output_index":0,"part":{"annotations":[],"text":"","type":"output_text","logprobs":null},"sequence_number":3,"type":"response.content_part.added"}

// response.output_text.delta: Segmen teks inkremental (dapat dipicu beberapa kali).
{"content_index":0,"delta":"Artificial Intelligence","item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","logprobs":[],"output_index":0,"sequence_number":4,"type":"response.output_text.delta"}
{"content_index":0,"delta":" (AI) refers to the technology","item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","logprobs":[],"output_index":0,"sequence_number":6,"type":"response.output_text.delta"}

// response.output_text.done: Generasi teks untuk bagian konten selesai.
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","logprobs":[],"output_index":0,"sequence_number":53,"text":"Artificial Intelligence (AI) refers to the technology and science that enables computer systems to simulate human intelligent behaviors...","type":"response.output_text.done"}

// response.content_part.done: Bagian konten selesai.
{"content_index":0,"item_id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","output_index":0,"part":{"annotations":[],"text":"...full text...","type":"output_text","logprobs":null},"sequence_number":54,"type":"response.content_part.done"}

// response.output_item.done: Item keluaran selesai.
{"item":{"id":"msg_bcb45d66-fc34-46a2-bb56-714a51e8exxx","content":[{"annotations":[],"text":"...full text...","type":"output_text","logprobs":null}],"role":"assistant","status":"completed","type":"message"},"output_index":0,"sequence_number":55,"type":"response.output_item.done"}

// response.completed: Respons selesai (termasuk respons lengkap dan penggunaan).
{"response":{"id":"428c90e9-9cd6-90a6-9726-c02b08ebexxx","created_at":1769082930,"model":"qwen3.7-max","object":"response","output":[...],"status":"completed","usage":{"input_tokens":37,"output_tokens":243,"total_tokens":280,...}},"sequence_number":56,"type":"response.completed"}

Ekstraksi web

id:1
event:response.created
:HTTP_STATUS/200
data:{"sequence_number":0,"type":"response.created","response":{"output":[],"parallel_tool_calls":false,"created_at":1769435906,"tool_choice":"auto","model":"","id":"863df8d9-cb29-4239-a54f-3e15a2427xxx","tools":[],"object":"response","status":"queued"}}

id:2
event:response.in_progress
:HTTP_STATUS/200
data:{"sequence_number":1,"type":"response.in_progress","response":{"output":[],"parallel_tool_calls":false,"created_at":1769435906,"tool_choice":"auto","model":"","id":"863df8d9-cb29-4239-a54f-3e15a2427xxx","tools":[],"object":"response","status":"in_progress"}}

id:3
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":2,"item":{"summary":[],"type":"reasoning","id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx"},"output_index":0,"type":"response.output_item.added"}

id:4
event:response.reasoning_summary_text.delta
:HTTP_STATUS/200
data:{"delta":"The user wants me to:\n1. Search for the Alibaba Cloud official website.\n2. Extract key information from the homepage.\n\nI need to first search for the URL of the Alibaba Cloud official website, and then use the web_extractor tool to access the website and extract key information.","sequence_number":3,"output_index":0,"type":"response.reasoning_summary_text.delta","item_id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx","summary_index":0}

id:14
event:response.reasoning_summary_text.done
:HTTP_STATUS/200
data:{"sequence_number":13,"text":"The user wants me to:\n1. Search for the Alibaba Cloud official website.\n2. Extract key information from the homepage.\n\nI need to first search for the URL of the Alibaba Cloud official website, and then use the web_extractor tool to access the website and extract key information.","output_index":0,"type":"response.reasoning_summary_text.done","item_id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx","summary_index":0}

id:15
event:response.output_item.done
:HTTP_STATUS/200
data:{"sequence_number":14,"item":{"summary":[{"type":"summary_text","text":"The user wants me to:\n1. Search for the Alibaba Cloud official website.\n2. Extract key information from the homepage.\n\nI need to first search for the URL of the Alibaba Cloud official website, and then use the web_extractor tool to access the website and extract key information."}],"type":"reasoning","id":"msg_5bd0c6df-19b8-4a04-bc00-8042a224exxx"},"output_index":1,"type":"response.output_item.done"}

id:16
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":15,"item":{"action":{"type":"search","query":"Web search"},"id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx","type":"web_search_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

id:17
event:response.web_search_call.in_progress
:HTTP_STATUS/200
data:{"sequence_number":16,"output_index":1,"type":"response.web_search_call.in_progress","item_id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx"}

id:19
event:response.web_search_call.completed
:HTTP_STATUS/200
data:{"sequence_number":18,"output_index":1,"type":"response.web_search_call.completed","item_id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx"}

id:20
event:response.output_item.done
:HTTP_STATUS/200
data:{"sequence_number":19,"item":{"action":{"sources":[{"type":"url","url":"https://cn.aliyun.com/"},{"type":"url","url":"https://www.aliyun.com/"}],"type":"search","query":"Web search"},"id":"msg_a8a686b1-0a57-40e1-bb55-049a89cd4xxx","type":"web_search_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

id:33
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":32,"item":{"urls":["https://cn.aliyun.com/"],"goal":"Extract key information from the Alibaba Cloud homepage, including: company positioning/overview, core products and services, main business segments, key features/solutions, latest news/events, free trial/discount information, and navigation menu structure.","id":"msg_8c2cf651-48a5-460c-aa7a-bea5b09b4xxx","type":"web_extractor_call","status":"in_progress"},"output_index":3,"type":"response.output_item.added"}

id:34
event:response.output_item.done
:HTTP_STATUS/200
data:{"sequence_number":33,"item":{"output":"The useful information in https://cn.aliyun.com/ for user goal 'Extract key information from the Alibaba Cloud homepage, including: company positioning/overview, core products and services, main business segments, key features/solutions, latest news/events, free trial/discount information, and navigation menu structure' is as follows: \n\nEvidence in page: \n## Tongyi large model, the first choice for enterprises in the AI era\n\n## A complete product system, building a cloud for enterprise technological innovation\n\nAll cloud products## Making AI accessible through the synergistic development of large models and cloud computing\n\nAll AI solutions\n\nSummary: \nAlibaba Cloud positions itself as a leading enterprise AI solution provider centered around the Tongyi large model...","urls":["https://cn.aliyun.com/"],"goal":"Extract key information from the Alibaba Cloud homepage, including: company positioning/overview, core products and services, main business segments, key features/solutions, latest news/events, free trial/discount information, and navigation menu structure.","id":"msg_8c2cf651-48a5-460c-aa7a-bea5b09b4xxx","type":"web_extractor_call","status":"completed"},"output_index":3,"type":"response.output_item.done"}

id:50
event:response.output_item.added
:HTTP_STATUS/200
data:{"sequence_number":50,"item":{"content":[{"type":"text","text":""}],"type":"message","id":"msg_final","role":"assistant"},"output_index":5,"type":"response.output_item.added"}

id:51
event:response.output_text.delta
:HTTP_STATUS/200
data:{"delta":"I have found the Alibaba Cloud website and extracted the key information from its homepage:\n\n","sequence_number":51,"output_index":5,"type":"response.output_text.delta"}

id:60
event:response.completed
:HTTP_STATUS/200
data:{"type":"response.completed","response":{"id":"863df8d9-cb29-4239-a54f-3e15a2427xxx","status":"completed","usage":{"input_tokens":45,"output_tokens":320,"total_tokens":365}}}

Pencarian teks-ke-gambar

// 1. response.created: Respons dibuat.
id:1
event:response.created
data:{"sequence_number":0,"type":"response.created","response":{"output":[],"status":"queued",...}}

// 2. response.in_progress: Respons sedang diproses.
id:2
event:response.in_progress
data:{"sequence_number":1,"type":"response.in_progress","response":{"status":"in_progress",...}}

// 3. response.output_item.added: Reasoning dimulai.
id:3
event:response.output_item.added
data:{"sequence_number":2,"item":{"summary":[],"type":"reasoning","id":"msg_xxx"},"output_index":0,"type":"response.output_item.added"}

// 4. response.reasoning_summary_text.delta: Delta ringkasan reasoning.
id:4
event:response.reasoning_summary_text.delta
data:{"delta":"The user wants to find a picture of a cat. I need to use the web_search_image tool to search...","sequence_number":3,"output_index":0,"type":"response.reasoning_summary_text.delta","item_id":"msg_xxx","summary_index":0}

// 5. response.reasoning_summary_text.done: Ringkasan reasoning selesai.
id:10
event:response.reasoning_summary_text.done
data:{"sequence_number":9,"text":"The user wants to find a picture of a cat. I need to use the web_search_image tool to search for cat pictures.","output_index":0,"type":"response.reasoning_summary_text.done","item_id":"msg_xxx","summary_index":0}

// 6. response.output_item.done: Item reasoning selesai.
id:11
event:response.output_item.done
data:{"sequence_number":10,"item":{"summary":[{"type":"summary_text","text":"..."}],"type":"reasoning","id":"msg_xxx"},"output_index":0,"type":"response.output_item.done"}

// 7. response.output_item.added: Pemanggilan alat pencarian teks-ke-gambar dimulai (status: in_progress; mencakup name dan arguments).
id:12
event:response.output_item.added
data:{"sequence_number":11,"item":{"name":"web_search_image","arguments":"{\"queries\": [\"cat pictures\", \"cute cat\"]}","id":"msg_xxx","type":"web_search_image_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 8. response.output_item.done: Pemanggilan alat pencarian teks-ke-gambar selesai (mencakup hasil pencarian 'output' lengkap).
id:13
event:response.output_item.done
data:{"sequence_number":12,"item":{"name":"web_search_image","output":"[{\"title\": \"Cute little cat...\", \"url\": \"https://example.com/cat.jpg\", \"index\": 1}, ...]","arguments":"{\"queries\": [\"cat pictures\", \"cute cat\"]}","id":"msg_xxx","type":"web_search_image_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 9-12. Acara reasoning dan keluaran pesan berikutnya mengikuti, mirip dengan alur panggilan dasar.
// response.output_item.added (reasoning) → reasoning_summary_text.delta/done → response.output_item.done (reasoning)
// response.output_item.added (message) → response.content_part.added → response.output_text.delta → response.output_text.done → response.content_part.done → response.output_item.done (message)

// 13. response.completed: Respons selesai.
id:118
event:response.completed
data:{"sequence_number":117,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":7895,"output_tokens":318,"total_tokens":8213,"x_tools":{"web_search_image":{"count":1}}}}}

Pencarian gambar-ke-gambar

// 1-6. Fase reasoning sama seperti dalam alur pencarian teks-ke-gambar.

// 7. response.output_item.added: Pemanggilan alat pencarian gambar-ke-gambar dimulai.
// Catatan: arguments mencakup img_idx (indeks gambar) dan bbox (kotak pembatas).
id:29
event:response.output_item.added
data:{"sequence_number":29,"item":{"name":"image_search","arguments":"{\"img_idx\": 0, \"bbox\": [0, 0, 1000, 1000]}","id":"msg_xxx","type":"image_search_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 8. response.output_item.done: Pemanggilan alat pencarian gambar-ke-gambar selesai.
id:30
event:response.output_item.done
data:{"sequence_number":30,"item":{"name":"image_search","output":"[{\"title\": \"Ink wash mountain background...\", \"url\": \"https://example.com/landscape.jpg\", \"index\": 1}, ...]","arguments":"{\"img_idx\": 0, \"bbox\": [0, 0, 1000, 1000]}","id":"msg_xxx","type":"image_search_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 9-12. Putaran reasoning kedua + keluaran pesan akhir (sama seperti panggilan dasar).

// 13. response.completed
id:408
event:response.completed
data:{"sequence_number":407,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":8371,"output_tokens":417,"total_tokens":8788,"x_tools":{"image_search":{"count":1}}}}}

MCP

// 1-6. Fase reasoning (sama seperti alat lainnya).

// 7. response.mcp_call_arguments.delta: Delta argumen MCP (acara khusus MCP).
id:27
event:response.mcp_call_arguments.delta
data:{"delta":"{\"city\": \"Beijing\"}","sequence_number":26,"output_index":1,"type":"response.mcp_call_arguments.delta","item_id":"msg_xxx"}

// 8. response.mcp_call_arguments.done: Argumen MCP selesai (acara khusus MCP).
id:28
event:response.mcp_call_arguments.done
data:{"sequence_number":27,"arguments":"{\"city\": \"Beijing\"}","output_index":1,"type":"response.mcp_call_arguments.done","item_id":"msg_xxx"}

// 9. response.output_item.added: Pemanggilan alat MCP dimulai (mencakup name, server_label, arguments).
id:29
event:response.output_item.added
data:{"sequence_number":28,"item":{"name":"amap-maps-maps_weather","server_label":"MCP Server","arguments":"{\"city\": \"Beijing\"}","id":"msg_xxx","type":"mcp_call","status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 10. response.mcp_call.completed: Pemanggilan MCP selesai (acara khusus MCP).
id:30
event:response.mcp_call.completed
data:{"sequence_number":29,"output_index":1,"type":"response.mcp_call.completed","item_id":"msg_xxx"}

// 11. response.output_item.done: Item keluaran MCP selesai (mencakup 'output' lengkap).
id:31
event:response.output_item.done
data:{"sequence_number":30,"item":{"output":"{\"city\":\"Beijing\",\"forecasts\":[...]}","name":"amap-maps-maps_weather","server_label":"MCP Server","arguments":"{\"city\": \"Beijing\"}","id":"msg_xxx","type":"mcp_call","status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 12-15. Putaran reasoning kedua + keluaran pesan akhir.

// 16. response.completed
id:172
event:response.completed
data:{"sequence_number":171,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":5019,"output_tokens":539,"total_tokens":5558}}}

Pencarian basis pengetahuan

// 1-6. Fase reasoning (sama seperti alat lainnya).

// 7. response.output_item.added: Pencarian basis pengetahuan dimulai (mencakup queries, tanpa hasil).
id:19
event:response.output_item.added
data:{"sequence_number":18,"item":{"id":"msg_xxx","type":"file_search_call","queries":["Alibaba Cloud Model Studio X1 phone","Alibaba Cloud Model Studio X1 phone","Model Studio X1"],"status":"in_progress"},"output_index":1,"type":"response.output_item.added"}

// 8. response.file_search_call.in_progress: Pencarian sedang berlangsung (acara khusus file_search).
id:20
event:response.file_search_call.in_progress
data:{"sequence_number":19,"output_index":1,"type":"response.file_search_call.in_progress","item_id":"msg_xxx"}

// 9. response.file_search_call.searching: Sedang mencari (acara khusus file_search).
id:21
event:response.file_search_call.searching
data:{"sequence_number":20,"output_index":1,"type":"response.file_search_call.searching","item_id":"msg_xxx"}

// 10. response.file_search_call.completed: Pencarian selesai (acara khusus file_search).
id:22
event:response.file_search_call.completed
data:{"sequence_number":21,"output_index":1,"type":"response.file_search_call.completed","item_id":"msg_xxx"}

// 11. response.output_item.done: Memberikan item keluaran lengkap, termasuk queries dan results.
id:23
event:response.output_item.done
data:{"sequence_number":22,"item":{"id":"msg_xxx","type":"file_search_call","queries":["Alibaba Cloud Model Studio X1 phone","Alibaba Cloud Model Studio X1 phone","Model Studio X1"],"results":[{"score":0.7519,"filename":"Alibaba Cloud Model Studio Series Phone Product Introduction","text":"Alibaba Cloud Model Studio X1 — Enjoy the ultimate visual experience...","file_id":"file_xxx"}],"status":"completed"},"output_index":1,"type":"response.output_item.done"}

// 12-15. Putaran reasoning kedua + keluaran pesan akhir.

// 16. response.completed
id:146
event:response.completed
data:{"sequence_number":145,"type":"response.completed","response":{"output":[...],"status":"completed","usage":{"input_tokens":1576,"output_tokens":722,"total_tokens":2298,"x_tools":{"file_search":{"count":1}}}}}

Keluaran streaming mengembalikan serangkaian objek JSON. Setiap objek mencakup bidang type untuk menentukan jenis peristiwa dan bidang sequence_number untuk menunjukkan urutan peristiwa. Peristiwa response.completed menandai akhir aliran.

type string

Pengidentifikasi jenis peristiwa. Nilai yang mungkin meliputi:

  • response.created: Respons dibuat, dengan status queued.

  • response.in_progress: Respons mulai diproses, dan status berubah menjadi in_progress.

  • response.output_item.added: Item keluaran baru (misalnya, pesan atau web_extractor_call) ditambahkan ke array keluaran. Ketika item.type adalah web_extractor_call, ini menunjukkan awal pemanggilan alat ekstraksi web.

  • response.content_part.added: Bagian konten baru ditambahkan ke array content item keluaran.

  • response.output_text.delta: Segmen teks inkremental dihasilkan. Peristiwa ini dipicu beberapa kali, dan bidang delta berisi segmen teks baru.

  • response.output_text.done: Generasi teks untuk bagian konten selesai. Bidang text berisi teks lengkap.

  • response.content_part.done: Bagian konten selesai. Objek part berisi bagian konten lengkap.

  • response.output_item.done: Item keluaran selesai. Objek item berisi item keluaran lengkap. Ketika item.type adalah web_extractor_call, ini menunjukkan penyelesaian pemanggilan alat ekstraksi web.

  • response.reasoning_summary_text.delta: (Dalam mode reasoning) Memberikan pembaruan inkremental ke ringkasan reasoning. Bidang delta berisi segmen baru.

  • response.reasoning_summary_text.done: (Dalam mode reasoning) Ringkasan reasoning selesai. Bidang text berisi ringkasan lengkap.

  • response.web_search_call.in_progress / searching / completed: Peristiwa yang menunjukkan perubahan status pencarian ketika menggunakan alat web_search.

  • response.code_interpreter_call.in_progress / interpreting / completed: Peristiwa untuk perubahan status eksekusi kode (ketika menggunakan alat code_interpreter).

  • Catatan: Alat web_extractor tidak memiliki pengidentifikasi jenis peristiwa khusus. Pemanggilan alatnya diteruskan melalui peristiwa umum response.output_item.added dan response.output_item.done dan diidentifikasi oleh bidang item.type dengan nilai web_extractor_call.

  • response.mcp_call_arguments.delta / response.mcp_call_arguments.done: Peristiwa ini memberikan delta dan status penyelesaian untuk argumen pemanggilan MCP.

  • response.mcp_call.completed: Pemanggilan layanan MCP selesai.

  • response.file_search_call.in_progress / searching / completed: Peristiwa perubahan status untuk pencarian basis pengetahuan (ketika Anda menggunakan alat file_search).

  • Catatan: Ketika menggunakan alat web_search_image dan image_search, tidak ada peristiwa status menengah khusus. Pemanggilan alat dikomunikasikan melalui peristiwa response.output_item.added (awal pemanggilan) dan response.output_item.done (pemanggilan selesai).

  • response.completed: Generasi respons selesai. Objek response berisi respons lengkap, termasuk penggunaan. Peristiwa ini menandai akhir aliran.

sequence_number integer

Nomor urutan peristiwa, dimulai dari 0 dan bertambah dengan setiap peristiwa. Gunakan nomor ini untuk memproses peristiwa dalam urutan yang benar.

response objek

Objek respons. Muncul dalam peristiwa response.created, response.in_progress, dan response.completed. Dalam peristiwa response.completed, objek ini berisi data respons lengkap (termasuk output dan usage), dan strukturnya identik dengan objek Respons non-streaming.

item objek

Objek item keluaran. Muncul dalam peristiwa response.output_item.added dan response.output_item.done. Dalam peristiwa added, objek ini berupa kerangka awal di mana content adalah array kosong. Dalam peristiwa done, objek ini lengkap.

Properti

id string

Identifikasi unik untuk item keluaran (misalnya, msg_xxx).

type string

Jenis item keluaran. Nilai yang mungkin: message, reasoning, web_search_call, web_search_image_call (pencarian teks-ke-gambar), image_search_call (pencarian gambar-ke-gambar), mcp_call (pemanggilan MCP), file_search_call (pencarian basis pengetahuan).

role string

Peran pesan, yang selalu assistant. Hanya ada ketika type adalah message.

status string

Status generasi. Dalam peristiwa added, statusnya in_progress, dan dalam peristiwa done, statusnya completed.

content array

Array konten pesan. Dalam peristiwa added, array ini kosong []. Dalam peristiwa done, array ini berisi objek bagian konten lengkap yang strukturnya sama dengan objek part.

part objek

Objek bagian konten. Muncul dalam peristiwa response.content_part.added dan response.content_part.done.

Properti

type string

Jenis bagian konten, yang selalu output_text.

text string

Konten teks. Ini adalah string kosong dalam peristiwa added dan teks lengkap dalam peristiwa done.

annotations array

Array anotasi teks. Biasanya berupa array kosong.

logprobs objek | null

Probabilitas log token. Bidang ini saat ini selalu mengembalikan null.

delta string

Segmen teks inkremental. Bidang ini muncul dalam peristiwa response.output_text.delta dan berisi segmen teks yang baru ditambahkan. Gabungkan semua nilai delta untuk merekonstruksi teks lengkap.

text string

Konten teks lengkap. Bidang ini muncul dalam peristiwa response.output_text.done. Anda dapat menggunakannya untuk memvalidasi teks yang direkonstruksi dari fragmen delta.

item_id string

Identifikasi unik untuk item keluaran. Gunakan ID ini untuk mengkorelasikan peristiwa yang termasuk dalam item yang sama.

output_index integer

Indeks item keluaran dalam array output.

content_index integer

Indeks bagian konten dalam array content.

summary_index integer

Indeks item dalam array summary item keluaran reasoning. Bidang ini muncul dalam peristiwa response.reasoning_summary_text.delta dan response.reasoning_summary_text.done.

FAQ

T: Bagaimana cara meneruskan konteks untuk percakapan multi-putaran?

J: Saat membuat permintaan percakapan baru, teruskan id dari respons sukses sebelumnya model sebagai parameter previous_response_id.

T: Mengapa beberapa bidang dalam contoh respons tidak dijelaskan dalam topik ini?

J: SDK OpenAI resmi mungkin mengeluarkan bidang tambahan yang didefinisikan oleh protokol OpenAI. Layanan kami tidak mendukung bidang-bidang tersebut, sehingga biasanya bernilai null. Fokuslah hanya pada bidang yang dijelaskan dalam topik ini.