GPT Image 2 API
เอกสารอ้างอิง API ฉบับสมบูรณ์สำหรับโมเดล GPT Image 2 ที่ขับเคลื่อนโดย OpenAI.
ตัวเลือกโมเดล {#}
API นี้รองรับโมเดล 4 ตัวเลือก:
เปรียบเทียบอย่างรวดเร็ว
อัตราส่วนภาพที่รองรับ
16:9, 9:16, 1:1, 3:2, 2:3, 3:4, 4:3, 5:4, 4:5, 21:9
GPT Image 2 (ข้อความเป็นรูปภาพ)
จุดเชื่อมต่อ
POST /api/v1/image/task
การยืนยันตัวตน
Authorization: Bearer YOUR_API_KEY
พารามิเตอร์คำขอ
จำเป็น
หมายเหตุ: อัตราส่วน width:height ต้องเป็นหนึ่งใน: 16:9, 9:16, 1:1, 3:2, 2:3, 3:4, 4:3, 5:4, 4:5, 21:9
ตัวอย่างคำขอ
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'gpt-image-2',
prompt: 'A minimalist product shot of a ceramic mug on marble, soft studio light',
width: 1,
height: 1,
resolution: '1k',
quality: 'medium'
})
});
const { data } = await response.json();
const taskId = data.task_id;
const pollResponse = await fetch(
`https://api.flaq.ai/api/v1/image/${taskId}`,
{
headers: { Authorization: 'Bearer YOUR_API_KEY' }
}
);
const result = await pollResponse.json();
console.log(result.data.task_result.images[0].url);
GPT Image 2 Edit (การแก้ไขรูปภาพ)
จุดเชื่อมต่อ
POST /api/v1/image/task
พารามิเตอร์คำขอ
จำเป็น
ไม่บังคับ
หมายเหตุ: เมื่อระบุ width และ height อัตราส่วนต้องเป็นหนึ่งใน: 16:9, 9:16, 1:1, 3:2, 2:3, 3:4, 4:3, 5:4, 4:5, 21:9
ตัวอย่างการแก้ไขรูปภาพเดียว
{
model_name: 'gpt-image-2-edit',
prompt: 'Replace the background with a clean studio scene and brighten the product lighting',
image_url_list: ['https://example.com/product-photo.jpg'],
width: 16,
height: 9,
resolution: '1k',
quality: 'medium'
}
ตัวอย่างการจัดองค์ประกอบหลายรูปภาพ
{
model_name: 'gpt-image-2-edit',
prompt: 'Blend these reference images into a polished campaign composition while keeping the main subject identity consistent',
image_url_list: [
'https://example.com/image1.jpg',
'https://example.com/image2.jpg',
'https://example.com/image3.jpg'
],
width: 16,
height: 9,
resolution: '2k',
quality: 'high'
}
GPT Image 2 Client
ใช้พารามิเตอร์และความสามารถเดียวกับ GPT Image 2 โดยตั้ง model_name เป็น gpt-image-2-client. นี่เป็นเวอร์ชันประสบการณ์พรีวิวและอาจมีความเสถียรน้อยกว่า.
ตัวอย่างคำขอ
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'gpt-image-2-client',
prompt: 'A luxury skincare still life with soft reflections and elegant typography',
width: 4,
height: 5,
resolution: '1k',
quality: 'medium'
})
});
const { data } = await response.json();
const taskId = data.task_id;
GPT Image 2 Edit Client
ใช้พารามิเตอร์และความสามารถเดียวกับ GPT Image 2 Edit โดยตั้ง model_name เป็น gpt-image-2-edit-client. นี่เป็นเวอร์ชันประสบการณ์พรีวิวและอาจมีความเสถียรน้อยกว่า.
ตัวอย่างคำขอ
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'gpt-image-2-edit-client',
prompt: 'Turn this portrait into a clean editorial poster while preserving the face and pose',
image_url_list: ['https://example.com/portrait.jpg'],
width: 4,
height: 5,
resolution: '1k',
quality: 'medium'
})
});
const { data } = await response.json();
const taskId = data.task_id;
รูปแบบการตอบกลับ
การตอบกลับเริ่มต้น
GPT Image 2 ทุก variant จะส่งคืน task_id สำหรับ Poll:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
การตอบกลับจากการ Poll
Poll GET /api/v1/image/{task_id} เพื่อตรวจสอบสถานะ:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "succeed",
"task_status_msg": null,
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}",
"task_result": {
"credit": 0.0997,
"images": [
{
"url": "https://example.com/generated-image.jpeg"
}
]
}
},
"message": "success"
}
ค่าสถานะ
submitted: รับงานแล้ว
processing: กำลังสร้างหรือแก้ไขรูปภาพ
succeed: งานเสร็จสมบูรณ์สำเร็จ
failed: งานล้มเหลว
เวลาประมวลผล
เวลาประมวลผลโดยทั่วไปคือ 15-60 วินาที ขึ้นอยู่กับความละเอียด คุณภาพ ความซับซ้อนของพรอมต์ และจำนวนรูปภาพในคำขอแก้ไข.
แนวทางปฏิบัติที่ดี
- ระบุองค์ประกอบให้ชัดเจน: GPT Image 2 ทำงานได้ดีที่สุดเมื่อพรอมต์อธิบายวัตถุ การจัดเฟรม แสง และสไตล์ที่ต้องการอย่างชัดเจน.
- เลือกคุณภาพตามเวิร์กโฟลว์: ใช้
low หรือ medium สำหรับการวนปรับ และใช้ high สำหรับเอาต์พุตที่ขัดเกลา.
- จับคู่อัตราส่วนภาพกับเป้าหมายการส่งมอบ: ตั้งอัตราส่วนล่วงหน้าสำหรับโพสต์โซเชียล แบนเนอร์ หน้าสินค้า หรือเลย์เอาต์บรรณาธิการ.
- ใช้รูปต้นฉบับที่สะอาดสำหรับการแก้ไข: อินพุตที่คมชัดและมีแสงดีช่วยรักษาอัตลักษณ์และเพิ่มคุณภาพการแก้ไขเฉพาะจุด.
- จำกัดคำขอหลายรูปให้เหลือเฉพาะ reference สำคัญ: สำหรับ variant แก้ไข ให้ส่งเฉพาะรูปที่จำเป็นเพื่อหลีกเลี่ยงคำแนะนำภาพที่ขัดแย้งกัน.