Responses
通过 OpenAI Responses 协议调用任意对话模型,支持存储响应和 previous_response_id。
POST /v1/responses 使用 OpenAI Responses 协议,也就是 Codex 和 OpenAI SDK 的 client.responses 所用的协议。所有对话模型都能在这里调用,previous_response_id 也对所有模型可用,包括 Claude 和 Gemini。完整的 schema 见端点参考。
| 端点 | POST https://api.ohmygpt.com/v1/responses |
| SDK Base URL | https://api.ohmygpt.com/v1 |
| 鉴权 | Authorization: Bearer $OHMYGPT_API_KEY |
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.ohmygpt.com/v1",
api_key=os.environ["OHMYGPT_API_KEY"],
)
response = client.responses.create(
model="openai/gpt-5.4-nano",
input="Explain QUIC in two sentences.",
)
print(response.output_text)让 Codex 接入 OhMyGPT,见 Codex CLI。
GPT 模型收到的请求与你发送的一致,厂商支持的所有 Responses 字段都可以用。其他模型同样以 Responses 格式返回。background、conversation、max_tool_calls、truncation 和 prompt 只对 GPT 模型生效,见协议。
用 reasoning.effort 设置推理,见思考。
存储的响应
无论哪个模型,OhMyGPT 都会存储每个成功的响应,并返回一个 resp_ 开头的 ID。store 默认为 true;发送 store: false 则不存储。存储的响应保留 30 天,只有你的账户能看到。
| 路由 | 作用 |
|---|---|
GET /v1/responses/{id} | 返回一个存储的响应 |
GET /v1/responses/{id}/input_items | 列出它的输入项(limit、after、order) |
DELETE /v1/responses/{id} | 删除它 |
GET /v1/responses | 列出你存储的响应,最新的在前(limit、after) |
POST /v1/responses/{id}/cancel | 把进行中的响应标记为已取消 |
把存储的 ID 作为 previous_response_id 传入,就能在任意模型上继续对话。模型会先看到之前的几轮,再看到你新的 input;之前的几轮按输入 token 计费:
first = client.responses.create(model="ohmygpt/mock", input="ping")
follow = client.responses.create(
model="ohmygpt/mock",
input="again",
previous_response_id=first.id,
)
items = client.responses.input_items.list(follow.id)
print([item.type for item in items.data]) # ['message', 'message', 'message']请使用存储的响应的 resp_ ID。其他 ID,包括以 store: false 发送的请求返回的 ID,都会返回 404:
{
"error": {
"type": "not_found_error",
"code": "not_found",
"param": null,
"message": "No response found with this `previous_response_id`."
}
}Codex 的工具项
Codex 会发送 Responses 核心规范之外的几种 item 类型:custom_tool_call、custom_tool_call_output、agent_message 和 additional_tools。所有对话模型都支持它们,所以你可以用 Claude、Gemini 或模型列表中的任何模型来跑 Codex。
流式输出
stream: true 返回 Responses 事件流,以 response.completed、response.incomplete 或 response.failed 结尾。最后一个事件之前有一行 : x-cost-credits 注释。如果流开始后模型出错,流会以 response.failed 结束,错误在 response.error 中。详见流式输出。