Skip to main content
POST
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 से भेजें।
पेज के दाईं ओर Playground में form field भरें और reference image अपलोड करें, फिर अनुरोध सीधे https://bettertoken.ai/v1/images/edits पर भेजें।
image-to-image अनुरोधों के लिए सामान्य JSON body उपयोग न करें। text field और file field को multipart/form-data से भेजें।

अनुशंसित मान

हर अनुरोध में इन फ़ील्ड को स्पष्ट रूप से भेजें:
एक reference image के लिए 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 नहीं है।

संबंधित दस्तावेज

प्राधिकरण

Authorization
string
header
आवश्यक

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

बॉडी

multipart/form-data
model
enum<string>
डिफ़ॉल्ट:gpt-image-2
आवश्यक

Use the GPT Image 2 model ID.

उपलब्ध विकल्प:
gpt-image-2
उदाहरण:

"gpt-image-2"

prompt
string
आवश्यक

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."

image
file

The reference image field for a single input image.

image[]
file[]

Repeat this field for each input when sending multiple reference images.

mask
file

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.

n
डिफ़ॉल्ट:1

Use 1. Send separate requests when you need multiple output images.

उदाहरण:

"1"

size
enum<string>
डिफ़ॉल्ट:1024x1024

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"

response_format
enum<string>
डिफ़ॉल्ट:b64_json

Use b64_json.

उपलब्ध विकल्प:
b64_json
उदाहरण:

"b64_json"

output_format
enum<string>
डिफ़ॉल्ट:png

Use png. Do not rely on jpeg or webp being returned directly in the selected format.

उपलब्ध विकल्प:
png
उदाहरण:

"png"

प्रतिक्रिया

Image editing result.

created
integer
उदाहरण:

1710000000

data
object[]