Skip to content

Create a response

使用 OpenAI Responses API 规范格式创建模型响应。支持复杂的多模态输入、内置 Agent 工具链(文件检索、网页搜索、代码解释器、计算机操作、MCP 工具等)、深度思考推理,并支持通过 Server-Sent Events (SSE) 进行流式传输。

POST/v1/responses

请求头 (Headers)

Authorizationstringheader
Bearer Token 鉴权凭证。推荐方式,支持传入上游提供商 API Key 或 OmniCortex 虚拟密钥(以 sk-bf- 开头)。格式:Bearer <token>
x-api-keystringheader
通过请求头传递 API 密钥。同样支持直接传入 OmniCortex 虚拟密钥。
x-bf-vkstringheader
OmniCortex 虚拟密钥专属请求头,用于精细化团队组织治理、分流路由与配额限流控制。
Content-Typestringheaderrequired
请求体媒体格式,固定为 application/json

必填参数 (Required Body Parameters)

modelstringbodyrequired
目标模型标识或统一路由别名。格式为 provider/model(例如 openai/gpt-4.5-previewopenai/gpt-4oanthropic/claude-3-7-sonnet)。
inputstring | arraybodyrequired
传递给模型的输入内容。支持传入简单的纯文本字符串,或包含多轮会话结构、多模态媒体块、工具执行结果的事件对象列表:
  • 文本字符串:如 "简要介绍量子计算的核心原理"
  • 事件对象列表:每个元素为一个条目对象,包含 typemessagefunction_call_outputmcp_call 等)、roleuserassistantsystemdeveloper)、content(支持纯文本或包含 input_textinput_imageinput_fileinput_audio 的多模态分块)。

系统指引与会话上下文 (Instructions & Context)

instructionsstringbody
系统级全局操作指引(System Instructions)。用于设定模型的全局人设、响应规则、安全边界与行为准则,作用范围贯穿整个会话链路。
conversationstringbody
会话上下文唯一 ID。用于在多次连续的请求调用之间自动持久化并继承历史对话状态,免除客户端手动拼接超长上下文的历史开销。
previous_response_idstringbody
前序响应对象的唯一 ID。当需要基于某一特定轮次的生成结果进行增量追加或追问时指定。
context_managementobjectbody
上下文窗口动态管理策略配置,包含自动滑动窗口裁剪与记忆压缩规则。

高可用与调度路由 (Routing & Reliability)

fallbacksarraybody
备选模型容灾列表,每个元素格式为 provider/model。当主模型遭遇速率限制(429)或上游不可用(5xx)时,网关将无感依序降级至备选模型。

采样与生成控制 (Sampling & Generation)

streambooleanbodydefault: false
是否使用 Server-Sent Events (SSE) 流式返回响应分块。
stream_optionsobjectbody
流式响应扩展选项,例如 include_obfuscation 混淆控制。
temperaturenumberbodydefault: 1
采样温度,介于 0 到 2 之间。较高的值会使输出更具创意与随机性,较低的值则使输出更集中且确定。
top_pnumberbodydefault: 1
核采样(Nucleus sampling)阈值,介于 0 到 1 之间。模型仅考虑累积概率达到该阈值的 token 候选集。
max_output_tokensintegerbody
单次响应允许生成的最大 token 上限。
textobjectbody
文本输出格式与结构化约束配置:
  • format: 结构化输出模式,可选 textjson_objectjson_schema
  • verbosity: 输出详细度等级,可选 lowmediumhigh
top_logprobsintegerbody
在每个 token 位置返回最可能的前 N 个候选项的对数概率。
truncationstringbody
当输入内容超过目标模型上下文长度限制时的自动截断策略。

工具调用与代理扩展 (Tools & Agents)

toolsarraybody
模型在生成过程中可自主调用的工具库列表。Responses API 原生支持强大的内置与扩展 Agent 驱动能力:
  • function: 标准自定义函数调用工具(包含名称、描述与 JSON Schema 参数校验)。
  • file_search: 知识库文件检索工具,支持绑定 vector_store_ids 向量库与筛选过滤条件。
  • web_search / web_search_preview: 联网搜索引擎检索工具,支持地理位置过滤与上下文控制。
  • code_interpreter: 代码解释器沙箱,支持模型自主编写并执行 Python 代码与数据分析。
  • computer_use_preview: 桌面系统/界面自动化操控工具,支持屏幕截图读取与键盘鼠标交互。
  • mcp: Model Context Protocol (MCP) 客户端工具集成,支持动态对接企业 MCP 服务器。
  • image_generation: 文生图/图像编辑工具。
  • local_shell: 本地命令行执行工具。
tool_choicestring | objectbody
工具调用策略控制。支持枚举字符串(noneautorequired)或指定执行特定工具的对象结构。
parallel_tool_callsbooleanbodydefault: true
是否允许模型在单次决策中并行触发多个工具调用。
max_tool_callsintegerbody
单次响应会话循环中允许调用的最大工具执行次数上限。

深度思考推理 (Reasoning)

reasoningobjectbody
新一代推理模型(如 o1、o3、Claude 3.7 Thinking)专属配置:
  • effort (string): 推理思考强度等级,可选 noneminimallowmediumhighxhigh
  • summary (string): 思维链摘要输出模式,可选 autoconcisedetailed
  • max_tokens (integer): 允许思考过程消耗的最大 token 数量上限。

任务执行与治理安全 (Execution & Governance)

backgroundbooleanbodydefault: false
是否启用异步后台离线执行。当设为 true 时,网关立即返回响应 ID,客户端可后续通过轮询或 Webhook 接收完整运行结果。
storebooleanbodydefault: false
是否在网关端持久化归档本次响应执行轨迹,用于离线评测与审计追溯。
includearraybody
显式指定在响应中一并返回的附加字段列表(例如 ["file_search_result.content"])。
prompt_cache_keystringbody
提示词缓存键,用于跨请求精确复用历史长文本计算结果。
metadataobjectbody
附加到请求的自定义键值对元数据,可用于全链路业务追踪与自定义合规审计。
safety_identifierstringbody
安全合规检测标识符。
service_tierstringbody
上游处理请求的服务级别(如 autodefault)。
Create a response
HTTP / SDK
bash
curl --request POST \
  --url http://localhost:8080/v1/responses \
  --header 'Authorization: Bearer sk-bf-your-virtual-key' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "deepseek-v4-flash",
  "instructions": "You are a helpful and concise AI assistant.",
  "input": "Introduce yourself in one sentence.",
  "temperature": 0.7,
  "max_output_tokens": 2048,
  "stream": false
}'
python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8080/v1",
    api_key="sk-bf-your-virtual-key"
)

# 使用 OpenAI 原生 Responses API 规范
response = client.responses.create(
    model="openai/gpt-4o",
    instructions="You are a professional research agent specializing in AI infrastructure.",
    input="Analyze the architectural differences between API Gateways and Service Meshes.",
    tools=[{"type": "web_search"}],
    # 传入 OmniCortex 专属跨模型容灾配置
    extra_body={
        "fallbacks": ["anthropic/claude-3-7-sonnet"]
    },
    temperature=0.7,
    max_output_tokens=2048
)

print(response.output)
typescript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'http://localhost:8080/v1',
  apiKey: 'sk-bf-your-virtual-key',
});

async function main() {
  const response = await client.responses.create({
    model: 'openai/gpt-4o',
    instructions: 'You are a professional research agent specializing in AI infrastructure.',
    input: 'Analyze the architectural differences between API Gateways and Service Meshes.',
    tools: [{ type: 'web_search' }],
    // @ts-ignore - 传递 OmniCortex 扩展容灾参数
    fallbacks: ['anthropic/claude-3-7-sonnet'],
    temperature: 0.7,
  });

  console.log(response.output);
}

main();
Response
json
{
  "id": "resp_01j8m4k8x2f1g3h5j7k9",
  "object": "response",
  "status": "completed",
  "created_at": 1726915200,
  "model": "openai/gpt-4o",
  "instructions": "You are a professional research agent specializing in AI infrastructure.",
  "output": [
    {
      "id": "item_01j8m4k9a1b2c3d4e5",
      "type": "message",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "An API Gateway operates at the perimeter (North-South traffic), handling external client authentication, rate limiting, and unified routing. In contrast, a Service Mesh manages service-to-service communication within the cluster (East-West traffic) with mTLS, dynamic traffic splitting, and deep observability."
        }
      ]
    }
  ],
  "usage": {
    "prompt_tokens": 42,
    "completion_tokens": 58,
    "total_tokens": 100,
    "prompt_tokens_details": {
      "cached_read_tokens": 0,
      "cached_write_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0
    }
  },
  "extra_fields": {
    "request_type": "responses",
    "provider": "openai",
    "model_requested": "openai/gpt-4o",
    "latency": 320
  }
}