BazaarLinkBazaarLink
Đăng nhập
Tài liệuTham chiếu APITham chiếu SDKSử dụng AgentKỹ năng AI
Mục lục

Responses API

Responses API

Endpoint tương thích OpenAI Responses API cho hội thoại đa lượt không trạng thái, gọi công cụ và đầu vào đa phương thức. Lý tưởng cho agent và framework sử dụng OpenAI Python SDK ≥ 1.x với client.responses.create().

POST/v1/responses
Note
Chấp nhận cùng xác thực và định tuyến mô hình như Chat Completions.

Nội dung yêu cầu

modelbắt buộc
string
Dùng id hoặc alias được liệt kê tại GET /v1/models, ví dụ "claude-sonnet-4.6" hoặc "anthropic/claude-sonnet-4.6".
inputbắt buộc
string | Item[]
Đầu vào người dùng — chuỗi văn bản (tin nhắn đơn) hoặc mảng mục đầu vào cho hội thoại đa lượt / đa phương thức.
instructions
string
Hướng dẫn cấp hệ thống, tương đương tin nhắn system. Phải gửi lại mỗi yêu cầu.
stream
boolean
Nếu true, trả về sự kiện SSE Responses API. Loại sự kiện: response.created, response.output_text.delta, response.completed.
max_output_tokens
integer
Số token đầu ra tối đa để tạo (bao gồm token suy luận cho mô hình o-series).
temperature
number
Giá trị sampling được chuyển tiếp mà không kiểm tra phạm vi. Mô hình có thể giới hạn hoặc bỏ qua giá trị ngoài phạm vi hỗ trợ.
top_p
number
Xác suất lấy mẫu nucleus. Mặc định: 1
tools
Tool[]
Định nghĩa công cụ (hàm) — cùng định dạng JSON Schema như Chat Completions (chấp nhận cả dạng phẳng của Responses và dạng lồng). Các công cụ tích hợp sẵn của riêng OpenAI (web_search_preview, file_search, computer_use_preview) không được hỗ trợ; tìm kiếm web khả dụng qua plugins: [{id:"web"}] — chỉ hỗ trợ trên một số tuyến model.
tool_choice
string | object
Điều khiển sử dụng công cụ: "auto", "none", hoặc công cụ cụ thể
parallel_tool_calls
boolean
Bật gọi hàm song song khi cung cấp công cụ. Mặc định: true. Chỉ áp dụng cho mô hình họ OpenAI — xem ghi chú bên dưới.
response_format
object
Buộc đầu ra JSON có cấu trúc. Xem phần Đầu ra có cấu trúc
previous_response_id
string
Endpoint này không trạng thái — truyền giá trị khác null sẽ trả về 400 (invalid_prompt) ngay lập tức, không bao giờ được chấp nhận rồi bỏ qua. Hãy dùng chế độ không trạng thái: truyền toàn bộ lịch sử hội thoại trong mảng input.

Schema yêu cầu (TypeScript)

type ResponsesRequest = {
  model: string;                    // Listed id or alias from GET /v1/models
  input: string | InputItem[];      // string or multi-turn array

  // Optional
  instructions?: string;            // System-level message
  stream?: boolean;                 // Default: false
  max_output_tokens?: number;
  temperature?: number;
  top_p?: number;
  tools?: Tool[];
  tool_choice?: "auto" | "none" | "required" | object;
  parallel_tool_calls?: boolean;    // Default: true
  previous_response_id?: string;    // Not supported — use full input array
};

type InputItem =
  | { type?: "message"; role: "user" | "assistant" | "system" | "developer"; content: string | ContentBlock[] }
  | { type: "function_call_output"; call_id: string; output: string }   // tool result
  | { type: "function_call"; call_id: string; name: string; arguments: string };

type ContentBlock =
  | { type: "input_text"; text: string }
  | { type: "input_image"; image_url: string; detail?: "auto" | "low" | "high" };

Yêu cầu mẫu

curl https://api.bazaarlink.ai/v1/responses \
  -H "Authorization: Bearer $BAZAARLINK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-5.4-mini",
    "instructions": "You are a helpful assistant.",
    "input": "What is the capital of Taiwan?"
  }'

Định dạng phản hồi

BazaarLink trả về phản hồi chuẩn hóa và loại bỏ các trường riêng của upstream. BazaarLink request ID opaque trong phản hồi trùng với x-request-id; dùng nó với GET /v1/generation. Phản hồi không stream cũng có cùng ID trong x-generation-id. usage.cost là số tiền USD đã tính cho khách hàng. Số liệu có thể xuất hiện sau vài giây khi hoàn tất; thử lại 404 trong thời gian ngắn.

// Non-streaming response object
type ResponsesResponse = {
  id: string;             // Opaque BazaarLink request id; format may change
  object: "response";
  created_at: number;
  completed_at: number;
  status: "completed" | "failed" | "incomplete";
  model: string;
  output: OutputItem[];
  usage: {
    input_tokens: number;   // equivalent to prompt_tokens
    output_tokens: number;  // equivalent to completion_tokens
    total_tokens: number;
    cost?: number;          // USD amount charged to the customer for this request
  } | null;
  error: null | { code: string; message: string };
};

type OutputItem =
  | {
      type: "message";
      id: string;
      role: "assistant";
      status: "completed";
      content: Array<{ type: "output_text"; text: string; annotations: [] }>;
    }
  | { type: "function_call"; id: string; call_id: string; name: string; arguments: string; status: "completed" };

Di chuyển từ Chat Completions

Thay messages bằng input (chuỗi hoặc mảng), dùng instructions thay cho tin nhắn system-role, và đọc output[0].content[0].text thay vì choices[0].message.content.

# Chat Completions (before)
response = client.chat.completions.create(
    model="openai/gpt-5.4-mini",
    messages=[
        {"role": "system", "content": "You are helpful."},
        {"role": "user",   "content": "Hello"},
    ]
)
text = response.choices[0].message.content

# Responses API (after)
response = client.responses.create(
    model="openai/gpt-5.4-mini",
    instructions="You are helpful.",
    input="Hello"
)
text = response.output[0].content[0].text

Hạn chế

  • previous_response_id hoặc store: true bị từ chối với 400 (mã lỗi invalid_prompt) — không phải chấp nhận rồi bỏ qua. Luôn dùng chế độ không trạng thái: truyền toàn bộ lịch sử hội thoại trong mảng input.
  • Các công cụ tích hợp sẵn của riêng OpenAI (web_search_preview, file_search, computer_use_preview) không được hỗ trợ. Tìm kiếm web khả dụng qua plugins: [{id:"web"}] — chỉ hỗ trợ trên một số tuyến model.
  • background: true được chấp nhận nhưng bị bỏ qua — mọi yêu cầu đều chạy đồng bộ đến khi hoàn tất.
Support
Hi! How can we help you?
Send a message and we'll get back to you soon.
Responses API | BazaarLink