इमेज जनरेशन API
GPT Image 2 और BetterToken के OpenAI-compatible API से text से इमेज बनाएं: API Key, Base URL, parameter, Python, JavaScript और त्रुटियां। सेटअप और उदाहरण।
POST /v1/images/generations
text-to-image endpoint application/json request body उपयोग करता है। prompt भेजें, HTTP request खुला रखें और उसी response में data[0].b64_json से generated इमेज पढ़ें।
https://bettertoken.ai/v1 को Base URL के रूप में उपयोग करें। BetterToken API Key को Authorization: Bearer YOUR_API_KEY से भेजें।सही workflow चुनें
- टेक्स्ट से image बनाकर result सेव करें: इसी पेज पर रहें।
curlexample से शुरू करें, फिरdata[0].b64_jsondecode करने के लिए नीचे का Image सेव करें section उपयोग करें। - मौजूदा image edit करें: Image to image खोलें, जहां एक या अधिक source files
multipart/form-dataके रूप में भेजी जाती हैं। - Model चुनें, parameters देखें और budget का अनुमान लगाएं: मौजूदा Model ID और price model plaza में देखें और request parameters के लिए नीचे अनुशंसित मान पढ़ें। व्यापक request-response context अंग्रेज़ी GPT Image 2 first-request article में है।
curl के साथ त्वरित शुरुआत
https://bettertoken.ai/v1 को Base URL के रूप में उपयोग करें और https://bettertoken.ai/v1/images/generations पर अनुरोध भेजें:
अनुशंसित मान
हर अनुरोध में इन फ़ील्ड को स्पष्ट रूप से भेजें:n > 1 वाले एक अनुरोध पर निर्भर न रहें।
अनुशंसित आकार
size अपेक्षित aspect ratio और size tier दर्शाता है। वास्तविक लौटे pixel server द्वारा map या adjust किए जा सकते हैं। output को मांगे गए मान पर जबरन crop करने के बजाय decoded इमेज dimension उपयोग करें।
इमेज सहेजें
सफल response OpenAI-compatible इमेज response स्वरूप का पालन करता है:data[0].b64_json पढ़ें और इसे base64 image content के रूप में सहेजें। response में revised_prompt जैसे अतिरिक्त field हो सकते हैं; इन्हें client में स्वीकार करें।
output_format: "png" हमेशा सेट करें। फिर file header जांचे बिना decoded इमेज को .png के रूप में सहेजें।
JavaScript उदाहरण (Node.js)
response flow
यह endpoint synchronous है।POST /images/generations भेजने के बाद server के response तक मौजूदा HTTP request खुला रखें। generation सफल होने पर image content data[0].b64_json में लौटता है।
endpoint task_id नहीं लौटाता, और कोई अलग status query या result download endpoint नहीं है।
timeout और retry
- HTTP client timeout को कई मिनट पर सेट करें।
- transport error,
408,409,425,429और5xxपर retry करें। 400,401, missing parameter या malformed request को अपने-आप retry न करें।3s,8sऔर15sजैसे exponential backoff उपयोग करें।- duplicate image स्वीकार्य न हों तो retry से पहले अपनी request ID रिकॉर्ड करें।
त्रुटि प्रबंधन
त्रुटियां सामान्यतः JSON लौटाती हैं। त्रुटि दिखाते समय पहलेerror.message, फिर message, फिर HTTP status text पढ़ें।
एकीकरण जांचसूची
- Base URL
https://bettertoken.ai/v1है। - header में
Authorization: Bearer YOUR_API_KEYहै। - अनुरोध
application/jsonऔरPOST /images/generationsउपयोग करता है। modelgpt-image-2,response_formatb64_json,output_formatpngऔरn1है।sizeअनुशंसित मानों में से है, जैसे1024x1024।- HTTP client generation के लिए कई मिनट की अनुमति देता है।
संबंधित दस्तावेज
प्राधिकरण
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"
A detailed description of the image to generate.
"A futuristic AI product poster on a light background, with glass textures, a clean composition, and a premium technology aesthetic."
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"
प्रतिक्रिया
Image generation result.

