Chat Completions
/v1/chat/completions 是 OpenAI Chat Completions 兼容入口。OpenAI 分组会走 OpenAI 兼容链路,其他分组会按网关能力做协议转换。
接口说明
| 项目 | 值 |
|---|---|
| Method | POST |
| Path | /v1/chat/completions |
| Content-Type | application/json |
| 认证 | Authorization: Bearer YOUR_API_KEY |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 请求模型。 |
messages | array | 是 | OpenAI Chat Completions 消息数组。 |
stream | boolean | 否 | 是否流式响应。 |
temperature | number | 否 | 采样温度,是否生效取决于所选模型。 |
max_tokens | integer | 否 | 最大输出 token,是否生效取决于所选模型。 |
请求示例
bash
curl https://api.llmapi.site/v1/chat/completions \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "gpt-5.1",
"messages": [
{ "role": "user", "content": "Hello" }
]
}'响应 — 200 OK
json
{
"id": "chatcmpl_123",
"object": "chat.completion",
"model": "gpt-5.1",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 4,
"total_tokens": 16
}
}当 stream 为 true 时,响应使用 OpenAI Chat Completions 兼容的 SSE 分块。
兼容路径
部分客户端使用无 /v1 前缀路径:
text
POST /chat/completions该路径与 /v1/chat/completions 指向同一类网关能力。
错误码
| 状态码 | 原因 |
|---|---|
400 | 请求体、模型名或 messages payload 无效。 |
401 | API Key 缺失或无效。 |
403 | 余额、额度、分组或订阅校验失败。 |
404 | 请求模型或 Chat 兼容路径不可用。 |
429 | 达到频率限制或并发限制。 |
500 / 502 / 503 | 网关或上游服务商失败。 |