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://www.bettertoken.ai/v1 को Base URL के रूप में उपयोग करें। BetterToken API Key को Authorization: Bearer YOUR_API_KEY से भेजें।
पेज के दाईं ओर Playground में Authorization और request body भरें, फिर अनुरोध सीधे https://www.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 में रखें।

curl के साथ त्वरित शुरुआत

https://www.bettertoken.ai/v1 को Base URL के रूप में उपयोग करें और https://www.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://www.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
आवश्यक

Use your BetterToken API Key as a bearer token. Do not expose API keys in frontend browser code, screenshots, logs, tickets, or Git repositories.

बॉडी

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

固定使用 YOUR_MODEL_ID。

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

"YOUR_MODEL_ID"

prompt
string
आवश्यक

图片生成提示词。

उदाहरण:

"一张未来感 AI 产品海报,浅色背景,玻璃质感,干净构图,高级科技感"

n
integer
डिफ़ॉल्ट:1

推荐固定为 1。多张图片建议发起多次独立请求。

आवश्यक सीमा: 1 <= x <= 1
उदाहरण:

1

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

图片尺寸和比例档位。auto 为自动;1024x1024 和 2048x2048 为 1:1;1536x1024 为 3:2;1024x1536 为 2:3;1536x1152 为 4:3;1152x1536 为 3:4;2048x1152 和 3840x2160 为 16:9;2160x3840 为 9:16。实际返回像素可能由服务端映射或调整,客户端应以解码后的真实图片尺寸为准。

उपलब्ध विकल्प:
auto,
1024x1024,
1536x1024,
1024x1536,
1536x1152,
1152x1536,
2048x2048,
2048x1152,
3840x2160,
2160x3840
उदाहरण:

"1024x1024"

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

推荐固定为 b64_json,便于稳定保存图片。

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

"b64_json"

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

推荐固定为 png。不要依赖 jpeg 或 webp 直接返回对应格式。

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

"png"

प्रतिक्रिया

Image generation result.

OpenAI-compatible image response. Clients should read data[0].b64_json and allow additional fields such as revised_prompt.

created
integer
उदाहरण:

1710000000

data
object[]