创建 Responses
面向 Responses 协议的生文调用。请求体使用 input 形态。
请求体将透传至模型上游的 Responses 接口(如 GPT-5.5 上游的 OpenAI Responses)。实际支持的请求字段和响应结构取决于上游是否支持该协议。
使用 Chat Completions 协议? 参见 创建对话补全。
Endpoint
| Method | URL |
|---|---|
POST | {TRINITY_BASE_URL}/responses |
Base URL
| 项 | 值 |
|---|---|
| Base URL | https://api.trinitydesk.ai/v1 |
| 协议 | HTTPS |
bash
export TRINITY_BASE_URL="https://api.trinitydesk.ai/v1"
export TRINITY_API_KEY="xh-..."Headers
| Header | 必填 | 说明 |
|---|---|---|
Authorization | 是 | Bearer <TRINITY_API_KEY> |
Content-Type | 是 | application/json |
Accept | 流式时 | text/event-stream |
请求示例
非流式
bash
curl -sS "${TRINITY_BASE_URL}/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TRINITY_API_KEY}" \
-d '{
"model": "gpt-5.5",
"input": "Introduce yourself",
"max_output_tokens": 256
}'数组 input
bash
curl -sS "${TRINITY_BASE_URL}/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TRINITY_API_KEY}" \
-d '{
"model": "gpt-5.5",
"input": [
{ "role": "user", "content": "用一句话介绍你自己" }
],
"max_output_tokens": 256
}'流式
bash
curl -sS -N "${TRINITY_BASE_URL}/responses" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-H "Authorization: Bearer ${TRINITY_API_KEY}" \
-d '{
"model": "gpt-5.5",
"input": "Hello",
"stream": true
}'带 instructions 和 tools
bash
curl -sS "${TRINITY_BASE_URL}/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TRINITY_API_KEY}" \
-d '{
"model": "gpt-5.5",
"input": "北京现在几点?",
"instructions": "用中文回答,如果问到时间请说明时间来源",
"tools": [{
"type": "web_search",
"name": "web_search"
}]
}'请求体字段
以下字段将被透传至上游 Responses 接口。并非所有上游都支持全部字段,请参考对应模型文档。
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
model | 是 | string | 模型 ID |
input | 是 | string | array | 消息内容;字符串或 { role, content } 数组 |
prompt | 否 | string | object | 直接 prompt 输入,简单场景 |
stream | 否 | boolean | 默认 false;设为 true 启用 SSE 流式输出 |
instructions | 否 | string | 系统指令,影响回复风格和行为约束 |
max_output_tokens | 否 | integer | 输出 token 上限 |
reasoning | 否 | object | 推理配置,如 { "effort": "medium" } |
tools | 否 | array | 工具列表,如 web_search、function 等 |
tool_choice | 否 | string | 工具选择策略;"auto" / "required" / "none" |
parallel_tool_calls | 否 | boolean | 默认 true;允许并行工具调用 |
response_format / text | 否 | object | 输出格式配置,如 { "format": { "type": "json_schema", ... } } |
不支持的字段:
previous_response_id和store不支持。Responses 接口不提供基于历史 response ID 的续接,也不会存储对话历史;请在客户端自行维护多轮对话上下文,并通过input传入。提示:请求体中的
model值会被自动规范化(如"gpt-5.5"映射为内部模型 code)。不支持model=auto。
响应
成功时返回上游 Responses 协议形态 JSON(非流式)或 text/event-stream(流式)。响应结构由上游决定。
非流式响应示例
json
{
"id": "resp_abc123",
"object": "response",
"created": 1700000000,
"model": "gpt-5.5",
"status": "completed",
"output": [
{
"type": "message",
"role": "assistant",
"content": [
{ "type": "output_text", "text": "我是 AI 助手,很高兴为您服务!" }
]
}
],
"usage": {
"input_tokens": 15,
"output_tokens": 30,
"total_tokens": 45
}
}流式事件
流式模式下,每行以 data: 前缀输出 SSE 事件。行格式:
data: {"type": "response.output_text.delta", "delta": "...", ...}
data: [DONE]事件类型由上游决定。常见类型:
| 事件类型 | 说明 |
|---|---|
response.created | 响应已创建 |
response.in_progress | 响应开始生成 |
response.output_text.delta | 文本增量 |
response.output_text.done | 文本块完成 |
response.completed | 响应完成 |
response.failed | 响应失败 |
错误码
| HTTP | error.code | 场景 |
|---|---|---|
| 400 | invalid_request | 请求体缺少 input |
| 400 | unsupported_request_shape | 请求体形状无法识别 |
| 400 | model_interface_not_supported | 模型不支持 Responses 协议 |
| 402 | insufficient_quota | 余额不足 |
| 404 | model_not_found | 模型不存在或路由不可达 |
| 502 | upstream_error | 上游服务错误或超时 |
完整错误码见 错误与调试。
Python 示例
python
import os
import requests
url = f"{os.environ['TRINITY_BASE_URL']}/responses"
r = requests.post(
url,
headers={
"Authorization": f"Bearer {os.environ['TRINITY_API_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "gpt-5.5",
"input": [{"role": "user", "content": "用一句话介绍你自己"}],
"max_output_tokens": 256,
},
timeout=120,
)
r.raise_for_status()
resp = r.json()
print(f"Response ID: {resp.get('id')}")
print(f"Status: {resp.get('status')}")
for output in resp.get("output", []):
if output.get("type") == "message":
for block in output.get("content", []):
print(block.get("text"))