Gemini
Gemini 3.1 Pro Preview · 对话补全
文本 / Gemini / Gemini 3.1 Pro Preview / 对话补全
接口
POST /v1/chat/completions
Content-Type: application/json
Authorization: Bearer $API_KEY
OpenAI 兼容的对话补全接口,支持多轮对话与流式输出。
请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID,固定为 gemini-3.1-pro-preview |
messages | array | 是 | 对话消息列表,每条含 role(system / user / assistant)与 content |
stream | bool | 否 | 是否流式返回(SSE),默认 false |
temperature | number | 否 | 采样温度,越大越随机 |
top_p | number | 否 | 核采样,与 temperature 二选一。范围 0–1 |
max_tokens | int | 否 | 最大生成 token 数 |
n | int | 否 | 生成的候选回复数,默认 1 |
stop | array | 否 | 停止序列;命中任一即停止输出 |
presence_penalty | number | 否 | 对已出现过的 token 施加惩罚以提升新意。范围 -2–2 |
frequency_penalty | number | 否 | 按出现频率惩罚 token 以减少重复。范围 -2–2 |
reasoning_effort | string | 否 | 思考型模型的推理深度:low / medium / high |
tools | array | 否 | 工具 / 函数定义(function calling) |
tool_choice | string/object | 否 | 是否及调用哪个工具:auto / none / 指定工具 |
response_format | object | 否 | 约束输出格式,例如强制输出 JSON 对象 |
extra_body | object | 否 | 厂商专有选项(如 thinking_config),经 extra_body 透传 |
Gemini 走 OpenAI 兼容端点。无法识别的字段会被忽略;Gemini 专有选项(如思考)经 extra_body 传入。
示例
curl https://api.beerouter.ai/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-pro-preview",
"messages": [
{ "role": "user", "content": "你好,介绍一下你自己" }
]
}'
流式
把 stream 设为 true,响应以 SSE 数据块逐条返回,最后以 data: [DONE] 结束。
响应
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1730000000,
"model": "gemini-3.1-pro-preview",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "你好!很高兴见到你……" },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 12, "completion_tokens": 24, "total_tokens": 36 }
}

