原生OpenAI格式
概述
平台兼容 OpenAI API 协议,可直接使用 OpenAI 官方 SDK 或兼容 OpenAI 协议的客户端进行调用。
目前支持:
- Chat Completions API
- Responses API
Chat Completions API
根据对话历史生成模型回复。
兼容 OpenAI Chat Completions API。
请求地址
POST /v1/chat/completions
请求头
Authorization: Bearer <Token>
Content-Type: application/json
核心请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型 ID |
| messages | array | 是 | 对话消息列表 |
| temperature | number | 否 | 采样温度,0~2 |
| stream | boolean | 否 | 是否流式返回 |
| max_completion_tokens | integer | 否 | 最大输出 Token 数 |
| tools | array | 否 | 工具列表 |
| tool_choice | string/object | 否 | 工具调用策略 |
| response_format | object | 否 | 指定返回格式 |
Messages
消息数组中的每个元素包含:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| role | string | 是 | system、user、assistant、tool、developer |
| content | string | 是 | 消息内容 |
| name | string | 否 | 角色名称 |
示例:
{
"role": "user",
"content": "介绍一下 MCP"
}
工具调用(Tools)
支持 OpenAI Function Calling。
工具定义:
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取天气信息",
"parameters": {}
}
}
工具调用策略:
| 值 | 说明 |
|---|---|
| none | 不调用工具 |
| auto | 自动决定 |
| required | 必须调用工具 |
请求示例
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "你好"
}
],
"temperature": 0.7,
"stream": false
}
成功响应
HTTP Status:200 OK
响应结构
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 请求唯一标识 |
| object | string | 固定为 chat.completion |
| created | integer | 创建时间 |
| model | string | 使用模型 |
| choices | array | 回复结果 |
| usage | object | Token 使用统计 |
choices
| 字段 | 类型 | 说明 |
|---|---|---|
| index | integer | 回复序号 |
| message | object | 模型回复内容 |
| finish_reason | string | 停止原因 |
支持的 finish_reason:
- stop
- length
- tool_calls
- content_filter
- sensitive
usage
| 字段 | 类型 | 说明 |
|---|---|---|
| prompt_tokens | integer | 输入 Token 数 |
| completion_tokens | integer | 输出 Token 数 |
| total_tokens | integer | 总 Token 数 |
响应示例
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1710000000,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好,很高兴为你服务。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 18,
"total_tokens": 30
}
}
Responses API
用于创建模型响应,支持多轮对话、工具调用和推理能力。
兼容 OpenAI Responses API。
请求地址
POST /v1/responses
请求头
Authorization: Bearer <Token>
Content-Type: application/json
核心请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型 ID |
| input | string | 是 | 用户输入内容 |
| instructions | string | 否 | 系统指令 |
| max_output_tokens | integer | 否 | 最大输出 Token 数 |
| stream | boolean | 否 | 是否流式输出 |
| tools | array | 否 | 工具列表 |
| tool_choice | string | 否 | 工具调用策略 |
| previous_response_id | string | 否 | 多轮对话关联 |
| reasoning | object | 否 | 推理配置 |
推理配置(Reasoning)
| 参数 | 类型 | 说明 |
|---|---|---|
| effort | string | low、medium、high |
| summary | string | 推理摘要 |
示例:
{
"reasoning": {
"effort": "high"
}
}
请求示例
{
"model": "gpt-5",
"input": "解释 MCP 的作用",
"reasoning": {
"effort": "medium"
}
}
成功响应
HTTP Status:200 OK
响应结构
| 字段 | 类型 | 说明 |
|---|---|---|
| id | string | 响应 ID |
| object | string | 固定为 response |
| status | string | 响应状态 |
| model | string | 使用模型 |
| output | array | 输出内容 |
| usage | object | Token 使用统计 |
响应示例
{
"id": "resp_xxx",
"object": "response",
"status": "completed",
"model": "gpt-5",
"output": [
{
"role": "assistant",
"content": [
{
"type": "text",
"text": "MCP 是一种模型上下文协议..."
}
]
}
]
}
错误响应
HTTP Status:400 Bad Request
{
"error": {
"message": "Invalid request",
"type": "invalid_request_error",
"code": "invalid_parameter"
}
}