POST /v1/chat/completions

ChatCompletions格式

根据对话历史创建模型响应,支持流式和非流式响应。兼容 OpenAI Chat Completions API。

认证

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

请求体参数

参数 类型 必需 说明
model string 是 模型 ID
messages array<object> 是 对话消息列表
temperature number 否 采样温度 (0-2),默认 1
top_p number 否 核采样参数 (0-1),默认 1
n integer 否 生成数量,默认 1
stream boolean 否 是否流式响应,默认 false
max_tokens integer 否 最大生成 Token 数
presence_penalty number 否 存在惩罚 (-2 到 2),默认 0
frequency_penalty number 否 频率惩罚 (-2 到 2),默认 0
tools array<object> 否 工具配置
tool_choice string | object 否 工具选择策略
response_format object 否 响应格式
reasoning_effort string 否 推理强度 (low/medium/high)

请求示例

cURL
curl -X POST "https://your-base-url/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxx" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ],
    "temperature": 0.7,
    "max_tokens": 1000
  }'

响应示例

200 OK
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1677652288,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I assist you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 19,
    "completion_tokens": 10,
    "total_tokens": 29
  }
}
在线测试 直接在此页面测试 API
Authorization
Body