Responses API 接入
Responses API 适合 Agent、工具调用、结构化输入和需要统一事件流的应用。Codex 等编程工具通常也依赖这一类接口。
在 CoreRouter 中,/v1/responses 不是所有聊天模型的通用入口。它要求当前 Model ID 已绑定支持 Responses 协议的模型或渠道。普通 /v1/chat/completions 可用,不代表 /v1/responses 一定可用。
接口信息
| 配置项 | 填写内容 |
|---|---|
| Endpoint | https://api.corerouter.tech/v1/responses |
| Header | Authorization: Bearer sk-... |
| 必填字段 | model、input |
| 常见能力 | 文本生成、流式输出、工具调用、后台响应查询 |
| 模型要求 | 控制台中明确支持 Responses / Coding Agent 的 Model ID |
接入 Codex 或 Agent 前,请先用同一个 Model ID 单独验证
/v1/responses。如果返回 404、模型不存在或协议不支持,请更换支持 Responses 的模型。
最小请求
bash
export COREROUTER_API_KEY="sk-xxxxxxxxxxxxxxxx"
curl https://api.corerouter.tech/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $COREROUTER_API_KEY" \
-d '{
"model": "responses-model-id",
"input": "请用三句话介绍 CoreRouter。"
}'
流式输出
bash
curl https://api.corerouter.tech/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $COREROUTER_API_KEY" \
-d '{
"model": "responses-model-id",
"input": "请逐步解释 HTTP 流式响应是什么。",
"stream": true
}'
流式返回通常是 Server-Sent Events。不同 SDK 对事件解析方式不同,排查时优先用 curl 观察原始事件。
结构化输入
bash
curl https://api.corerouter.tech/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $COREROUTER_API_KEY" \
-d '{
"model": "responses-model-id",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "把这句话改写得更适合产品文档:配置好 key 就能用。"
}
]
}
]
}'
工具调用
bash
curl https://api.corerouter.tech/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $COREROUTER_API_KEY" \
-d '{
"model": "responses-model-id",
"input": "北京现在适合穿什么衣服?",
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "查询城市天气",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称"
}
},
"required": ["city"]
}
}
]
}'
工具调用是否可用取决于模型能力。用于 Agent 时,请优先选择控制台标记支持 Tool Calling、Streaming 和 Coding Agent 的模型。
查询后台响应
如果你的调用模式会返回后台任务 ID,可以用下面的接口查询:
bash
curl https://api.corerouter.tech/v1/responses/resp_xxxxxxxxxxxxxxxx \
-H "Authorization: Bearer $COREROUTER_API_KEY"
Responses 上下文压缩
/v1/responses/compact 是给 Agent 或编程工具压缩历史上下文的高级接口,不是普通聊天替代入口。它要求当前渠道支持 Responses 压缩能力,普通 Chat Completions 可用不代表这个接口可用。
bash
curl https://api.corerouter.tech/v1/responses/compact \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $COREROUTER_API_KEY" \
-d '{
"model": "responses-model-id",
"input": [
{
"role": "user",
"content": [
{"type": "input_text", "text": "请压缩这段对话上下文。"}
]
}
],
"instructions": "保留任务目标、约束条件和未完成事项。",
"previous_response_id": "resp_xxxxxxxxxxxxxxxx",
"service_tier": "auto"
}'
| 字段 | 是否必填 | 说明 |
|---|---|---|
model | 是 | 控制台中支持 Responses 压缩的 Model ID。 |
input | 否 | 需要压缩的输入,可以是字符串或 Responses 输入数组。 |
instructions | 否 | 指定压缩时需要保留的重点。 |
previous_response_id | 否 | 关联上一条 Responses 响应。 |
prompt_cache_key | 否 | 客户端使用提示缓存时的缓存键。 |
prompt_cache_options | 否 | 提示缓存选项,是否生效取决于渠道。 |
prompt_cache_retention | 否 | 提示缓存保留策略。 |
service_tier | 否 | 服务等级选项,是否生效取决于渠道。 |
部分客户端还会发送 tools、reasoning、text 等兼容字段。网关可以解析这些字段以兼容客户端,但不会保证它们全部转发到上游;不要把压缩接口当成完整的 Responses 创建接口来使用。
常见问题
404:确认 Base URL 是https://api.corerouter.tech/v1,并确认当前 Model ID 已绑定支持 Responses 的模型或渠道。400:确认请求体包含model和input,并且input格式符合当前 SDK 要求。/v1/responses/compact返回不支持:当前渠道没有 Responses 压缩能力,请换用支持该能力的 Model ID 或渠道。401:检查 API Key 和Authorization: Bearer ...。- Agent 没有工具调用:更换支持 Tool Calling / Coding Agent 的模型后再测。
CoreRouter API 文档