BazaarLinkBazaarLink
เข้าสู่ระบบ
เอกสารAPI ข้อมูลอ้างอิงSDK ข้อมูลอ้างอิงการใช้งาน AgentAI ทักษะ
สารบัญ

Responses API

Responses API

Endpoint ที่รองรับ OpenAI Responses API สำหรับการสนทนาหลายรอบแบบ stateless, tool calling และอินพุต multimodal เหมาะสำหรับ agent และเฟรมเวิร์กที่ใช้ OpenAI Python SDK ≥ 1.x กับ client.responses.create()

POST/v1/responses
Note
รับการยืนยันตัวตนและการกำหนดเส้นทางโมเดลเดียวกับ Chat Completions

เนื้อความคำขอ

modelจำเป็น
string
ใช้ id หรือ alias ที่แสดงใน GET /v1/models เช่น "claude-sonnet-4.6" หรือ "anthropic/claude-sonnet-4.6"
inputจำเป็น
string | Item[]
อินพุตผู้ใช้ — สตริงธรรมดา (ข้อความเดียว) หรืออาร์เรย์ของรายการอินพุตสำหรับการสนทนาหลายรอบ/multimodal
instructions
string
คำสั่งระดับระบบ เทียบเท่ากับข้อความระบบ ต้องส่งใหม่ทุกคำขอ
stream
boolean
ถ้า true จะส่งคืน Responses API SSE stream events ประเภทเหตุการณ์: response.created, response.output_text.delta, response.completed
max_output_tokens
integer
จำนวนโทเค็นเอาต์พุตสูงสุดที่จะสร้าง (รวมโทเค็นการใช้เหตุผลสำหรับโมเดล o-series)
temperature
number
ส่งค่าการสุ่มตัวอย่างโดยไม่ตรวจสอบช่วง โมเดลอาจจำกัดหรือไม่สนใจค่าที่อยู่นอกช่วงรองรับ
top_p
number
มวลความน่าจะเป็นการสุ่มตัวอย่าง Nucleus ค่าเริ่มต้น: 1
tools
Tool[]
คำจำกัดความเครื่องมือ (ฟังก์ชัน) — รูปแบบ JSON Schema เดียวกับ Chat Completions (รับทั้งรูปแบบแบนของ Responses และรูปแบบซ้อน) เครื่องมือโฮสต์ในตัวของ OpenAI เอง (web_search_preview, file_search, computer_use_preview) ไม่รองรับ; การค้นหาเว็บใช้ได้ผ่าน plugins: [{id:"web"}] — รองรับเฉพาะบางเส้นทางโมเดล
tool_choice
string | object
ควบคุมการใช้เครื่องมือ: "auto", "none" หรือเครื่องมือเฉพาะ
parallel_tool_calls
boolean
เปิดใช้งานการเรียกฟังก์ชันแบบขนานเมื่อมีเครื่องมือ ค่าเริ่มต้น: true ใช้ได้เฉพาะโมเดลตระกูล OpenAI เท่านั้น — ดูหมายเหตุด้านล่าง
response_format
object
บังคับเอาต์พุต JSON ที่มีโครงสร้าง ดูส่วน Structured Output
previous_response_id
string
เอนด์พอยต์นี้ไม่มีสถานะ — การส่งค่าที่ไม่ใช่ null จะคืนค่า 400 (invalid_prompt) ทันที ไม่เคยถูกยอมรับแล้วละเว้น ให้ใช้โหมด stateless แทน: ส่งประวัติการสนทนาเต็มในอาร์เรย์ input

Request Schema (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" };

ตัวอย่างคำขอ

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?"
  }'

รูปแบบการตอบกลับ

BazaarLink ส่งคืน response แบบมาตรฐานและลบฟิลด์เฉพาะของ upstream ออก request ID แบบ opaque ของ BazaarLink ใน response ตรงกับ x-request-id ใช้ร่วมกับ GET /v1/generation response แบบ non-streaming จะส่ง ID เดียวกันใน x-generation-id ด้วย usage.cost คือจำนวนเงิน USD ที่เรียกเก็บจากลูกค้า สถิติอาจพร้อมใช้งานหลังเสร็จสิ้นไม่กี่วินาที หากได้ 404 ให้ลองซ้ำช่วงสั้นๆ

// 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" };

ย้ายจาก Chat Completions

แทนที่ messages ด้วย input (สตริงหรืออาร์เรย์) ใช้ instructions แทนข้อความบทบาทระบบ และอ่าน output[0].content[0].text แทน 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

ข้อจำกัด

  • previous_response_id หรือ store: true จะถูกปฏิเสธด้วย 400 (รหัสข้อผิดพลาด invalid_prompt) — ไม่ใช่ถูกยอมรับแล้วละเว้น ให้ใช้โหมด stateless เสมอ: ส่งประวัติการสนทนาเต็มในอาร์เรย์ input
  • เครื่องมือโฮสต์ในตัวของ OpenAI เอง (web_search_preview, file_search, computer_use_preview) ไม่รองรับ การค้นหาเว็บใช้ได้ผ่าน plugins: [{id:"web"}] — รองรับเฉพาะบางเส้นทางโมเดล
  • background: true ได้รับการยอมรับแต่ถูกละเว้น — ทุกคำขอทำงานแบบซิงโครนัสจนเสร็จสมบูรณ์เสมอ
Support
Hi! How can we help you?
Send a message and we'll get back to you soon.
Responses API | BazaarLink