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

# 图生图

> GPT Image 2 图生图 —— 基于参考图与提示词编辑图像

使用 GPT Image 2 编辑现有图像。

### 可用模型

`gpt-image-2/image-to-image`

### 价格

按 **分辨率档位 × 张数** 计费，失败不扣费：

| `resolution` | 单价 / 张     |
| ------------ | ---------- |
| `1k`（默认）     | **\$0.02** |
| `2k`         | **\$0.04** |
| `4k`         | **\$0.06** |

总费用 = `n × 单价(resolution)`。

<ParamField body="model" type="string" required>
  `gpt-image-2/image-to-image`
</ParamField>

<ParamField body="callBackUrl" type="string">
  Webhook 回调地址。
</ParamField>

<ParamField body="input" type="object" required>
  <Expandable title="properties" defaultOpen>
    <ParamField body="prompt" type="string" required>
      描述要应用的编辑效果。
    </ParamField>

    <ParamField body="imageUrls" type="string[]" required>
      可公网访问的参考图 HTTPS URL。**仅接受 1 张**。WebP 会自动转码为 JPEG。
    </ParamField>

    <ParamField body="ratio" type="string">
      图像宽高比。13 个可选值：

      `1:1` / `3:2` / `2:3` / `4:3` / `3:4` / `5:4` / `4:5` / `16:9` / `9:16` / `2:1` / `1:2` / `21:9` / `9:21`

      不传时由上游决定（通常贴近输入图比例）。

      <Warning>
        当 `resolution = 4k` 时，`ratio` 仅支持 `16:9` / `9:16` / `2:1` / `1:2` / `21:9` / `9:21`。
      </Warning>
    </ParamField>

    <ParamField body="resolution" type="string">
      输出分辨率档位。可选 `1k` / `2k` / `4k`。默认 `1k`。

      `ratio × resolution` → 实际像素：详见[文生图文档](/cn/api-reference/gpt-image-2/text-to-image)。
    </ParamField>

    <ParamField body="n" type="integer">
      输出变体数量。范围 `1-10`，默认 `1`。账单按 `n × 单价(resolution)` 线性扣费。
    </ParamField>
  </Expandable>
</ParamField>

<RequestExample>
  ```bash 默认（1K） theme={null}
  curl --request POST \
    --url https://api.maxapi.io/api/v1/task/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-image-2/image-to-image",
    "callBackUrl": "https://example.com/webhook",
    "input": {
      "prompt": "把人物风格改成赛博朋克",
      "imageUrls": ["https://example.com/source.jpg"],
      "ratio": "3:4",
      "n": 1
    }
  }'
  ```

  ```bash 4K 输出 theme={null}
  curl --request POST \
    --url https://api.maxapi.io/api/v1/task/submit \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gpt-image-2/image-to-image",
    "callBackUrl": "https://example.com/webhook",
    "input": {
      "prompt": "提升细节并放大到 4K",
      "imageUrls": ["https://example.com/source.jpg"],
      "ratio": "16:9",
      "resolution": "4k"
    }
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 提交成功 theme={null}
  {
    "code": 0,
    "msg": "ok",
    "data": {
      "taskId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
    }
  }
  ```
</ResponseExample>

***

## 获取结果

通过 [Query Task](/cn/api-reference/query-task) 或 Webhook 获取结果。

```json theme={null}
{
  "code": 0,
  "msg": "ok",
  "data": {
    "taskId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "status": "SUCCESS",
    "input": {
      "model": "gpt-image-2/image-to-image",
      "prompt": "把人物风格改成赛博朋克"
    },
    "result": {
      "type": "image",
      "urls": ["https://cdn.maxapi.io/images/.../image-0.png"]
    }
  }
}
```
