POST /v1/responses

Responses格式

OpenAI Responses API,支持多轮对话、工具调用和推理能力。

认证

使用 Bearer Token 认证,格式:Authorization: Bearer sk-xxxxxx

请求体参数

参数 类型 必需 说明
model string 是 模型标识符
input string | array<object> 否 输入内容(字符串或消息数组)
instructions string 否 系统指令
max_output_tokens integer 否 最大生成 token 数
temperature number 否 采样温度
top_p number 否 核采样参数
stream boolean 否 是否启用流式响应
tools array<object> 否 可用工具(函数调用)
tool_choice string | object 否 工具选择策略
reasoning object 否 推理配置
previous_response_id string 否 前一条响应 ID(用于上下文)
truncation string 否 截断策略:auto 或 disabled

请求示例

cURL
curl -X POST "https://your-base-url/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxx" \
  -d '{
    "model": "gpt-4o",
    "input": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "What is the weather like?"
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "Get the current weather",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {"type": "string"}
            }
          }
        }
      }
    ]
  }'

响应示例

200 OK
{
  "id": "resp_abc123",
  "object": "response",
  "created_at": 1699062912,
  "status": "completed",
  "model": "gpt-4o",
  "output": [
    {
      "type": "message",
      "id": "msg_abc123",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "text",
          "text": "I'd be happy to help you check the weather. Could you please tell me your location?"
        }
      ]
    }
  ],
  "usage": {
    "prompt_tokens": 45,
    "completion_tokens": 20,
    "total_tokens": 65
  }
}
在线测试 直接在此页面测试 API
Authorization
Body