OpenAI Images 兼容图像编辑
curl --request POST \
--url https://www.geeknow.top/v1/images/edits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"image": {},
"prompt": "<string>",
"model": "<string>",
"mask": {},
"n": 123,
"size": "<string>",
"quality": "<string>",
"watermark": true
}
'import requests
url = "https://www.geeknow.top/v1/images/edits"
payload = {
"image": {},
"prompt": "<string>",
"model": "<string>",
"mask": {},
"n": 123,
"size": "<string>",
"quality": "<string>",
"watermark": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
image: {},
prompt: '<string>',
model: '<string>',
mask: {},
n: 123,
size: '<string>',
quality: '<string>',
watermark: true
})
};
fetch('https://www.geeknow.top/v1/images/edits', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.geeknow.top/v1/images/edits",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'image' => [
],
'prompt' => '<string>',
'model' => '<string>',
'mask' => [
],
'n' => 123,
'size' => '<string>',
'quality' => '<string>',
'watermark' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.geeknow.top/v1/images/edits"
payload := strings.NewReader("{\n \"image\": {},\n \"prompt\": \"<string>\",\n \"model\": \"<string>\",\n \"mask\": {},\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"watermark\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}HttpResponse<String> response = Unirest.post("https://www.geeknow.top/v1/images/edits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": {},\n \"prompt\": \"<string>\",\n \"model\": \"<string>\",\n \"mask\": {},\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"watermark\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.geeknow.top/v1/images/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"image\": {},\n \"prompt\": \"<string>\",\n \"model\": \"<string>\",\n \"mask\": {},\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"watermark\": true\n}"
response = http.request(request)
puts response.read_body{
"created": 1735689600,
"data": [
{
"url": "https://.../images/edit-abc123.png",
"revised_prompt": "把背景改成科技感办公室,保留主体构图"
}
]
}
{
"error": {
"message": "failed to parse image edit form request",
"type": "invalid_request_error",
"param": "",
"code": "invalid_request"
}
}
{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "",
"code": "invalid_api_key"
}
}
{
"error": {
"message": "用户额度不足",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}
{
"error": {
"message": "当前请求频率过高,请稍后再试",
"type": "new_api_error",
"param": "",
"code": "too_many_requests"
}
}
{
"error": {
"message": "bad response body",
"type": "new_api_error",
"param": "",
"code": "bad_response_body"
}
}
OpenAI Images 兼容
OpenAI Images 兼容图像编辑
使用 POST /v1/images/edits 或 POST /v1/edits 基于已有图片执行编辑、局部重绘和图生图。
POST
https://www.geeknow.top
/
v1
/
images
/
edits
OpenAI Images 兼容图像编辑
curl --request POST \
--url https://www.geeknow.top/v1/images/edits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"image": {},
"prompt": "<string>",
"model": "<string>",
"mask": {},
"n": 123,
"size": "<string>",
"quality": "<string>",
"watermark": true
}
'import requests
url = "https://www.geeknow.top/v1/images/edits"
payload = {
"image": {},
"prompt": "<string>",
"model": "<string>",
"mask": {},
"n": 123,
"size": "<string>",
"quality": "<string>",
"watermark": True
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
image: {},
prompt: '<string>',
model: '<string>',
mask: {},
n: 123,
size: '<string>',
quality: '<string>',
watermark: true
})
};
fetch('https://www.geeknow.top/v1/images/edits', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://www.geeknow.top/v1/images/edits",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'image' => [
],
'prompt' => '<string>',
'model' => '<string>',
'mask' => [
],
'n' => 123,
'size' => '<string>',
'quality' => '<string>',
'watermark' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://www.geeknow.top/v1/images/edits"
payload := strings.NewReader("{\n \"image\": {},\n \"prompt\": \"<string>\",\n \"model\": \"<string>\",\n \"mask\": {},\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"watermark\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}HttpResponse<String> response = Unirest.post("https://www.geeknow.top/v1/images/edits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"image\": {},\n \"prompt\": \"<string>\",\n \"model\": \"<string>\",\n \"mask\": {},\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"watermark\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://www.geeknow.top/v1/images/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"image\": {},\n \"prompt\": \"<string>\",\n \"model\": \"<string>\",\n \"mask\": {},\n \"n\": 123,\n \"size\": \"<string>\",\n \"quality\": \"<string>\",\n \"watermark\": true\n}"
response = http.request(request)
puts response.read_body{
"created": 1735689600,
"data": [
{
"url": "https://.../images/edit-abc123.png",
"revised_prompt": "把背景改成科技感办公室,保留主体构图"
}
]
}
{
"error": {
"message": "failed to parse image edit form request",
"type": "invalid_request_error",
"param": "",
"code": "invalid_request"
}
}
{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "",
"code": "invalid_api_key"
}
}
{
"error": {
"message": "用户额度不足",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}
{
"error": {
"message": "当前请求频率过高,请稍后再试",
"type": "new_api_error",
"param": "",
"code": "too_many_requests"
}
}
{
"error": {
"message": "bad response body",
"type": "new_api_error",
"param": "",
"code": "bad_response_body"
}
}
OpenAI Images 兼容图像编辑
图像编辑使用与生成相同的模型家族,但入口换成编辑路由。- 兼容
POST /v1/images/edits和POST /v1/edits两个入口。 - 同时支持
multipart/form-data和 JSON 请求体。 - 传
image为图生图,额外传mask为局部重绘。 gpt-image-1在编辑场景下默认quality = standard,n不传或传0时回退为1。
方法与路径
| Method | Path |
|---|---|
POST | /v1/images/edits |
POST | /v1/edits |
请求示例
curl -X POST https://www.geeknow.top/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-1" \
-F "prompt=把背景改成科技感办公室,保留主体构图" \
-F "image=@input.png" \
-F "size=1024x1024" \
-F "watermark=false"
import requests
with open("input.png", "rb") as f:
resp = requests.post(
"https://www.geeknow.top/v1/images/edits",
headers={"Authorization": "Bearer YOUR_API_KEY"},
data={
"model": "gpt-image-1",
"prompt": "把背景改成科技感办公室,保留主体构图",
"size": "1024x1024",
"watermark": "false",
},
files={"image": ("input.png", f, "image/png")},
timeout=60,
)
print(resp.json())
const formData = new FormData();
formData.append("model", "gpt-image-1");
formData.append("prompt", "把背景改成科技感办公室,保留主体构图");
formData.append("size", "1024x1024");
formData.append("watermark", "false");
formData.append("image", fileInput.files[0]);
const response = await fetch("https://www.geeknow.top/v1/images/edits", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
},
body: formData,
});
console.log(await response.json());
响应示例
{
"created": 1735689600,
"data": [
{
"url": "https://.../images/edit-abc123.png",
"revised_prompt": "把背景改成科技感办公室,保留主体构图"
}
]
}
{
"error": {
"message": "failed to parse image edit form request",
"type": "invalid_request_error",
"param": "",
"code": "invalid_request"
}
}
{
"error": {
"message": "Invalid API key provided",
"type": "invalid_request_error",
"param": "",
"code": "invalid_api_key"
}
}
{
"error": {
"message": "用户额度不足",
"type": "new_api_error",
"param": "",
"code": "insufficient_user_quota"
}
}
{
"error": {
"message": "当前请求频率过高,请稍后再试",
"type": "new_api_error",
"param": "",
"code": "too_many_requests"
}
}
{
"error": {
"message": "bad response body",
"type": "new_api_error",
"param": "",
"code": "bad_response_body"
}
}
认证
Authorization: Bearer YOUR_API_KEY
Body
编辑输入图。
multipart/form-data 下通常是文件;JSON 场景下可以是 URL、Base64 或对象结构。编辑说明。用于描述要保留什么、修改什么。
模型名称。未传时最终是否有默认行为取决于上游,不建议省略。
局部重绘遮罩。透明区域通常表示允许编辑的区域。
输出数量。不传或显式传
0 时按 1 处理。输出尺寸。具体可用值与目标模型有关。
质量字段。
gpt-image-1 在编辑表单场景下默认补成 standard。显式水印开关。显式传
false 表示明确关闭,不传表示沿用默认策略。Response
编辑结果生成时间戳。
结果图片 URL。
当请求 Base64 格式时返回的图片数据。
上游可能改写后的编辑提示词。
使用场景
基础图生图
curl -X POST https://www.geeknow.top/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-1" \
-F "prompt=把人物服装改成深蓝色西装" \
-F "image=@portrait.png"
局部重绘
curl -X POST https://www.geeknow.top/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-1" \
-F "prompt=把背景改成现代办公室" \
-F "image=@input.png" \
-F "mask=@mask.png"
使用旧版别名
curl -X POST https://www.geeknow.top/v1/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-1" \
-F "prompt=保留主体,增强灯光层次" \
-F "image=@input.png"
注意事项
编辑接口虽然同时兼容 JSON 和表单,但不同上游对字段形状的要求差异很大。最稳的做法仍然是使用
multipart/form-data 提交 image、prompt、mask 这类编辑字段。相关接口
⌘I