Chat Completions
POST /v1/chat/completions
完全兼容 OpenAI Chat Completions API 格式。支持流式(SSE)和非流式两种模式。
请求格式
{
"model": "gpt-5.5",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false,
"max_tokens": 2048,
"temperature": 0.7
}请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID,参见 /models |
messages | array | 是 | 消息列表,支持 system、user、assistant、tool 角色 |
stream | boolean | 否 | 是否启用流式响应(SSE) |
max_tokens | integer | 否 | 最大生成 Token 数 |
temperature | number | 否 | 采样温度,0-2 |
top_p | number | 否 | 核采样参数 |
stop | string/array | 否 | 停止序列 |
tools | array | 否 | 工具定义(Function Calling) |
tool_choice | string | 否 | 工具选择策略 |
响应格式
非流式响应:
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1712345678,
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
}
}流式响应每行格式为 data: {...},以 data: [DONE] 结束。
可用模型
支持所有 Chat Completions 兼容的模型,包括但不限于 GPT 系列、Claude 系列(通过 /v1/messages 获取更完整功能)。
