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

# GPT-Image-2

GPT Image 2 是 OpenAI 推出的领先图像生成模型，能够快速生成和编辑高质量图像，它支持多种图像尺寸和高保真度的图像输入，支持文生图、图生图。

### 模型参数

* 模型ID：`gpt-image-2`
* 模型价格：你可以在[模型广场](https://geekai.co/models?platform=openai\&type=image)查看最新价格信息
* 调用入口：`https://geekai.co/api/v1/images/generations`
* 模型参数：参考[画图 API 手册](https://docs.geekai.co/cn/api/image/generations)
* API认证：[获取 API KEY](https://docs.geekai.co/cn/docs/quick_start)

<Note>
  不支持画图公共 API 中的以下参数：

  * `negative_prompt`
  * `seed`
  * `strength`
  * `aspect_ratio`
  * `style_preset`

  附：[GPT-Image-2 官方 API 文档](https://developers.openai.com/api/docs/guides/image-generation)
</Note>

GPT-Image-2 的 `size` 值支持满足以下条件的任意尺寸：

* 图片宽、高长度必须是 16 的倍数（整数）；
* 图片宽、高长度不得大于 3840 像素；
* 图片像素总数必须在 655360 到 8294400 之间；
* 图片宽高比不得大于 3:1。

### 模型价格

不同尺寸和质量对应的价格不同，以下是 GPT-Image-2 的价格表：

| 质量（quality） | 尺寸（size）      | 价格（单位：元/张） |
| ----------- | ------------- | ---------- |
| low         | 1024x1024     | 0.045      |
| low         | 1024x1536     | 0.036      |
| low         | 1536x1024     | 0.036      |
| low         | 2048x2048(2K) | 0.09       |
| low         | 2048x1152(2K) | 0.036      |
| low         | 3840x2160(4K) | 0.084      |
| low         | 2160x3840(4K) | 0.084      |
| medium      | 1024x1024     | 0.398      |
| medium      | 1024x1536     | 0.311      |
| medium      | 1536x1024     | 0.311      |
| medium      | 2048x2048(2K) | 0.808      |
| medium      | 2048x1152(2K) | 0.32       |
| medium      | 3840x2160(4K) | 0.755      |
| medium      | 2160x3840(4K) | 0.755      |
| high        | 1024x1024     | 1.59       |
| high        | 1024x1536     | 1.24       |
| high        | 1536x1024     | 1.24       |
| high        | 2048x2048(2K) | 3.231      |
| high        | 2048x1152(2K) | 1.28       |
| high        | 3840x2160(4K) | 3.02       |
| high        | 2160x3840(4K) | 3.02       |

<Note>
  以上只是常见尺寸的价格示例，GPT-Image-2 支持的尺寸非常广泛，实际价格会根据你选择的具体尺寸和质量进行计算。
</Note>

GPT-Image-2 模型参数默认值 `quality` 是 `medium`，`size` 是 `1024x1024`。

使用极客智坊提供的[低价代理渠道](https://docs.geekai.co/cn/docs/model_price)调用时，不同参数对应价格按照价格表x对应的折扣值即可：以高可用默认通道为例，折扣值是 `0.5`，那么生成一张 `size` 为 `1024x1024`、`quality` 为 `medium` 的图片价格是 `0.398 x 0.5 = 0.199` 元，如果生成同样尺寸但 `quality` 为 `high` 的图片价格是 `1.586 x 0.5 = 0.793` 元。其他参数依次类推。

### 文生图片

通过文字描述来生成对应图像：

```bash theme={null}
curl --location --request POST 'https://geekai.co/api/v1/images/generations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--data '{
    "model":"gpt-image-2",
    "prompt":"画一只可爱的小猫在草丛中玩耍"
}'
```

### 以图生图

**单图**

基于已有图片，结合文字指令进行图像编辑，生成新的图像：

```bash theme={null}
curl --location --request POST 'https://geekai.co/api/v1/images/generations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--data '{
    "model":"gpt-image-2",
    "prompt":"修复这张破损的照片",
    "image":"https://static.geekai.co/storage/2025/04/02/broken-picture.jpg"
}'
```

注意，GPT-Image-2 支持图片编辑接口，这里我们借助图片编辑接口实现图生图功能：

<CodeGroup>
  ```bash json theme={null}
  curl --location --request POST 'https://geekai.co/api/v1/images/edits' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer $GEEKAI_API_KEY' \
  --data '{
      "model": "gpt-image-2",
      "prompt": "修复这张破损的照片",
      "image": "https://static.geekai.co/storage/2025/04/02/broken-picture.jpg"
  }'
  ```

  ```bash form theme={null}
  curl --location --request POST 'https://geekai.co/api/v1/images/edits' \
  --header 'Authorization: Bearer $GEEKAI_API_KEY' \
  --form 'model="gpt-image-2"' \
  --form 'prompt="修复这张破损的照片"' \
  --form 'image=@/path/to/your/local/image.jpg'
  ```
</CodeGroup>

<Note>
  `image` 参数支持传入图片链接或图片的 Base64 编码字符串。
</Note>

**多图**

基于多张参考图片，融合它们的风格、元素等特征来生成新图像，如衣裤鞋帽与模特图融合成穿搭图，人物与风景融合为人物风景图等：

```bash theme={null}
curl --location --request POST 'https://geekai.co/api/v1/images/generations' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $GEEKAI_API_KEY' \
--data '{
    "model":"gpt-image-2",
    "prompt": "将图1中的面料应用至图2的服装上，图片比例按照图2来",
    "images": [
        "https://style3d-render.oss-cn-hangzhou.aliyuncs.com/test/针织.jpg",
        "https://style3d-render.oss-cn-hangzhou.aliyuncs.com/test/款式图.jpg"
    ],
    "quality": "high",
    "background": "auto",
    "output_format": "png",
    "response_format": "url",
    "async": true
}'
```

同样地，图片编辑接口也支持多图编辑：

<CodeGroup>
  ```bash json theme={null}
  curl --location --request POST 'https://geekai.co/api/v1/images/edits' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer $GEEKAI_API_KEY' \
  --data '{
      "model": "gpt-image-2",
      "prompt": "将图1中的面料应用至图2的服装上，图片比例按照图2来",
      "images": [
          "https://style3d-render.oss-cn-hangzhou.aliyuncs.com/test/针织.jpg",
          "https://style3d-render.oss-cn-hangzhou.aliyuncs.com/test/款式图.jpg"
      ],
      "quality": "high",
      "background": "auto",
      "output_format": "png",
      "response_format": "url",
      "async": true
  }'
  ```

  ```bash form theme={null}
  curl --location --request POST 'https://geekai.co/api/v1/images/edits' \
  --header 'Authorization: Bearer $GEEKAI_API_KEY' \
  --form 'model="gpt-image-2"' \
  --form 'prompt="将图1中的面料应用至图2的服装上，图片比例按照图2来"' \
  --form 'image[]=@/path/to/your/local/image1.jpg' \
  --form 'image[]=@/path/to/your/local/image2.jpg'
  ```
</CodeGroup>

<Note>
  对于耗时生图任务，可以通过设置 `async` 参数为 `true` 开启异步任务模式。异步任务模式下，画图接口会返回一个 `task_id`，你可以通过轮询 `https://geekai.co/api/v1/images/{task_id}` 来获取图像生成的最新状态，当任务完成后即可获得最终的图像URL，相关细节请参考[异步生图](https://docs.geekai.co/cn/docs/image/txt2img#异步生图)。
</Note>
