Image to image (इमेज एडिटिंग)
BetterToken के OpenAI-compatible API से GPT Image 2 का उपयोग करके reference image से इमेज बनाएं या संपादित करें। पैरामीटर, कोड उदाहरण और त्रुटि समाधान सहित।
POST /v1/images/edits
image-to-image endpoint multipart/form-data request body उपयोग करता है। एक या अधिक reference image अपलोड करें और prompt व parameter फ़ील्ड को form field के रूप में भेजें।
https://bettertoken.ai/v1 को Base URL के रूप में उपयोग करें। BetterToken API Key को Authorization: Bearer YOUR_API_KEY से भेजें।अनुशंसित मान
हर अनुरोध में इन फ़ील्ड को स्पष्ट रूप से भेजें:image उपयोग करें। कई reference image के लिए image[] फ़ील्ड दोहराएं।
एक reference image
कई reference image
mask के साथ चुने हुए क्षेत्र को edit करें
किसी चुने हुए क्षेत्र में edit को निर्देशित करने के लिए वैकल्पिकmask file field जोड़ें। मौजूदा BetterToken endpoint एक mask file पढ़ता है। बार-बार mask[] fields न भेजें।
- मूल image और mask का file format और pixel dimensions एक समान होना चाहिए। हर file 50 MB से छोटी होनी चाहिए। अधिकतम compatibility के लिए दोनों files में Alpha channel वाला PNG इस्तेमाल करें।
- Mask में Alpha channel होना चाहिए। पूरी तरह transparent pixels (
Alpha 0) उस क्षेत्र को दिखाते हैं जिसे model दोबारा बना सकता है। पूरी तरह opaque pixels (Alpha 255) उस क्षेत्र को सुरक्षित रखने के लिए model को निर्देशित करते हैं। - सामान्य RGB black-and-white image तब तक मान्य mask नहीं है जब तक उसमें वास्तव में Alpha channel न हो।
- अगर आप कई
image[]fields भेजते हैं, तो mask पहली input image पर लागू होता है। - Mask model को निर्देशित करता है। यह guarantee नहीं करता कि transparent क्षेत्र के बाहर के pixels बिल्कुल समान रहेंगे।
Python से masked edit
दोनों files को एक हीwith statement में खोलें, ताकि request के बाद Python उन्हें बंद कर दे:
upload से पहले files जांचें
यह छोटा Pillow check अनिवार्य format, dimensions और Alpha channel की जांच करता है। सामान्य local mask के लिए, Alpha channel में पूरी तरह transparent और opaque दोनों areas न होने पर यह warning भी देता है:Python उदाहरण
अनुशंसित आकार
size अपेक्षित aspect ratio और size tier दर्शाता है। वास्तविक लौटे pixel server द्वारा map या adjust किए जा सकते हैं। output को मांगे गए मान पर जबरन crop करने के बजाय decoded इमेज dimension उपयोग करें।
इमेज सहेजें
सफल response OpenAI-compatible इमेज response स्वरूप का पालन करता है:data[0].b64_json पढ़ें और इसे base64 image content के रूप में सहेजें। output_format: "png" हमेशा सेट करें ताकि decoded इमेज को .png के रूप में सहेज सकें।
response flow
यह endpoint synchronous है।POST /images/edits भेजने के बाद server के response तक मौजूदा HTTP request खुला रखें। generation सफल होने पर image content data[0].b64_json में लौटता है।
endpoint task_id नहीं लौटाता, और कोई अलग status query या result download endpoint नहीं है।
संबंधित दस्तावेज
प्राधिकरण
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
बॉडी
Use the GPT Image 2 model ID.
gpt-image-2 "gpt-image-2"
Instructions for editing the image or generating from reference images.
"Use this reference image to create a more polished square product hero image while preserving the main style."
The reference image field for a single input image.
Repeat this field for each input when sending multiple reference images.
An optional single mask file. The mask and original image must have the same format and dimensions, each file must be smaller than 50 MB, and the mask must contain an Alpha channel. For maximum compatibility, use PNG with an Alpha channel for both files. With multiple image[] inputs, the mask applies to the first image.
Use 1. Send separate requests when you need multiple output images.
"1"
The requested image size or aspect-ratio tier. The server may map or adjust the final pixel dimensions, so inspect the decoded image for its actual size.
auto, 1024x1024, 1536x1024, 1024x1536, 1536x1152, 1152x1536, 2048x2048, 2048x1152, 3840x2160, 2160x3840 "1024x1024"
Use b64_json.
b64_json "b64_json"
Use png. Do not rely on jpeg or webp being returned directly in the selected format.
png "png"

