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

# 图生图

> 使用 GPT Image 2.5 根据一张或多张参考图片生成新图片。

使用 `gpt-image-2.5` 根据一张或多张参考图片生成新图片。图片通过 `images` 数组传入，支持单张或多张参考图。

## 请求

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl --request POST \
    --url https://xcompute.us/v1/images/edits \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "gpt-image-2.5",
      "prompt": "小狗换成小猫",
      "response_format": "url",
      "size": "1024x1024",
      "images": ["https://example.com/source.png"],
      "n": 1
    }'
  ```

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

  response = requests.post(
      "https://xcompute.us/v1/images/edits",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json",
      },
      json={
          "model": "gpt-image-2.5",
          "prompt": "小狗换成小猫",
          "response_format": "url",
          "size": "1024x1024",
          "images": ["https://example.com/source.png"],
          "n": 1,
      },
      timeout=300,
  )
  response.raise_for_status()
  print(response.json()["data"][0]["url"])
  ```
</RequestExample>

## 参数

<ParamField header="Authorization" type="string" required>
  Bearer Token，例如 `Authorization: Bearer YOUR_API_KEY`。
</ParamField>

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

<ParamField body="model" type="string" default="gpt-image-2.5" required>
  固定填写 `gpt-image-2.5`。
</ParamField>

<ParamField body="prompt" type="string" required>
  图像编辑提示词，例如需要替换、添加、删除或修改的内容。
</ParamField>

<ParamField body="size" type="string" default="1024x1024">
  输出尺寸。可用值见下方的[支持尺寸](#支持尺寸)。
</ParamField>

<ParamField body="response_format" type="string" default="url">
  返回格式。目前仅支持 `url`。
</ParamField>

<ParamField body="images" type="array[string]" required>
  参考图片 URL 数组，支持单张或多张图片。URL 必须可以被 Xcompute 服务端访问。
</ParamField>

<ParamField body="n" type="integer" default="1">
  生成数量，范围为 `1` 到 `4`。
</ParamField>

## 支持尺寸

| 档位 | 支持的 `size` |
| - | - |
| 标准 | `1024x1024`、`1536x1024`、`1024x1536`、`1024x1365`、`1365x1024`、`1088x1920`、`1920x1088` |
| 高分辨率 | `2048x2048`、`1712x2560`、`2560x1712`、`2048x1536`、`1536x2048`、`1152x2048`、`2048x1152`、`2880x2880`、`2560x3840`、`3840x2560`、`2880x3840`、`3840x2880`、`2160x3840`、`3840x2160` |

## 成功响应

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

使用 `n` 大于 `1` 时，遍历 `data` 数组读取全部图片。图片 URL 可能具有有效期，请及时下载并保存。
