BazaarLinkBazaarLink
登入
文件API 参考SDK 参考Agent 应用AI Skills
章节导航

Responses API

Responses API

相容 OpenAI Responses API 格式的端点,支援无状态多轮对话、工具呼叫与多模态输入。适用于使用 OpenAI Python SDK ≥ 1.x 的 client.responses.create() 的 Agent 框架。

POST/v1/responses
Note
使用与 Chat Completions 相同的身份验证与模型路由逻辑。

请求内文

model必填
string
使用 GET /v1/models 列出的 id 或 alias,例如“claude-sonnet-4.6”或“anthropic/claude-sonnet-4.6”。
input必填
string | Item[]
使用者输入 — 纯字串(单则讯息)或输入项目阵列(多轮 / 多模态对话)。
instructions
string
系统层级指令,等同于 system 角色的讯息。每次请求都必须重新传送。
stream
boolean
若为 true,回传 Responses API SSE 串流事件,包含 response.created、response.output_text.delta、response.completed 等事件类型。
max_output_tokens
integer
最大输出 Token 数量(o 系列推理模型包含推理 Token)。
temperature
number
采样参数会转发且不做范围验证;模型可能自行限制或忽略超出支持范围的值。
top_p
number
核取样概率质量。预设:1
tools
Tool[]
工具(函数)定义,格式与 Chat Completions 相同的 JSON Schema(接受扁平的 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 输出。请参阅结构化输出章节
previous_response_id
string
本端点是无状态的——传入非 null 值会直接返回 400(invalid_prompt),不是被接受后忽略。请改用无状态模式:在 input 数组中带入完整对话历史。

请求结构 (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 返回标准化响应,并移除上游专属字段。响应中不透明的 BazaarLink 请求 ID 与 x-request-id 相同;可配合 GET /v1/generation 使用。非流式响应也会在 x-generation-id 返回同一个 ID。usage.cost 是向客户收取的美元金额。统计数据可能在完成后几秒才可用;若收到 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 取代 system 角色讯息,并从 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)——不是被接受后忽略。请一律使用无状态模式,在 input 数组中带入完整对话历史。
  • 不支持 OpenAI 专属的内建托管工具(web_search_preview、file_search、computer_use_preview)。网页搜索可通过 plugins: [{id:"web"}] 启用,仅部分模型路由支持。
  • background: true 会被接受但忽略,请求一律同步执行到完成为止。
客服
您好!有什么可以协助?
请留下消息,我们会尽快回复。
Responses API | BazaarLink