Skip to main content
POST
cURL
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 से भेजें।
पेज के दाईं ओर Playground में Authorization और request body भरें, फिर अनुरोध सीधे https://bettertoken.ai/v1/images/generations पर भेजें।
API key को frontend browser code, Git repository, ticket, screenshot या log में न रखें। server-side proxy call के लिए API key केवल server environment variable या secret manager में रखें।

सही workflow चुनें

  • टेक्स्ट से image बनाकर result सेव करें: इसी पेज पर रहें। curl example से शुरू करें, फिर data[0].b64_json decode करने के लिए नीचे का 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)

JPEG या WebP फ़ाइल सीधे पाने के लिए output_format: "jpeg" या output_format: "webp" पर निर्भर न रहें। वर्तमान endpoint अब भी PNG image content लौटा सकता है। product को JPEG या WebP चाहिए तो पहले PNG लें और अपने code में बदलें।

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 उपयोग करता है।
  • model gpt-image-2, response_format b64_json, output_format png और n 1 है।
  • size अनुशंसित मानों में से है, जैसे 1024x1024।
  • HTTP client generation के लिए कई मिनट की अनुमति देता है।

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

प्राधिकरण

Authorization
string
header
आवश्यक

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

बॉडी

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

Use the GPT Image 2 model ID.

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

"gpt-image-2"

prompt
string
आवश्यक

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

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 generation result.