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

# GPT Image 2 图像生成

> gpt-image-2 的生成接口、独立请求示例和已测参数范围。

使用 `POST https://code.heihuzi.ai/v1/images/generations`，并显式指定 `model: "gpt-image-2"`。请使用具有图片权限的 API Key。

本页依据 **2026-09-13** 的该模型实际请求与图片结果整理。GPT Image 2.5 Flare / Sunburst 请查看 [2.5 图像生成](/cn/api-reference/images/gpt-image-2.5/generation)。

## 请求示例

设置 `HEIHUZI_API_KEY` 后运行；请求体与上述历史实测一致，响应保存到 `generation.json`。

<RequestExample>
  ```bash theme={null}
  curl --fail-with-body --silent --show-error --max-time 600 \
    --request POST \
    --url https://code.heihuzi.ai/v1/images/generations \
    --header "Authorization: Bearer $HEIHUZI_API_KEY" \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-image-2",
    "prompt": "A simple blue ceramic cup on a white background, centered product photo, no text.",
    "n": 1,
    "size": "1024x1024",
    "quality": "low",
    "output_format": "png"
  }' \
    --output generation.json
  ```
</RequestExample>

## 请求参数

<ParamField body="model" type="string" required>
  填写 `gpt-image-2`。调用此模型时必须显式指定，省略模型会使用 GPT Image 2.5 Flare。
</ParamField>

<ParamField body="prompt" type="string" required>
  描述要生成的画面或对参考图的修改要求。
</ParamField>

<ParamField body="n" type="integer" default="1">
  本页已测单张输出 `1`；省略时也返回一张图片。
</ParamField>

<ParamField body="size" type="string">
  本页已测固定尺寸 `1024x1024`。省略尺寸的历史测试返回 1254×1254；需要固定尺寸时请显式填写。
</ParamField>

<ParamField body="quality" type="string">
  已分别验证 `low`、`medium`、`high`、`auto`，测试使用单张 1024×1024 PNG。
</ParamField>

<ParamField body="output_format" type="string">
  本页已测 `png`，响应图片经解码确认为 PNG。
</ParamField>

## 响应示例

以下为 2026-09-13 该模型的实际响应节选，仅省略图片 base64。`data[].b64_json` 解码后得到图片；客户端应检查 HTTP 状态、错误字段和实际返回图片。

<ResponseExample>
  ```json theme={null}
  {
    "created": 1789276135,
    "background": "opaque",
    "data": [
      {
        "b64_json": "<此处省略真实图片的 base64>",
        "generation_id": "3c7ba4e3-107f-48b6-b599-c30e51b061d1"
      }
    ],
    "output_format": "png",
    "quality": "low",
    "size": "1024x1024",
    "usage": {
      "input_tokens": 23,
      "input_tokens_details": {
        "image_tokens": 0,
        "text_tokens": 23
      },
      "output_tokens": 196,
      "output_tokens_details": {
        "image_tokens": 196,
        "text_tokens": 0
      },
      "total_tokens": 219
    }
  }
  ```
</ResponseExample>

参考图修改见 [GPT Image 2 图像编辑](/cn/api-reference/images/gpt-image-2/edits)。本页列出的已测范围不包含 2.5 的 `xhigh`、`max`、透明输出和流式组合；其他组合未在本页承诺。
