图像编辑
最后更新:2026-11-14
POSThttps://www.sagelib.com/images/edits
图像编辑API,基于现有图像+文本指令,对图像进行局部或整体修改,适用于图片的风格调整、内容添加/删除、局部修改等场景。
接口鉴权方式请参考:API接入与鉴权
当前展示通用接口文档,各模型支持的参数存在差异。请点击下方模型标签查看专属文档。
支持模型:doubao-seedream-4-5-251128doubao-seedream-5-0-260128gpt-image-2.5-flaregpt-image-2.5-sunburstgpt-image-2
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
可选值:multipart/form-data multipart/form-data; boundary=${boundary},boundary由请求工具自动生成 |
Body 参数
| 参数名称 | 描述 |
|---|---|
model string |
默认值:Default model configured on the channel 编辑图像使用的模型名称 |
*prompt string |
图像编辑的核心提示词(如“添加水印”“调整为动漫风格”) |
*image string |
可选值:Common formats such as PNG, JPG 待编辑的图片文件或图片URL,示例如:image=@body-lotion.png、image[]=@body-lotion.png、image=http://xxx/body-lotion.png |
mask string |
可选的遮罩文件,仅一张 |
n integer |
默认值:1 可选值:>0 生成编辑后图像的数量(部分模型仅支持1张,会忽略该字段) |
size string |
可选值:Varies by model 编辑后图像的宽高像素(部分模型仅支持特定分辨率) |
response_format string |
可选值:url、b64_json 编辑后图像的返回格式(部分模型仅支持特定格式,会忽略该字段) |
请求示例
curl -v 'https://www.sagelib.com/images/edits' \
-H "Authorization: Bearer ***" \
-F "image=@test2.png" \
-F "prompt=Add watermark: Technology to the image" \
-F "size=1024x1024"
import requests
base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/images/edits"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
"prompt": "Add watermark: Technology to the image",
"size": "1024x1024"
}
files = {
"image": ("image.bin", open("image.bin", "rb"))
}
response = requests.post(url, headers=headers, data=data, files=files)
print(response.text)
import java.io.*;
import java.net.URI;
import java.net.http.*;
public class LlmStreamClient {
public static void main(String[] args) throws Exception {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/images/edits";
String boundary = "----Boundary" + System.currentTimeMillis();
String CRLF = "\r\n";
StringBuilder sb = new StringBuilder();
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"image\"").append(CRLF).append(CRLF);
sb.append("@test2.png").append(CRLF);
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"prompt\"").append(CRLF).append(CRLF);
sb.append("Add watermark: Technology to the image").append(CRLF);
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"size\"").append(CRLF).append(CRLF);
sb.append("1024x1024").append(CRLF);
sb.append("--").append(boundary).append("--").append(CRLF);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.header("Authorization", "Bearer " + apiKey)
.POST(HttpRequest.BodyPublishers.ofString(sb.toString()))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status Code: " + response.statusCode());
System.out.println(response.body());
}
}
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/images/edits"
var buf bytes.Buffer
writer := multipart.NewWriter(&buf)
_ = writer.WriteField("image", "@test2.png")
_ = writer.WriteField("prompt", "Add watermark: Technology to the image")
_ = writer.WriteField("size", "1024x1024")
writer.Close()
req, err := http.NewRequest("POST", url, &buf)
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", writer.FormDataContentType())
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
响应参数
Body 参数
| 参数名称 | 描述 |
|---|---|
created integer |
编辑后图像的创建时间戳(Unix时间格式) |
data array |
编辑后的图像数组,数组长度与请求参数n一致(部分模型固定为1) |
url string |
编辑后图像的URL地址,仅当response_format=url时返回(必填) |
b64_json string |
编辑后图像内容的Base64编码,仅当response_format=b64_json时返回(必填) |
响应示例
{
"created": 1754372091,
"data": [
{
"url": "https://example.com/generated-image.png"
}
]
}
状态码
| HTTP状态码 | 描述 |
|---|---|
| 200 | 请求成功,返回编辑后的图像数据 |
| 401 | 访问被拒绝,拒绝原因见响应主体。可能原因:缺少Authorization请求头、token无效或过期等 |
| 403 | 访问被拒绝,拒绝原因见响应主体。可能原因:请求主体格式错误、缺少必填参数(如image、prompt)等 |
| 500 | 服务器内部错误,错误原因见响应主体 |
POSThttps://www.sagelib.com/openai/images/edits
OpenAI 直连模式图像编辑API,基于现有图像+文本指令对图像进行局部或整体修改,URL 前缀 /openai,支持 multipart 文件上传或 JSON+图片 URL 两种形式。
接口鉴权方式请参考:API接入与鉴权
当前展示通用接口文档,各模型支持的参数存在差异。请点击下方模型标签查看专属文档。
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
可选值:application/json application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
model string |
可选值:gpt-image-2.5-flare / gpt-image-2.5-sunburst / gpt-image-2 / doubao-seedream-5-0-260128 指定用于图像编辑的模型名 |
prompt string |
图像编辑的文本提示词 |
image string |
待编辑的原始图像 |
mask string |
编辑掩码图像 |
n integer |
默认值:1 可选值:1-10 一次请求生成的图像数量 |
size string |
默认值:1024x1024 可选值:auto / 1024x1024 / 1536x1024 / 1024x1536 (+ custom WxH; gpt-image-2 width/height must be divisible by 16; doubao-seedream-5: e.g. 1k / 2k / 4k) 输出图像尺寸 |
quality string |
默认值:auto 可选值:auto / low / medium / high / xhigh / max (gpt-image-2: auto / low / high) 生成质量档位 |
background string |
默认值:auto 可选值:auto / opaque / transparent 输出图像的背景处理方式 |
output_format string |
默认值:png 可选值:png / jpeg / webp (doubao-seedream-5: jpeg / png etc.) 输出图像编码格式 |
output_compression integer |
默认值:100 可选值:0-100 (jpeg/webp only) 输出图像压缩级别 |
partial_images integer |
默认值:0 可选值:0-3 流式生成过程中回传的中间图像数量 |
stream boolean |
默认值:false 可选值:true、false 是否以流式(SSE)方式返回 |
user string |
调用方标识 |
input_fidelity string |
可选值:high / low 输入图像保真度 |
moderation string |
默认值:auto 可选值:auto / low 内容审核级别 |
response_format string |
响应中图像的返回形式 |
响应参数
Body 参数
| 参数名称 | 描述 |
|---|---|
created integer |
生成时间戳(Unix 秒) |
data array |
图像数组,长度 = n |
b64_json string |
Base64 编码的图像数据(本模型系列不返回 url 字段) |
generation_id string |
本次生成的标识 ID |
usage object |
Token 使用统计 |
input_tokens integer |
输入 token 数(input_tokens_details 含 image_tokens/text_tokens 细分) |
output_tokens integer |
输出 token 数(output_tokens_details 含 image_tokens 细分) |
total_tokens integer |
总 token 数 |
size string |
实际输出尺寸 |
quality string |
实际质量档位 |
background string |
实际背景处理方式 |
output_format string |
实际输出格式 |
状态码
| HTTP状态码 | 描述 |
|---|---|
| 200 | 请求成功 |
| 401 | 访问被拒绝,拒绝原因见响应主体。可能的原因有:缺少Authorization请求头,token错误等。 |
| 403 | 访问被拒绝,拒绝原因见响应主体。可能的原因有:请求主体格式错误、请求主体缺少用户问题等。 |
| 500 | 服务器内部错误,原因见响应主体 |