API 参考OpenAI 兼容
Responses
OpenAI Responses API - GPT-4、GPT-4o 新对话格式,内置工具处理。简化多轮对话和 Agent 工作流的 API。
Responses API
Responses API 是 OpenAI 较新的创建 AI 响应格式。UniterRouter 完全支持此 API 格式。
Chat Completions vs Responses:Responses API 是 OpenAI 较新的格式。对于大多数场景,Chat Completions 仍然是推荐的方式。
端点
POST https://api.uniterouter.ai/v1/responses请求体
| 参数 | 类型 | 必需 | 描述 |
|---|---|---|---|
model | string | 是 | 要使用的模型 ID |
input | string/array | 是 | 输入文本或消息 |
instructions | string | 否 | 系统指令 |
temperature | number | 否 | 采样温度 |
max_output_tokens | integer | 否 | 生成的最大 token 数 |
tools | array | 否 | 可用工具 |
response_format | object | 否 | 输出格式规范 |
请求示例
curl https://api.uniterouter.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-d '{
"model": "gpt-4o",
"input": "法国的首都是什么?",
"instructions": "你是一个有帮助的助手。"
}'from openai import OpenAI
client = OpenAI(
base_url="https://api.uniterouter.ai/v1",
api_key="your_uniterouter_api_key",
)
response = client.responses.create(
model="gpt-4o",
input="法国的首都是什么?",
instructions="你是一个有帮助的助手。"
)
print(response.output_text)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.uniterouter.ai/v1",
apiKey: process.env.UNITEROUTER_API_KEY,
});
const response = await client.responses.create({
model: "gpt-4o",
input: "法国的首都是什么?",
instructions: "你是一个有帮助的助手。"
});
console.log(response.output_text);响应
{
"id": "resp_abc123",
"object": "response",
"created_at": 1699000000,
"model": "gpt-4o",
"output": [
{
"type": "message",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "法国的首都是巴黎。"
}
]
}
],
"usage": {
"input_tokens": 20,
"output_tokens": 10,
"total_tokens": 30
}
}多轮对话
在输入中包含之前的消息:
response = client.responses.create(
model="gpt-4o",
input=[
{"role": "user", "content": "你好!"},
{"role": "assistant", "content": "你好!有什么可以帮助你的?"},
{"role": "user", "content": "今天天气怎么样?"}
]
)工具使用
tools = [
{
"type": "function",
"name": "get_weather",
"description": "获取当前天气",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
},
"required": ["location"]
}
}
]
response = client.responses.create(
model="gpt-4o",
input="东京的天气怎么样?",
tools=tools
)相关文档
How is this guide?