# Gemini 3.1 Pro — /chat/completions

OpenAI 兼容的对话补全接口，承载 Google Gemini 3.1 Pro 新一代旗舰多模态模型，支持流式输出与超长上下文。只需把 model 设为 gemini-3.1-pro；默认低推理档，reasoning_effort=high 切换高推理档。该模型会返回思考过程：非流式在 choices[].message.reasoning_content，流式在 choices[].delta.reasoning_content；正文始终只在 content 里，二者不混合，因此只读 content 的老客户端无需任何改动。计费口径：思考 token 按输出价计入 usage.completion_tokens，可在 usage.completion_tokens_details.reasoning_tokens 查看其中的思考部分。内容拦截：Google 会在模型运行前对提示词做一次内容审核，被拦时不产出也不计费；网关会自动调整提示词结构并重试一次，仍被拦才返回错误。若你的提示词长期被拦，可把 system 内容并入第一条 user 消息后重试。

**端点:** `POST https://nezhagate.com/v1/chat/completions`

## 认证
```
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

## 请求参数
| 参数 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `model` | string | 是 | 模型 ID，此处为 gemini-3.1-pro。 |
| `messages` | array | 是 | 对话消息数组，每项含 role（system/user/assistant）与 content。content 可为字符串，或由 {type:text} 与 {type:image_url} 组成的数组以识别图片（多模态/Vision）。 |
| `stream` | boolean | 否 | 是否以 SSE 流式返回。默认 false。流式下思考过程按 choices[].delta.reasoning_content 逐块下发，正文仍在 delta.content，结束时发送 data: [DONE]。注意：流式时上游不单独上报思考 token，reasoning_tokens 显示为 0，但思考已计入 completion_tokens，计费与非流式一致。 |
| `temperature` | number | 否 | 采样温度，0–2，越高越随机。 |
| `max_tokens` | integer | 否 | 最大生成 token 数。 |
| `web_search` | boolean | 否 | 设为 true 开启联网搜索：网关会先用实时搜索补充资料、再让模型作答并附来源链接（也可在 tools 里传 {"type":"web_search"} 触发）。 |
| `reasoning_effort` | string | 否 | 推理档位：low（默认，更快更省）/ high（更深推理，按 Preview 档计价）。也可直接用带后缀的 model 名 gemini-3.1-pro-low / gemini-3.1-pro-high；旧模型名 gemini-3.1-pro-preview 等价于 high 档并保持原价。 |

## 请求示例
```bash
curl https://nezhagate.com/v1/chat/completions -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"model": "gemini-3.1-pro", "messages": [{"role": "user", "content": "Hello"}], "stream": false}'
```

## 响应示例
```json
{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "model": "gemini-3.1-pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning_content": "**My Thought Process** ... (the model summarises its own reasoning)",
        "content": "70"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 48,
    "completion_tokens": 2187,
    "total_tokens": 2235,
    "completion_tokens_details": {"reasoning_tokens": 1371}
  }
}
```

## 图片识别（Vision）
在 messages 的 content 数组里传入图片，即可让模型识别图片内容（看图问答、读图中文字/OCR 等）。image_url 支持公网图片链接，或 base64 内联（data:image/png;base64,...）。多模态模型可用（gpt-5.5、gemini 系列等）。

```bash
curl __BASE__/v1/chat/completions -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"model": "gemini-3.1-pro", "messages": [{"role": "user", "content": [{"type": "text", "text": "What is in this image?"}, {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}]}]}'
```