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

# GPT 图像接口

> OpenAI Images API 兼容格式

使用 OpenAI Images API 兼容格式生成图片，支持 `gpt-image` 系列及 DALL-E 等图像模型。

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://gogogotoken.ai/v1/images/generations \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-image-1",
      "prompt": "A minimalist logo of a giraffe, flat vector style, yellow and brown",
      "n": 1,
      "size": "1024x1024"
    }'
  ```

  ```bash 高清模式 theme={null}
  curl -X POST https://gogogotoken.ai/v1/images/generations \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gpt-image-1",
      "prompt": "Photorealistic close-up of a snow leopard, golden hour",
      "n": 2,
      "size": "1792x1024",
      "quality": "hd"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "created": 1730000000,
    "data": [
      {
        "url": "https://example.com/generated-image.png"
      }
    ]
  }
  ```

  ```json base64 theme={null}
  {
    "created": 1730000000,
    "data": [
      {
        "b64_json": "<base64>"
      }
    ]
  }
  ```
</ResponseExample>

## 接口说明

该接口适合文生图场景。部分模型或渠道可能返回 `b64_json` 而非 `url`，前端需要根据响应字段做对应处理。

<Info>
  完整图像模型列表以 `GET /v1/models` 返回为准，可用范围取决于 API Key 分组权限。
</Info>

## 请求头

<ParamField header="Authorization" type="string" required>
  API Key 鉴权信息，格式为 `Bearer YOUR_API_KEY`。
</ParamField>

<ParamField header="Content-Type" type="string" required>
  固定为 `application/json`。
</ParamField>

## 请求体

<ParamField body="model" type="string" required default="gpt-image-1">
  图像模型 ID，例如 `gpt-image-1`、`dall-e-3`。请以 `GET /v1/models` 返回结果为准。
</ParamField>

<ParamField body="prompt" type="string" required default="A minimalist logo of a giraffe, flat vector style, yellow and brown">
  图片描述。
</ParamField>

<ParamField body="n" type="integer" default={1}>
  生成数量，默认 `1`。不同模型支持的最大数量可能不同。
</ParamField>

<ParamField body="size" type="string" default="1024x1024">
  图片尺寸，例如 `1024x1024`、`1792x1024`。可选值取决于模型。
</ParamField>

<ParamField body="quality" type="string">
  图片质量，例如 `standard`、`hd`。仅在模型支持时生效。
</ParamField>

<ParamField body="response_format" type="string">
  返回格式，例如 `url` 或 `b64_json`。部分模型可能由上游配置决定。
</ParamField>

## 响应体

<ResponseField name="created" type="integer">
  响应创建时间戳。
</ResponseField>

<ResponseField name="data" type="object[]">
  图片结果数组。

  <ResponseField name="url" type="string">
    可访问的图片 URL。
  </ResponseField>

  <ResponseField name="b64_json" type="string">
    base64 编码的图片内容。
  </ResponseField>
</ResponseField>

## 图像编辑

如需图片编辑，请调用 [`POST /v1/images/edits`](/overseas/gpt-image-edits)。该接口支持 `multipart/form-data` 上传原图与蒙版，具体可用性取决于模型与渠道。

## 错误码

| 状态码   | 含义            | 处理建议            |
| ----- | ------------- | --------------- |
| `401` | API Key 无效或未传 | 检查请求头与令牌状态      |
| `403` | 无权限访问目标图像模型   | 检查 API Key 分组权限 |
| `429` | 触发限速          | 降低请求频率或调整套餐     |
| `5xx` | 上游或网关异常       | 稍后重试，并查看控制台日志   |
