创建 Responses 响应
端点
POST
/v1/responsesOpenAI Responses API 兼容端点。仅支持 GPT 系列:以本端点调用 Claude 或 Gemini 会返回 400;Claude 请使用创建消息,Gemini 请使用 Gemini 原生格式。
请求
| 请求头 | 取值 | 说明 |
|---|---|---|
Authorization |
Bearer sk-moyiapi-xxxxxx |
鉴权。也可以改用 x-api-key |
content-type |
application/json |
最小请求体:
{
"model": "gpt-5.6-sol",
"input": "用一句话介绍 模驿API"
}
参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 是 | GPT 系列模型 ID |
input |
string 或数组 | 是 | 输入内容 |
stream |
boolean | 否 | 设为 true 时以 SSE 流式返回 |
reasoning.effort |
string | 否 | 推理力度,如 low |
tools |
array | 否 | 工具列表,支持 {"type": "web_search"} 与 {"type": "function", ...} |
service_tier |
string | 否 | 设为 fast 开启快速模式 |
其余字段按 OpenAI Responses API 格式透传。
响应
object 为 response,生成结果在 output 数组里,按输出项类型区分:
输出项 type |
说明 |
|---|---|
message |
模型回复,文本在 content[].text(content[].type 为 output_text) |
function_call |
模型请求调用函数,name 与 arguments 为调用参数 |
web_search_call |
模型执行了 Web 搜索 |
reasoning |
推理摘要项 |
status 为 completed 表示生成完成;usage 含 input_tokens、output_tokens、total_tokens 及各自的 _details。
stream 为 true 时返回 Responses API 标准事件流:response.created → response.in_progress → response.output_item.added → response.content_part.added → 多个 response.output_text.delta → response.output_text.done → … → response.completed,以 response.completed 结束。流的开头会先出现 codex.rate_limits、codex.response.metadata,结束前会出现 responsesapi.websocket_timing,这三种附加事件可忽略。
示例
基础请求
curl https://api.moyiapi.cn/v1/responses \
-H "Authorization: Bearer sk-moyiapi-xxxxxx" \
-H "content-type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"input": "用一句话介绍 模驿API"
}'
Python SDK
from openai import OpenAI
client = OpenAI(
api_key="sk-moyiapi-xxxxxx",
base_url="https://api.moyiapi.cn/v1",
)
resp = client.responses.create(
model="gpt-5.6-sol",
input="用一句话介绍 模驿API",
)
print(resp.output_text)
流式请求
请求体加 "stream": true,其余不变。
错误
| HTTP 状态 | error.type |
触发条件 |
|---|---|---|
| 401 | missing_auth_credential / invalid_api_key / invalid_bearer_token |
鉴权失败,详见鉴权 |
| 400 | invalid_request_error |
模型与协议不匹配,例如用本端点调用 Claude |
| 400 | model_not_available |
模型 ID 不存在或暂不可用 |