# Grok 4.7 — /chat/completions

OpenAI 兼容的对话补全接口，承载 xAI Grok 4.7 —— 擅长复杂推理、代码与长文档分析的旗舰推理模型。始终开启思考，思考过程在 message.reasoning_content 返回，思考 token 按输出价计入 usage.completion_tokens；max_tokens 只限制正文，不限制思考部分。支持工具调用、JSON Schema 结构化输出、图片输入与流式输出；不支持 stop（返回 400），presence_penalty / frequency_penalty / logit_bias 会被忽略。只需把 model 设为 grok-4.7；目前仅提供 /v1/chat/completions。

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

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

## 请求参数
| 参数 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| `model` | string | 是 | 模型 ID，此处为 grok-4.7。 |
| `messages` | array | 是 | 对话消息数组，每项含 role（system/user/assistant）与 content。content 可为字符串，或由 {type:text} 与 {type:image_url} 组成的数组以识别图片（多模态/Vision）。 |
| `stream` | boolean | 否 | 是否以 SSE 流式返回。默认 false。 |
| `temperature` | number | 否 | 采样温度，0–2，越高越随机。 |
| `max_tokens` | integer | 否 | 最大生成 token 数。 |
| `web_search` | boolean | 否 | 设为 true 开启联网搜索：网关会先用实时搜索补充资料、再让模型作答并附来源链接（也可在 tools 里传 {"type":"web_search"} 触发）。 |

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

## 响应示例
```json
{
  "id": "chatcmpl_xxx",
  "object": "chat.completion",
  "model": "grok-4.7",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning_content": "The user is greeting me, so a short friendly reply fits...",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 42,
    "total_tokens": 51,
    "completion_tokens_details": {"reasoning_tokens": 31}
  }
}
```

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

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