Tham Khảo API

API Responses

API Responses tương thích OpenAI — phiên bản kế thừa của Chat Completions, với các công cụ tích hợp sẵn như web search và file search. Sử dụng qua cùng một endpoint và SDK.

Endpoint

http
POST https://api.tokspan.com/v1/responses

Ví Dụ Nhanh

API Responses tuân theo cùng các mẫu OpenAI SDK — chỉ cần đổi tên phương thức:

python
from openai import OpenAI

client = OpenAI(api_key="sk-your-key", base_url="https://api.tokspan.com/v1")

response = client.responses.create(
    model="MODEL_NAME",
    input="What is the capital of France?",
)

print(response.output_text)
shell
curl -X POST "https://api.tokspan.com/v1/responses" \
  -H "Authorization: Bearer sk-your-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_NAME",
    "input": "What is the capital of France?"
  }'
json — Response
{
  "id": "resp_abc123",
  "object": "response",
  "created_at": 1700000000,
  "status": "completed",
  "model": "MODEL_NAME",
  "output": [{
    "type": "message",
    "role": "assistant",
    "content": [{
      "type": "output_text",
      "text": "The capital of France is Paris.",
      "annotations": []
    }]
  }],
  "usage": {
    "input_tokens": 12,
    "output_tokens": 8,
    "total_tokens": 20
  }
}

Nội Dung Yêu Cầu

Tham SốKiểuBắt BuộcMô Tả
modelstringID mô hình (ví dụ: gpt-4o, claude-opus-4-8). Xem Mô Hình để biết danh mục đầy đủ.
inputstring / arrayĐầu vào cho phản hồi. Có thể là một chuỗi đơn giản hoặc một mảng các mục message (ví dụ: input_text, input_image).
instructionsstringKhôngCác hướng dẫn cấp system cho mô hình — tương đương với message <code>system</code> trong API Responses.
max_output_tokensintegerKhôngSố token tối đa để tạo trong phản hồi.
temperaturenumberKhôngNhiệt độ lấy mẫu (0–2). Càng cao = càng ngẫu nhiên.
streambooleanKhôngBật streaming SSE. Mặc định: false.
toolsarrayKhôngCác tool mô hình có thể gọi, bao gồm các công cụ tích hợp sẵn như web_search_previewfile_search.
tool_choicestring / objectKhôngKiểm soát lựa chọn tool: "auto", "none", "required", hoặc một đối tượng tool cụ thể.
previous_response_idstringKhôngTruyền id của phản hồi trước để tiếp tục hội thoại nhiều lượt với trạng thái.
reasoningobjectKhôngCấu hình reasoning cho các mô hình suy luận (ví dụ: <code>effort</code>: <code>"low"</code> | <code>"medium"</code> | <code>"high"</code>).

Phản Hồi Streaming (SSE)

Đặt stream: true để nhận phản hồi theo từng phần qua Server-Sent Events — giống như streaming của Chat Completions.

shell
curl -X POST "https://api.tokspan.com/v1/responses" \
  -H "Authorization: Bearer sk-your-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_NAME",
    "input": "Tell me a story.",
    "stream": true
  }'

Công Cụ Tích Hợp Sẵn

API Responses hỗ trợ các công cụ tích hợp sẵn không cần định nghĩa function tùy chỉnh:

Web Search

json
{
  "model": "MODEL_NAME",
  "input": "What is the latest news about AI?",
  "tools": [{
    "type": "web_search_preview"
  }]
}

File Search

json
{
  "model": "MODEL_NAME",
  "input": "Summarize the Q3 report",
  "tools": [{
    "type": "file_search",
    "vector_store_ids": ["vs_abc123"]
  }]
}
Tính khả dụng của công cụ tích hợp sẵn: Web search và file search yêu cầu các mô hình và kênh ngược dòng hỗ trợ chúng. Tính khả dụng phụ thuộc vào các kênh đã cấu hình trong backend của bạn.