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

# 图片编辑

> 上传图片并按提示词编辑

# 图片编辑

使用 OpenAI Images Edit 兼容格式编辑图片。请求支持 `multipart/form-data` 文件上传，也支持 JSON 中传图片资源地址。

<Info>
  JSON 请求里的图片字段可以直接传资源字符串：公网 URL、`data:image/<format>;base64,<data>` 或 `asset://asset_xxx`。需要在提示词中引用某张素材时，使用 `{ "uri": "...", "label": "原图" }`。本地文件可直接使用 `multipart/form-data` 上传，也可以先调用 [上传资源](/llm-gateway/api/assets-upload) 获取 `asset_uri` 后再提交 JSON。
</Info>

## 请求参数

<ParamField body="model" type="string" required>
  图片编辑模型 ID
</ParamField>

<ParamField body="image" type="file | string" required>
  待编辑图片。`multipart/form-data` 请求中使用文件；JSON 请求中可传资源字符串：公网 URL、data URL 或 `asset://asset_xxx`。需要在 `prompt` 中引用时，可传 `{ "uri": "...", "label": "原图" }`
</ParamField>

<ParamField body="images" type="array">
  多张待编辑图片。数组元素支持与 `image` 相同的 JSON 写法；每个对象可以设置不同 `label`
</ParamField>

<ParamField body="mask" type="file | string">
  蒙版图片。支持文件、公网 URL、data URL 和 `asset://asset_xxx`
</ParamField>

<ParamField body="prompt" type="string" required>
  编辑提示词
</ParamField>

<ParamField body="size" type="string">
  输出图片尺寸，例如 `1024x1024`
</ParamField>

<ParamField body="n" type="integer">
  生成图片数量
</ParamField>

## 响应参数

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

<ResponseField name="data" type="array">
  编辑结果列表

  <Expandable title="data">
    <ResponseField name="url" type="string">
      图片访问地址
    </ResponseField>
  </Expandable>
</ResponseField>

## 代码示例

<CodeGroup>
  ```python Python theme={null}
  import requests

  url = "https://api.chenyu.cn/v1/images/edits"
  headers = {"Authorization": "Bearer your_api_key"}
  data = {
      "model": "doubao-seedream-5-0-lite-260128",
      "prompt": "把背景改成浅蓝色，保持主体不变",
      "size": "1024x1024"
  }
  files = {
      "image": open("input.png", "rb")
  }

  response = requests.post(url, headers=headers, data=data, files=files)
  print(response.json()["data"][0]["url"])
  ```

  ```javascript JavaScript theme={null}
  const axios = require('axios');
  const fs = require('fs');
  const FormData = require('form-data');

  const form = new FormData();
  form.append('model', 'doubao-seedream-5-0-lite-260128');
  form.append('prompt', '把背景改成浅蓝色，保持主体不变');
  form.append('size', '1024x1024');
  form.append('image', fs.createReadStream('input.png'));

  axios.post('https://api.chenyu.cn/v1/images/edits', form, {
    headers: {
      Authorization: 'Bearer your_api_key',
      ...form.getHeaders()
    }
  }).then((response) => {
    console.log(response.data.data[0].url);
  });
  ```

  ```curl cURL theme={null}
  curl -X POST "https://api.chenyu.cn/v1/images/edits" \
    -H "Authorization: Bearer your_api_key" \
    -F "model=doubao-seedream-5-0-lite-260128" \
    -F "prompt=把背景改成浅蓝色，保持主体不变" \
    -F "size=1024x1024" \
    -F "image=@input.png"
  ```
</CodeGroup>

## JSON 图片资源示例

```json theme={null}
{
  "model": "doubao-seedream-5-0-lite-260128",
  "prompt": "把背景改成浅蓝色，保持主体不变",
  "size": "1024x1024",
  "image": "asset://asset_input_image"
}
```

需要在提示词里明确引用素材时：

```json theme={null}
{
  "model": "doubao-seedream-5-0-lite-260128",
  "prompt": "保留 @原图 的主体，把背景改成浅蓝色",
  "size": "1024x1024",
  "image": {
    "uri": "asset://asset_input_image",
    "label": "原图"
  }
}
```

## 响应示例

```json theme={null}
{
  "created": 1780000000,
  "data": [
    {
      "url": "https://example.com/edited.png"
    }
  ]
}
```
