Responses

OpenAI Responses 格式,Codex 使用的就是它。

POST试一试

较新的 OpenAI 格式,用 input 和 instructions 代替 messages。Codex 使用这种格式。

在这里它是无状态的:不保存任何内容,所以不支持 previous_response_id 和保存的提示词。每次都要把对话作为 input 条目发送。

上游也不保留任何内容:每次调用都以 store: false 发出,并且在服务商看到调用之前会去掉 user、metadata 和 safety_identifier。

用 Authorization: Bearer binf_... 或 x-api-key 发送你的密钥。

请求体

这里列出的是大多数调用会用到的字段。OpenAI 格式的其他字段都会按原样转发。

  • modelstring必填

    来自 GET /models 的模型 ID,比如 anthropic/claude-sonnet-5.5。加上 :online 开启联网搜索,或加上 :nitro、:floor 或 :exacto 来影响由哪个服务商运行。

  • inputstring | object[]必填

    一段提示词,或以输入条目表示的对话。

  • instructionsstring

    系统提示词。

  • max_output_tokensinteger

    回答的最大长度,以 Token 计。请设置它:调用运行期间会预留它最长可能回答的费用。

  • streamboolean

    以服务器发送事件的形式,边生成边发送回答。超过一句话的回答都建议使用:流式调用最长可运行 30 分钟,其他调用 13 分钟。

  • temperaturenumber

    随机性,0 到 2。越低越可预测。

  • toolsobject[]

    模型可以调用的函数,采用该格式自己的结构。由你的代码运行它们,并把结果发回。也支持联网搜索和网页抓取。

  • max_tool_callsinteger

    一次调用中最多的工具步骤数。联网搜索循环会为每一步预留费用,所以数字越小,预留越少。

  • reasoningobject

    用于推理模型:{ "effort": "low" | "medium" | "high" }。

  • modelsstring[]

    备用模型,在第一个模型繁忙或不可用时按顺序尝试。预留金额按其中最贵的模型计算。

返回

  • idstring

    响应的 ID。

  • outputobject[]

    输出条目:消息、推理和工具调用。output_text 是拼接好的文本。

  • usageobject

    input_tokens、output_tokens 和 cost:本次调用的扣费金额,单位为美元。

响应头

  • x-binference-call-idstring

    这次调用在你调用记录页面上的 ID。联系我们时请提供它。

  • x-generation-idstring

    模型服务商为这次回答生成的 ID。

  • retry-afterinteger

    出现 429 或 503 时:重新发送前需要等待的整秒数。

  • retry-after-msinteger

    同样的等待时间,以毫秒计。OpenAI 和 Anthropic SDK 会读取它。

请求
curl https://binference.io/api/v1/responses \  -H "Authorization: Bearer $BINF_API_KEY" \  -H "Content-Type: application/json" \  -d '{    "model": "openai/gpt-6.1-sol",    "instructions": "You are a concise trading assistant.",    "input": "Summarize the last 24 hours of trades in one line.",    "max_output_tokens": 256  }'
返回
{  "id": "resp_7Yq2c1",  "object": "response",  "status": "completed",  "model": "openai/gpt-6.1-sol",  "output": [    {      "type": "message",      "role": "assistant",      "content": [        {          "type": "output_text",          "text": "12 trades today: 9 wins, net +3.4 BNB, biggest move on $NOVA."        }      ]    }  ],  "usage": {    "input_tokens": 29,    "output_tokens": 21,    "total_tokens": 50,    "cost": 0.000322  }}
流式输出(stream: true)
event: response.createddata: {"type":"response.created","response":{"id":"resp_7Yq2c1","status":"in_progress"}}event: response.output_text.deltadata: {"type":"response.output_text.delta","delta":"12 trades today"}event: response.completeddata: {"type":"response.completed","response":{"id":"resp_7Yq2c1","status":"completed","usage":{"input_tokens":29,"output_tokens":21,"total_tokens":50,"cost":0.000322}}}