编辑图像
接口说明:同步编辑图像,基于参考图与指令进行编辑。
调用本接口前,请先请求「图像编辑模型」接口(GET /api/ai/models/image/edit),获取当前可用的模型列表及各模型支持的尺寸、最大输入图片数与价格,再据此填写本接口参数。
图像编辑为图生图:必须传入参考图片 image,按提示词在其基础上修改、重绘或风格化。如需仅用文字生成全新图像(文生图),请使用「生成图像」接口。
如已在使用 OpenAI SDK 或生态工具,可改用 OpenAI 兼容端点「OpenAI 图像编辑」。
curl --request POST \
--url https://aitoearn.cn/api/ai/image/edit \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"model": "gpt-image-2",
"image": "https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80",
"prompt": "Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style."
}
'import requests
url = "https://aitoearn.cn/api/ai/image/edit"
payload = {
"model": "gpt-image-2",
"image": "https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80",
"prompt": "Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style."
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-image-2',
image: 'https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80',
prompt: 'Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style.'
})
};
fetch('https://aitoearn.cn/api/ai/image/edit', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/image/edit"
payload := strings.NewReader("{\n \"model\": \"gpt-image-2\",\n \"image\": \"https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80\",\n \"prompt\": \"Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"code": 0,
"message": "请求成功",
"data": {
"created": 1,
"list": [
{
"url": "string",
"b64_json": "string",
"revised_prompt": "string"
}
],
"usage": {
"input_tokens": 1,
"output_tokens": 1,
"total_tokens": 1
},
"background": "string",
"output_format": "string",
"quality": "string",
"size": "string"
}
}授权
需要从 AiToEarn 获取 API Key。点击前往「API Key 获取教程」。
请求体
原始图片。支持单个图片 URL、data URL 或图片 URL 数组;当前 gpt-image-2 最多支持 14 张输入图片。
"https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80"
编辑描述
1 - 4000"Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style."
遮罩图片 URL,用于局部重绘(可选)。需为与 image 尺寸一致的 PNG 图片:完全透明(alpha 为 0)的区域表示需要按提示词重绘的部分,不透明区域保持原图不变。不传时对整张图片进行编辑。
生成图片数量
1 <= x <= 11
返回格式
url, b64_json "url"
响应
请求已被服务处理。业务是否成功以响应体 code === 0 为准。
业务状态码。0 表示成功,非 0 表示业务错误。
响应消息。
Hide child attributes
Hide child attributes
创建时间戳
背景
输出格式
质量档位
图片尺寸
请求 ID。
错误响应时间戳,Unix 毫秒。
curl --request POST \
--url https://aitoearn.cn/api/ai/image/edit \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"model": "gpt-image-2",
"image": "https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80",
"prompt": "Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style."
}
'import requests
url = "https://aitoearn.cn/api/ai/image/edit"
payload = {
"model": "gpt-image-2",
"image": "https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80",
"prompt": "Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style."
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'gpt-image-2',
image: 'https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80',
prompt: 'Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style.'
})
};
fetch('https://aitoearn.cn/api/ai/image/edit', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/image/edit"
payload := strings.NewReader("{\n \"model\": \"gpt-image-2\",\n \"image\": \"https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80\",\n \"prompt\": \"Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window. Preserve its orange fur, seated pose, and facial expression, enhance the soft natural light, add warm tones and subtle detail, and maintain a realistic photography style.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"code": 0,
"message": "请求成功",
"data": {
"created": 1,
"list": [
{
"url": "string",
"b64_json": "string",
"revised_prompt": "string"
}
],
"usage": {
"input_tokens": 1,
"output_tokens": 1,
"total_tokens": 1
},
"background": "string",
"output_format": "string",
"quality": "string",
"size": "string"
}
}
