> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hingnet.com.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat 图像能力

> 使用 /v1/chat/completions 生成或编辑图片（面向平台用户）

<Warning>
  **模型分组要求**：此接口仅支持 **经济型** 模型分组下的 `gemini-2.5-flash-image-preview` 模型。\
  创建令牌时，请确保选择 **经济型** 分组，否则将无法使用该图像生成能力。
</Warning>

本页说明如何通过 **Chat Completions** 使用 `gemini-2.5-flash-image-preview` 进行文生图与改图。
该模型适合低延迟原型验证，图像分辨率上限为 **1K**。

## 接口

* `POST /v1/chat/completions`
* （Gemini OpenAI 兼容入口）`POST /v1beta/openai/chat/completions`

## 文生图（非流式）

```bash theme={null}
curl -X POST "$BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash-image-preview",
    "messages": [
      {"role": "user", "content": "生成一张现代感办公室的插画，干净明亮"}
    ]
  }'
```

### 返回结构（示例）

```json theme={null}
{
  "choices": [
    {
      "message": {
        "role": "assistant",
        "content": "![image](https://...)" ,
        "image": [
          {"data": "<BASE64_IMAGE_DATA>"}
        ]
      }
    }
  ]
}
```

<Note>
  若已配置对象存储，平台会尝试返回可访问的 URL（显示在 `message.content` 中）。
  未配置对象存储时，仍会在 `message.image[].data` 返回 base64 图像数据。
</Note>

## 文生图（流式）

```bash theme={null}
curl -N "$BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash-image-preview",
    "messages": [
      {"role": "user", "content": "生成一张雨夜街道的电影感插画"}
    ],
    "stream": true
  }'
```

<Note>
  流式响应中，图片数据会出现在 `choices[].delta.image`（base64）。
</Note>

## 改图（参考图编辑）

```bash theme={null}
curl -X POST "$BASE_URL/v1/chat/completions" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash-image-preview",
    "messages": [
      {
        "role": "user",
        "content": [
          {"type": "text", "text": "将这张图片改成水彩画风格"},
          {"type": "image_url", "image_url": {"url": "https://example.com/input.png"}}
        ]
      }
    ]
  }'
```

## 何时使用 Chat / 何时使用 Images API

* **Chat 接口**：适合将图像生成或编辑作为对话中的一步（多轮交互、同时输出文本+图像）。
* **Images 接口**：需要更强的分辨率控制或批量生成时，建议使用
  `/v1/images/generations` / `/v1/images/edits`（见 [图像生成 (OpenAI 风格)](/gemini/images-openai)）。
