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

# GPT-Image-1.5 图片生成

> - 异步处理模式，返回任务ID用于后续查询
- OpenAI GPT Image 1.5，支持文生图 / 图生图（参考图编辑、多图合成）
- 传入 image_url 时自动走图生图，不传则为文生图
- 支持 3 种图片比例：1:1 / 3:2 / 2:3，通过 aspect_ratio 字段传入
- 支持 quality 质量档位：medium（默认，更快）/ high（更慢，细节更丰富）
- 参考图最多 16 张，支持 URL 与 base64 混填
- 每次请求返回 1 张图；不支持 resolution / size / 透明背景
- 提交的 prompt 会经过平台敏感词 / 安全审核，违规内容会被直接拒绝


export const apiKeyUrl = 'https://aireiter.com/keys';

## Authorizations

<ParamField header="Authorization" type="string" required>
  所有接口均需要使用Bearer Token进行认证

  获取 API Key：

  访问 <a href={apiKeyUrl} target="_blank">API Key 管理页面</a> 获取您的 API Key

  使用时在请求头中添加：

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" required>
  模型名称

  固定值：`"gpt_image_1_5"`
</ParamField>

<ParamField body="params" type="object" required>
  模型参数对象

  <Expandable title="params 对象属性">
    <ParamField body="prompt" type="string" required>
      图像生成的文本描述

      * 支持中英文，建议详细描述
      * 图生图时写清楚「要改什么」和「哪些保持不变」（如人物面部、姿势、背景）
      * 需要在图中出现的文字请用引号括起来
      * 提交前会经过平台敏感词 / 安全审核，命中违规内容会直接返回错误
    </ParamField>

    <ParamField body="image_url" type="string[]">
      参考图数组，传入后走图生图模式；不传则为文生图

      * 最多 16 张参考图
      * 单张不超过 10MB，支持 jpeg、png、webp
      * 支持以下两种格式：
        1. 公开可访问的 URL
        2. Base64 编码格式
           * 必须使用完整的 Data URI 格式：`data:image/{格式};base64,{base64数据}`
           * 示例：`data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABg...`
           * ⚠️ 注意：必须包含 `data:image/jpeg;base64,` 前缀部分
    </ParamField>

    <ParamField body="aspect_ratio" type="string" default="1:1">
      图像生成的比例

      支持以下取值：

      * `1:1` - 正方形（默认）
      * `3:2` - 横版
      * `2:3` - 竖版

      <Warning>
        仅支持以上 3 个取值；传入其他比例（如 `16:9`、`auto`）或像素尺寸（如 `1024x1024`）会直接报错
      </Warning>
    </ParamField>

    <ParamField body="quality" type="string" default="medium">
      图片质量档位

      * `medium` - 均衡，出图更快（默认）
      * `high` - 更慢，细节更丰富，适合定稿

      建议先用 `medium` 调试 prompt 和构图，确定后再用 `high` 出最终图。不同档位的计费不同，以提交响应中的 `estimated_credits` 为准。
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="out_task_id" type="string" required>
  发起方任务ID

  用户自定义的任务标识，必填
</ParamField>

## 使用说明

* **文生图 / 图生图自动切换**：不传 `image_url` 为文生图；传入 1\~16 张参考图即为图生图，可用于局部修改、换装、换背景、风格转换和多图合成。
* **两种模式参数一致**：文生图与图生图使用同一组参数，按 `quality` 档位计费。
* **输出尺寸**：由 `aspect_ratio` 与 `quality` 共同决定，实际像素以返回图片为准；如需 1K / 2K / 4K 或更多比例，请使用 [GPT-Image-2](/zh/api-reference/images/gpt-image-2/generation)。
* **失败不扣费**：任务失败时不会扣除积分。

## Response

<ResponseField name="out_task_id" type="string">
  发起方任务ID，可用于查询结果
</ResponseField>

<ResponseField name="status" type="string">
  初始状态，固定为 `"pending"`
</ResponseField>

<ResponseField name="estimated_credits" type="number">
  预估消耗积分，随 `quality` 档位变化
</ResponseField>

<ResponseField name="created_at" type="string">
  创建时间（ISO 格式）
</ResponseField>

<RequestExample>
  ```bash cURL（文生图） theme={null}
  curl --request POST \
    --url https://aireiter.com/api/openapi/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gpt_image_1_5",
      "params": {
        "prompt": "一张复古旅行海报，大标题写着 \"VISIT KYOTO\"，寺庙与樱花",
        "aspect_ratio": "2:3",
        "quality": "high"
      },
      "out_task_id": "my_task_123456"
    }'
  ```

  ```bash cURL（图生图） theme={null}
  curl --request POST \
    --url https://aireiter.com/api/openapi/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gpt_image_1_5",
      "params": {
        "prompt": "把背景换成阳光海滩，人物保持不变",
        "image_url": ["https://example.com/person.jpg"],
        "aspect_ratio": "3:2",
        "quality": "medium"
      },
      "out_task_id": "my_task_edit_001"
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://aireiter.com/api/openapi/submit"

  payload = {
      "model": "gpt_image_1_5",
      "params": {
          "prompt": "把背景换成阳光海滩，人物保持不变",
          "image_url": ["https://example.com/person.jpg"],
          "aspect_ratio": "3:2",
          "quality": "medium"
      },
      "out_task_id": "my_task_123456"
  }

  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }

  response = requests.post(url, json=payload, headers=headers)

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const url = "https://aireiter.com/api/openapi/submit";

  const payload = {
    model: "gpt_image_1_5",
    params: {
      prompt: "把背景换成阳光海滩，人物保持不变",
      image_url: ["https://example.com/person.jpg"],
      aspect_ratio: "3:2",
      quality: "medium"
    },
    out_task_id: "my_task_123456"
  };

  const headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  };

  fetch(url, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(payload)
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "io/ioutil"
      "net/http"
  )

  func main() {
      url := "https://aireiter.com/api/openapi/submit"

      payload := map[string]interface{}{
          "model": "gpt_image_1_5",
          "params": map[string]interface{}{
              "prompt":       "把背景换成阳光海滩，人物保持不变",
              "image_url":    []string{"https://example.com/person.jpg"},
              "aspect_ratio": "3:2",
              "quality":      "medium",
          },
          "out_task_id": "my_task_123456",
      }

      jsonData, _ := json.Marshal(payload)

      req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", "Bearer <token>")
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      body, _ := ioutil.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```

  ```java Java theme={null}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;

  public class Main {
      public static void main(String[] args) throws Exception {
          String url = "https://aireiter.com/api/openapi/submit";

          String payload = """
          {
            "model": "gpt_image_1_5",
            "params": {
              "prompt": "把背景换成阳光海滩，人物保持不变",
              "image_url": ["https://example.com/person.jpg"],
              "aspect_ratio": "3:2",
              "quality": "medium"
            },
            "out_task_id": "my_task_123456"
          }
          """;

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create(url))
              .header("Authorization", "Bearer <token>")
              .header("Content-Type", "application/json")
              .POST(HttpRequest.BodyPublishers.ofString(payload))
              .build();

          HttpResponse<String> response = client.send(request,
              HttpResponse.BodyHandlers.ofString());

          System.out.println(response.body());
      }
  }
  ```

  ```php PHP theme={null}
  <?php

  $url = "https://aireiter.com/api/openapi/submit";

  $payload = [
      "model" => "gpt_image_1_5",
      "params" => [
          "prompt" => "把背景换成阳光海滩，人物保持不变",
          "image_url" => ["https://example.com/person.jpg"],
          "aspect_ratio" => "3:2",
          "quality" => "medium"
      ],
      "out_task_id" => "my_task_123456"
  ];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "Authorization: Bearer <token>",
      "Content-Type: application/json"
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ?>
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
      "statusCode": 200,
      "message": "",
      "data": {
          "out_task_id": "my_task_123456",
          "status": "pending",
          "created_at": "2026-09-24T06:33:30.012Z"
      }
  }
  ```

  ```json 400 theme={null}
  {
      "statusCode": 400,
      "message": "请求参数无效",
      "ok": false
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "身份验证失败，请检查您的API密钥"
    }
  }
  ```

  ```json 433 theme={null}
  {
    "error": {
      "code": 433,
      "message": "账户余额不足，请充值后再试"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "服务器内部错误，请稍后重试"
    }
  }
  ```
</ResponseExample>
