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

# GPT-Image-2.5 · 文生图

> GPT-Image-2.5 Flare / Sunburst · POST /v1/images/generations

## 简介

GPT-Image-2.5 是 OpenAI 的图像生成模型系列，包含注重日常生成速度的 **Flare** 和注重视觉细节的 **Sunburst**。本页通过 `POST /v1/images/generations` 将文本描述转为图片，适用于海报、商品展示、品牌插画、图标和信息图等场景。

两个模型支持 `auto`、`low`、`medium`、`high`、`xhigh`、`max` 六档质量设置，以及 PNG、JPEG、WebP 输出。可通过 `quality`、`size` 和 `background` 调整质量、尺寸与背景；透明背景请配合 PNG 或 WebP。

### 模型选择

| 模型 ID | 适用场景 |
| - | - |
| `gpt-image-2.5-flare` | 快速迭代、交互式生成 |
| `gpt-image-2.5-sunburst` | 复杂布局与细节表现 |

两个模型共用本页的端点、参数和响应结构。示例默认使用 Flare；切换为 Sunburst 时只需替换请求中的 `model`，其他字段按实际需求设置。

## 认证

**Authorization** `string` *required*

Bearer \$GRAVITEX\_API\_KEY

**Content-Type** `string` *required*

application/json

## 请求参数

| 参数 | 类型 | 说明 |
| - | - | - |
| `model` | string | 必填，gpt-image-2.5-flare 或 gpt-image-2.5-sunburst |
| `prompt` | string | 必填，描述要生成的图片内容，最长 32,000 字符 |
| `quality` | string | auto / low / medium / high / xhigh / max；默认 auto |
| `size` | string | auto 或 WxH，宽高为 16 的倍数；受模型尺寸和总像素预算约束 |
| `n` | integer | 1–10 |
| `background` | string | auto / opaque / transparent；透明栅格输出使用 png 或 webp |
| `output_format` | string | png / jpeg / webp；默认 png |
| `output_compression` | integer | 0–100，默认 100，仅用于 JPEG / WebP |
| `moderation` | string | auto / low；默认 auto |
| `safety_identifier` | string | 稳定的终端用户标识，建议哈希化，最长 128 字符；替代 user |
| `stream` | boolean | 默认 false；开启后返回 SSE 事件，不能按普通 JSON 响应解析 |
| `partial_images` | integer | 仅栅格流式输出，0–3，默认 0；表示期望的中间预览数，实际可能更少 |

## 请求示例

示例从环境变量 `GRAVITEX_API_KEY` 读取平台令牌，请先在当前终端设置该变量。文件上传使用 curl 的 `-F` 自动生成 Content-Type 和 boundary，不要手动把 Content-Type 固定成 multipart/form-data。

### 基础生成

```bash theme={null}
curl https://api.gravitex.ai/v1/images/generations \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.5-flare",
  "prompt": "A clean botanical poster with precise typography",
  "quality": "medium",
  "size": "1024x1024"
}'
```

### 透明背景

```bash theme={null}
curl https://api.gravitex.ai/v1/images/generations \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.5-flare",
  "prompt": "A single green botanical icon, isolated on a transparent background",
  "quality": "medium",
  "size": "1024x1024",
  "background": "transparent",
  "output_format": "png"
}'
```

`user` 为兼容旧请求保留，已废弃；新请求使用 safety\_identifier。非空 safety\_identifier 优先，未提供、null 或空字符串时才回退 user。

### 流式输出

```bash theme={null}
curl --no-buffer https://api.gravitex.ai/v1/images/generations \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2.5-flare",
  "prompt": "A simple green botanical illustration",
  "quality": "medium",
  "size": "1024x1024",
  "stream": true,
  "partial_images": 1
}'
```

## 限制与注意事项

auto 为默认值。显式尺寸使用 WxH，宽高均为 16 的倍数，宽高比在 1:3–3:1 之间。image-2 官方指南规定最长边不超过 3840px、总像素为 655,360–8,294,400；2.5 的 API 参考也要求尺寸符合模型的边长和像素预算。2.6（尤其 GIF）的预算请按模型和项目实际支持确认，不直接套用旧模型上限。

本页仅列出官方明确说明的 GPT-Image-2.5 用法，不将 2.6 的 complexity、GIF、SVG 专属说明直接套用到 2.5。通用 API schema 出现某字段，不代表所有模型和渠道都支持。

## 响应示例

下面是非流式响应的结构示意，图片数据和 token 数仅为示例，并非实际生成结果。将 b64\_json 解码为对应格式的文件；不要将 Base64 字符串直接保存为图片。

```json theme={null}
{
  "created": 1794268800,
  "data": [
    {
      "b64_json": "<BASE64_IMAGE_DATA>"
    }
  ],
  "usage": {
    "input_tokens": 100,
    "output_tokens": 824,
    "total_tokens": 924
  }
}
```

若设置 `stream: true`，响应为 SSE 事件流；按事件读取中间预览和最终图片，不能对整个响应直接调用 JSON 解析。

## 响应与计费

本页示例为非流式调用时，图片通过 b64\_json 返回；不要传 response\_format=url 期待图片链接。输入图片和输出图片均有 token 用量；相同 token 单价不代表相同单张费用，需结合实际 usage。

返回 `data[].b64_json` 和 `usage`。图片数据须先 Base64 解码再保存。以下为 OpenAI 官方标准价，不是 GravitexAI 报价。

缓存价格是官方参考费率。官方指南说明，GPT Image 2 / 2.5 的缓存输入优惠仅适用于 Responses API 图像工具，不适用于直接调用本页 Images API（含 edits）；平台实际结算以控制台为准。

| 类型 | 美元 / 1M tokens |
| - | - |
| 文本输入 | \$5.00 |
| 缓存文本输入 | \$1.25 |
| 图片输入 | \$8.00 |
| 缓存图片输入 | \$2.00 |
| 图片输出 | \$30.00 |

## 官方参考

* [Image generation guide](https://developers.openai.com/api/docs/guides/image-generation)
* [API Reference](https://developers.openai.com/api/reference/resources/images/methods/generate)
* [Flare](https://developers.openai.com/api/docs/models/gpt-image-2.5-flare)
* [Sunburst](https://developers.openai.com/api/docs/models/gpt-image-2.5-sunburst)
* [Pricing](https://developers.openai.com/api/docs/pricing)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.