> ## 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.

# gpt-image-2

> 使用 Images API 调用 gpt-image-2 生成图片

## API 使用方法

<Info>
  gpt-image-2 按成功生成的图片数量按次收费，不按 Token 用量计费。普通用户在控制台调用日志中不会看到 Token 使用量，费用和生成数量仍会正常显示。
</Info>

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

### 请求参数

| 参数       | 类型      | 必填 | 说明                                 |
| -------- | ------- | -- | ---------------------------------- |
| `model`  | string  | 是  | 固定为 `gpt-image-2`                  |
| `prompt` | string  | 是  | 图片生成提示词                            |
| `size`   | string  | 否  | 图片尺寸；缺失、空值或 `auto` 时使用 `1024x1024` |
| `n`      | integer | 否  | 生成数量，默认为 `1`                       |

### cURL 示例

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

curl -sS -X POST "https://api.seeoneapi.com/v1/images/generations" \
  -H "Authorization: Bearer $SEEONE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A clean product photo of a white ceramic mug on a wooden desk, soft natural light.",
    "size": "1024x1024",
    "n": 1
  }'
```

### 尺寸说明

常用尺寸如下：

| 档位 | 尺寸                                  |
| -- | ----------------------------------- |
| 1K | `1024x1024`、`1536x1024`、`1024x1536` |
| 2K | `2048x2048`、`2048x1152`、`1152x2048` |
| 4K | `3840x2160`、`2160x3840`             |

传入其他尺寸时，需要同时满足以下规则：

* 格式为 `宽x高`，建议使用小写字母 `x`
* 宽和高都必须是 `16` 的倍数
* 最长边不小于 `1024`，且不超过 `3840`
* 长短边比例不超过 `3:1`
* 总像素数不超过 `8,294,400`

<Note>
  所有图片生成和编辑结果都只通过响应中的 `data[].url` 返回，不提供 Base64 或 `b64_json` 格式。
</Note>

## 图像编辑

图像编辑接口使用 `multipart/form-data` 上传原图：

| 项目           | 值                     |
| ------------ | --------------------- |
| 请求方法         | `POST`                |
| 请求路径         | `/v1/images/edits`    |
| Content-Type | `multipart/form-data` |

### 编辑参数

| 参数       | 类型      | 必填 | 说明                                |
| -------- | ------- | -- | --------------------------------- |
| `model`  | string  | 是  | 固定为 `gpt-image-2`                 |
| `image`  | file    | 是  | 需要编辑的原图                           |
| `prompt` | string  | 是  | 描述需要修改的内容                         |
| `size`   | string  | 否  | 输出尺寸；编辑接口不会自动处理 `auto`，建议显式传入具体尺寸 |
| `n`      | integer | 否  | 生成数量，默认为 `1`                      |
| `mask`   | file    | 否  | 局部编辑遮罩图                           |

### cURL 示例

```bash theme={null}
curl -sS -X POST "https://api.seeoneapi.com/v1/images/edits" \
  -H "Authorization: Bearer $SEEONE_API_KEY" \
  -F "model=gpt-image-2" \
  -F "image=@source.png" \
  -F "prompt=Keep the main subject and replace the background with a bright modern studio." \
  -F "size=1024x1024" \
  -F "n=1"
```

<Note>
  多参考图编辑时，可重复传入 `image[]`，例如 `-F "image[]=@source.png"` 和 `-F "image[]=@reference.png"`。需要局部编辑时，可额外传入 `-F "mask=@mask.png"`。
</Note>
