OpenAI 图像编辑
接口说明:OpenAI Images API /v1/images/edits 的兼容端点(图生图)。请求、响应与错误格式完全遵循 OpenAI 规范:支持 application/json 与 multipart/form-data(可直接上传图片与遮罩文件),返回 OpenAI 原始 ImagesResponse,不使用 AiToEarn 通用响应包裹;图片链接为上游原始返回,不做转存。鉴权使用 Authorization: Bearer <API Key>(OpenAI SDK 默认携带),已有 OpenAI SDK 或生态工具只需替换 baseURL 与 API Key 即可接入,按 AiToEarn 积分计费。
模型取值来自「图像编辑模型」接口返回的 data[n].name。如需 AiToEarn 通用响应格式(code === 0)与转存后的稳定图片链接,请改用「编辑图像」接口。
curl --request POST \
--url https://aitoearn.cn/api/ai/images/edits \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--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."
}
'import requests
url = "https://aitoearn.cn/api/ai/images/edits"
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."
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<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.'
})
};
fetch('https://aitoearn.cn/api/ai/images/edits', 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/images/edits"
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.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<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))
}{
"data": [
{
"url": "string"
}
],
"created": "number",
"size": "string",
"usage": {
"input_tokens": "number",
"output_tokens": "number",
"total_tokens": "number",
"input_tokens_details": {
"text_tokens": "number",
"image_tokens": "number"
},
"output_tokens_details": {
"text_tokens": "number",
"image_tokens": "number"
}
}
}授权
传入从 AiToEarn 获取 API Key。点击前往「API Key 获取教程」。示例:Bearer xxx。
请求体
图片列表
"https://images.unsplash.com/photo-1592194996308-7b43878e84a6?auto=format&fit=crop&w=1024&q=80"
提示词
"Edit the provided image into a cozy realistic scene by placing the cute orange cat beside a sunlit window."
遮罩图片 URL,用于局部重绘(可选)。需为与 image 尺寸一致的 PNG 图片:完全透明(alpha 为 0)的区域表示需要按提示词重绘的部分,不透明区域保持原图不变。不传时对整张图片进行编辑。
生成数量
1 <= x <= 90071992547409911
返回格式
url, b64_json "url"
响应
第三方协议原生响应或 SSE 数据。不使用 AiToEarn 通用响应包裹。
Hide child attributes
Hide child attributes
curl --request POST \
--url https://aitoearn.cn/api/ai/images/edits \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--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."
}
'import requests
url = "https://aitoearn.cn/api/ai/images/edits"
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."
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<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.'
})
};
fetch('https://aitoearn.cn/api/ai/images/edits', 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/images/edits"
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.\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<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))
}{
"data": [
{
"url": "string"
}
],
"created": "number",
"size": "string",
"usage": {
"input_tokens": "number",
"output_tokens": "number",
"total_tokens": "number",
"input_tokens_details": {
"text_tokens": "number",
"image_tokens": "number"
},
"output_tokens_details": {
"text_tokens": "number",
"image_tokens": "number"
}
}
}
