Gửi kèm một ảnh gốc và mô tả thay đổi để `gpt-image-2` chỉnh sửa. Endpoint này nhận `multipart/form-data`, không phải JSON.
Endpoint
POST https://cheapkeyai.shop/v1/images/editsYêu cầu
| Tên | Vị trí | Bắt buộc | Mô tả |
|---|---|---|---|
| Authorization | header | Có | `Bearer sk-your-api-key-here` |
| Content-Type | header | Có | `multipart/form-data` |
| model | form | Có | `gpt-image-2` |
| image | form | Có | File ảnh gốc cần sửa |
| prompt | form | Có | Mô tả nội dung muốn sửa thành |
| mask | form | Không | File mask, chỉ vùng cần sửa |
| size | form | Không | Kích thước ảnh, ví dụ `1024x1024` |
| n | form | Không | Số ảnh cần tạo, mặc định `1` |
Ví dụ
curl https://cheapkeyai.shop/v1/images/edits \
-H "Authorization: Bearer sk-your-api-key-here" \
-F model="gpt-image-2" \
-F image="@input.png" \
-F prompt="Một chú heo con đáng yêu" \
-F size="1024x1024" \
-F n=1Phản hồi 200
{
"created": 1677652288,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAAA..."
}
]
}Lưu ảnh ra file
curl -s https://cheapkeyai.shop/v1/images/edits \
-H "Authorization: Bearer sk-your-api-key-here" \
-F model="gpt-image-2" \
-F image="@input.png" \
-F prompt="Một chú heo con đáng yêu" \
| jq -r '.data[0].b64_json' | base64 -d > edited.pngimport base64
from openai import OpenAI
client = OpenAI(
api_key="sk-your-api-key-here",
base_url="https://cheapkeyai.shop/v1",
)
result = client.images.edit(
model="gpt-image-2",
image=open("input.png", "rb"),
prompt="Một chú heo con đáng yêu",
size="1024x1024",
)
with open("edited.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))Lỗi 400
{
"error": {
"message": "Invalid request (request id: 20260805120000123456789AbCdEfGh)",
"type": "new_api_error"
}
}