聊天补全(Chat Completions)
该接口用于文本生成和多轮对话。
- 方法:
POST - 路径:
/v1/chat/completions - Base URL:
https://api.unigateway.ai/v1
最小请求
{
"model": "gpt-5.2",
"messages": [
{ "role": "user", "content": "用 3 点说明统一 AI Gateway 的好处。" }
]
}
cURL 示例
curl https://api.unigateway.ai/v1/chat/completions \
-H "Authorization: Bearer $UNIGATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [
{"role": "system", "content": "你是一个简洁的助手。"},
{"role": "user", "content": "写一段从单一供应商迁移到 UniGateway 的说明。"}
],
"temperature": 0.3
}'
关键参数
| 字段 | 类型 | 说明 |
|---|---|---|
model | string | 必须使用 /v1/models 返回的精确值。 |
messages | array | 主流兼容 SDK 通用的消息数组结构。 |
temperature | number | 控制随机性,范围按模型而异。 |
max_tokens | number | 限制最大输出 token。 |
stream | boolean | true 时开启 SSE 流式输出。 |
部分高级参数存在模型家族差异,建议按目标模型实测验证。
响应结构示例
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"model": "gemini-3-pro-preview",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}
]
}