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

# Gemini 图片生成

> 使用 Chat Completions API 或 Gemini 原生接口调用 Gemini 图片生成模型

## 可用模型

SeeOneAPI 提供以下 Gemini 图片生成模型：

| 模型                            | 定位   | imageSize 上限 | 特点           |
| ----------------------------- | ---- | ------------ | ------------ |
| `gemini-3-pro-image`          | 旗舰画质 | `4K`         | 质量最高，适合专业级出图 |
| `gemini-3.1-flash-image`      | 均衡   | `2K`         | 质量与速度的平衡     |
| `gemini-2.5-flash-image`      | 快速   | `2K`         | 速度快，适合批量生成   |
| `gemini-3.1-flash-lite-image` | 极致速度 | `1K`         | 速度最快，适合实时场景  |

模型都按 Token 用量计费，具体单价以 [模型广场](https://www.seeoneapi.com/pricing) 为准。

## 调用方式

Gemini 图片生成模型**不是传统的 Images API**（`/v1/images/generations`），而是具备图片输出能力的对话模型。支持两种调用方式：

### 方式一：Chat Completions API（推荐）

使用 OpenAI 兼容的 Chat Completions 接口，通过 `extra_body` 传递 Gemini 原生图片配置：

| 项目           | 值                                 |
| ------------ | --------------------------------- |
| Base URL     | `https://api.seeoneapi.com`       |
| 请求方法         | `POST`                            |
| 请求路径         | `/v1/chat/completions`            |
| 认证方式         | `Authorization: Bearer <API_KEY>` |
| Content-Type | `application/json`                |

#### 请求参数

| 参数                                            | 类型     | 必填 | 说明                          |
| --------------------------------------------- | ------ | -- | --------------------------- |
| `model`                                       | string | 是  | 模型名称，如 `gemini-3-pro-image` |
| `messages`                                    | array  | 是  | 对话消息，格式同 Chat Completions   |
| `extra_body.google.image_config.aspect_ratio` | string | 否  | 画面宽高比，默认 `1:1`              |
| `extra_body.google.image_config.image_size`   | string | 否  | 输出画质，默认 `1K`                |

#### extra\_body 说明

`extra_body` 是与请求体平级的 JSON 字段，用于传递 Gemini 原生的生成配置。`image_config` 支持的参数：

| 参数             | 说明    | 可选值                                 |
| -------------- | ----- | ----------------------------------- |
| `aspect_ratio` | 画面宽高比 | `1:1`, `3:2`, `2:3`, `9:16`, `16:9` |
| `image_size`   | 输出画质  | `1K`, `2K`, `4K`（因模型上限而异）           |

<Note>
  传入的 `image_size` 不能超过模型支持的上限，否则 API 会返回错误或自动降级。
</Note>

#### cURL 示例

```bash theme={null}
export SEEONE_API_KEY="你的 SeeOneAPI Key"

curl -sS -X POST "https://api.seeoneapi.com/v1/chat/completions" \
  -H "Authorization: Bearer $SEEONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3-pro-image",
    "messages": [
      {
        "role": "user",
        "content": "A serene mountain lake at sunrise, mist rising from the water, photorealistic style."
      }
    ],
    "extra_body": {
      "google": {
        "image_config": {
          "aspect_ratio": "16:9",
          "image_size": "2K"
        }
      }
    }
  }'
```

#### 纯图片输出

如果只需要生成图片、不需要文字回复，可以在 `extra_body` 中额外指定 `response_modalities`：

```bash theme={null}
curl -sS -X POST "https://api.seeoneapi.com/v1/chat/completions" \
  -H "Authorization: Bearer $SEEONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.1-flash-image",
    "messages": [
      {
        "role": "user",
        "content": "A cute orange tabby kitten sitting on a windowsill."
      }
    ],
    "extra_body": {
      "google": {
        "response_modalities": ["IMAGE"],
        "image_config": {
          "aspect_ratio": "1:1",
          "image_size": "1K"
        }
      }
    }
  }'
```

<Note>
  Chat Completions 模式下，生成的图片会以 Markdown 内联图片格式 `![image](data:image/png;base64,...)` 嵌入在响应的 `choices[].message.content` 中。
</Note>

### 方式二：Gemini 原生 API

直接使用 Gemini 的 `generateContent` 接口：

| 项目           | 值                                        |
| ------------ | ---------------------------------------- |
| Base URL     | `https://api.seeoneapi.com`              |
| 请求方法         | `POST`                                   |
| 请求路径         | `/v1beta/models/{model}:generateContent` |
| 认证方式         | `Authorization: Bearer <API_KEY>`        |
| Content-Type | `application/json`                       |

#### 请求参数

| 参数                                         | 类型     | 必填 | 说明                                    |
| ------------------------------------------ | ------ | -- | ------------------------------------- |
| `contents`                                 | array  | 是  | 对话内容，包含 `role` 和 `parts`              |
| `generationConfig.responseModalities`      | array  | 是  | 输出模式，`["IMAGE"]` 或 `["TEXT","IMAGE"]` |
| `generationConfig.imageConfig.aspectRatio` | string | 否  | 画面宽高比，默认 `1:1`                        |
| `generationConfig.imageConfig.imageSize`   | string | 否  | 输出画质，默认 `1K`                          |

#### cURL 示例

```bash theme={null}
export SEEONE_API_KEY="你的 SeeOneAPI Key"

curl -sS -X POST "https://api.seeoneapi.com/v1beta/models/gemini-3.1-flash-image:generateContent" \
  -H "Authorization: Bearer $SEEONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "A watercolor painting of cherry blossoms in full bloom."}]
      }
    ],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "aspectRatio": "1:1",
        "imageSize": "2K"
      }
    }
  }'
```

#### 响应格式

Gemini 原生接口返回的图片在 `candidates[].content.parts[].inlineData` 中：

```json theme={null}
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "iVBORw0KGgoAAAANSUhEUgAA..."
            }
          }
        ]
      }
    }
  ]
}
```

## 尺寸与宽高比对照

| 传统尺寸                    | aspectRatio |
| ----------------------- | ----------- |
| `1024x1024`、`2048x2048` | `1:1`       |
| `1536x1024`             | `3:2`       |
| `1024x1536`             | `2:3`       |
| `1024x1792`             | `9:16`      |
| `1792x1024`             | `16:9`      |

也可以直接传比例值，如 `"3:2"`、`"16:9"` 等。

## 模型选择建议

| 场景           | 推荐模型                               |
| ------------ | ---------------------------------- |
| 海报 / 高清壁纸    | `gemini-3-pro-image` (4K)          |
| 社媒配图 / 博客插图  | `gemini-3.1-flash-image` (2K)      |
| 批量生成 / 工作流   | `gemini-2.5-flash-image` (2K)      |
| 实时生成 / 聊天机器人 | `gemini-3.1-flash-lite-image` (1K) |

<Note>
  Gemini 图片生成模型都具备文字渲染能力，适合需要在图片中生成清晰文字的场合。同时支持多轮对话修改图片——在同一次会话中继续发送消息即可对前一张图进行调整。
</Note>
