Skip to content

计算机模拟

POST  v1/responses

/v1/responses 是 OpenAI 为 computer-use-preview(计算机使用预览版)模型设计的专用接口,区别于常规的 /v1/chat/completions(纯文本对话),专门用于: 接收模型执行计算机 / 浏览器操作(如打开网页、键鼠交互、页面信息提取)后的全链路响应,而非仅返回文本回答。

结合请求场景,该接口的具体作用 你的请求配置是让模型在 browser 环境下(1024×768 分辨率)访问 bing.com 查 OpenAI 最新新闻,提交这个请求后,/v1/responses 接口会返回以下关键内容: 模型执行工具操作的完整日志:包括浏览器启动、访问网址、页面加载、关键词检索等步骤的记录; 结构化的任务结果:既包含模型从网页中提取的 OpenAI 最新新闻文本,也包含操作过程的上下文; 适配请求参数的格式化输出:按 reasoning: {summary: "concise"} 要求返回简洁的新闻摘要,同时遵循 truncation: "auto" 自动截断冗余内容。

请求参数

Authorization

在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。

Authorization: Bearer ******************

Body 参数

Content-Type: application/json

参数名类型必填说明
modelstring必需要使用的模型 ID。
toolsarray[object]必需工具
inputarray [object]必需输入消息列表。包含 role (可选), content (可选) 等字段。
reasoningobject必需仅适用于o系列模型
truncationstring必需用于模型响应的截断策略
includearray[string]可选指定要在模型响应中包含的附加输出数据。
instructionsstring可选作为系统消息插入到模型上下文的最前面。注意:当使用 previous_response_id 时,之前的指令不会自动带入,方便切换指令。
max_output_tokensinteger可选响应生成的最大 token 数(包含可见输出和推理 token)。
metadataobject可选最多包含 16 个键值对的元数据对象,用于存储额外信息。键最长 64 字符,值最长 512 字符。
parallel_tool_callsboolean可选是否在工具调用期间启用并行执行。
previous_response_idstring可选前一次响应的唯一 ID,用于创建多轮对话。
reasoningobject可选仅适用于 o 系列模型。配置模型的推理行为。
service_tierstring可选指定处理请求的延迟层级(如 auto, default, flex)。未设置时默认为 auto
storeboolean可选是否将此请求的输出存储用于模型蒸馏或评估。
streamboolean可选如果为 true,将通过服务器发送事件流式返回响应。
temperaturenumber可选采样温度 (0-2)。值越高输出越随机,值越低越确定。建议只调整此参数或 top_p 其中之一。
textobject可选文本响应的配置。可配置 { "type": "json_schema" } 以启用结构化输出。
tool_choicearray[string]可选模型可调用的工具列表(目前仅支持函数)。最多支持 128 个函数。
top_pnumber可选核采样参数 (0-1)。例如 0.1 意味着只考虑概率质量前 10% 的 token。
truncationstring可选用于模型响应的截断策略。
userstring可选最终用户的唯一标识符,有助于 OpenAI 监控和检测滥用行为。

请求示例 (JSON)

{
    "model": "computer-use-preview",
    "tools": [
        {
            "type": "computer_use_preview",
            "display_width": 1024,
            "display_height": 768,
            "environment": "browser"
        }
    ],
    "input": [
        {
            "role": "user",
            "content": [
                {
                    "type": "input_text",
                    "text": "Check the latest OpenAI news on [bing.com](http://bing.com)."
                }
            ]
        }
    ],
    "reasoning": {
        "summary": "concise"
    },
    "truncation": "auto"
}

返回响应

200 成功

Content-Type: application/json

响应参数

字段名类型必填说明
idstring必需响应的唯一标识符。
objectstring必需对象类型。
created_atinteger必需创建时间的 Unix 时间戳。
statusstring必需响应的当前状态。
backgroundboolean必需是否在后台运行。
modelstring必需使用的模型名称。
parallel_tool_callsboolean必需是否启用了并行工具调用。
service_tierstring必需服务层级(如 default, flex 等)。
storeboolean必需是否存储了输出用于训练/评估。
temperatureinteger必需采样温度。
tool_choicestring必需工具选择策略。
toolsarray[string]必需可用的工具列表。
top_logprobsinteger必需返回的对数概率数量。
top_pinteger必需核采样概率阈值。
truncationstring必需截断策略。
usernull必需用户标识(此处显示为 null,通常用于审计)。
metadataobject必需用户自定义的元数据。
createdinteger必需另一个时间戳字段(可能是兼容旧版字段)。

响应示例

{
  "id": "resp_1234567890abcdef",
  "object": "computer_use.response",
  "created": 1735700000,
  "model": "computer-use-preview",
  "response": {
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "OpenAI 最新新闻摘要(来自必应搜索):1. OpenAI 发布 GPT-4o Mini 轻量化版本,推理速度提升 30%;2. OpenAI 宣布与微软扩大云服务合作,拓展亚太地区算力节点。"
      },
      {
        "type": "computer_use_preview",
        "logs": [
          {
            "timestamp": 1735700001,
            "action": "browser_navigate",
            "details": {
              "url": "http://bing.com",
              "status": "success",
              "display_size": {
                "width": 1024,
                "height": 768
              }
            }
          },
          {
            "timestamp": 1735700005,
            "action": "browser_search",
            "details": {
              "query": "latest OpenAI news",
              "result_count": 28
            }
          },
          {
            "timestamp": 1735700010,
            "action": "text_extract",
            "details": {
              "source_url": "https://openai.com/blog/gpt-4o-mini",
              "extracted_text_length": 1280
            }
          }
        ]
      }
    ]
  },
  "usage": {
    "prompt_tokens": 89,
    "completion_tokens": 345,
    "tool_usage_tokens": 120,
    "total_tokens": 554
  }
}

示例代码

python
import http.client
import json

conn = http.client.HTTPSConnection("nxaiapp.com")
payload = json.dumps({
   "model": "computer-use-preview",
   "tools": [
      {
         "type": "computer_use_preview",
         "display_width": 1024,
         "display_height": 768,
         "environment": "browser"
      }
   ],
   "input": [
      {
         "role": "user",
         "content": [
            {
               "type": "input_text",
               "text": "Check the latest OpenAI news on [bing.com](http://bing.com)."
            }
         ]
      }
   ],
   "reasoning": {
      "summary": "concise"
   },
   "truncation": "auto"
})
headers = {
   'Authorization': 'Bearer <token>',
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1//responses", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))