GPT Image 2: पहला Image API request
Image API के पहले request को अलग key, current model और छोटा prompt के साथ चलाएँ; result, charge और error को application integration से पहले सत्यापित करें।
विषय-सूची
BetterToken से पहला image एक synchronous HTTP request से मिलता है। अपना API Key और POST request को https://www.bettertoken.ai/v1/images/generations पर भेजें। जाँचने योग्य शुरुआत के लिए model gpt-image-2, n=1, size=1024x1024, response_format=b64_json और output_format=png रखें। Response में image data[0].b64_json में है; इसे decode करके file में save करें।
BetterToken एक independent OpenAI-compatible Image API है। शुरू करने से पहले current Image API Docs और pricing page देखें; parameters और prices बदल सकते हैं।
क्या चाहिए
- request भेजने के लिए
curl; - अपना BetterToken API Key;
- exact Base URL
https://www.bettertoken.ai/v1; - model
gpt-image-2; - Base64 decoder या छोटा Python script।
Key को source code, screenshots या shell history में न डालें:
export BETTERTOKEN_API_KEY="your_api_key_here"
पहला GPT Image 2 request
क्या आप अपनी Key से पहला request चलाने के लिए तैयार हैं? BetterToken account बनाएँ, API Key लें और उसे source code से बाहर रखें। BetterToken account बनाएँ
curl https://www.bettertoken.ai/v1/images/generations \
-H "Authorization: Bearer $BETTERTOKEN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A clean editorial illustration of a coding desk at night, green and graphite palette",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json",
"output_format": "png"
}' \
-o image-response.json
यह synchronous contract है: दिखाए गए first request के लिए अलग task ID, polling या callback नहीं चाहिए। data[0].b64_json पढ़ें, decode करें और PNG save करें।
Image save करें
import base64
import json
with open("image-response.json", "r", encoding="utf-8") as source:
payload = json.load(source)
image_base64 = payload["data"][0]["b64_json"]
with open("bettertoken-image.png", "wb") as target:
target.write(base64.b64decode(image_base64))
print("Saved: bettertoken-image.png")
File खोलकर देखें कि वह prompt से मेल खाती है। HTTP 200 केवल request के काम करने का संकेत है; यह visual check का विकल्प नहीं है।
दूसरा request बेहतर करें
पहले छोटे prompt में subject, style, composition और palette/lighting रखें। पहले baseline check करें, फिर एक बार में एक parameter बदलें। Supported size, format और अन्य current values केवल Image API Docs से लें।
सामान्य errors
401: key rejected
देखें कि BETTERTOKEN_API_KEY current terminal में है और header में Bearer है। Key print या share न करें।
402 या insufficient balance
Dashboard में available balance देखें; request के लिए पर्याप्त balance चाहिए।
404: incorrect path
पूरा path यह है:
https://www.bettertoken.ai/v1/images/generations
400: incorrect model or parameters
ऊपर का minimal example फिर चलाएँ और gpt-image-2 तथा current Docs के parameters जाँचें।
429 या 5xx
Infinite retry loop न चलाएँ। HTTP status, request time और response का safe part लिखें, फिर delay के बाद retry करें। BetterToken Dashboard में request को time से match कर के केवल model, status और actual charge देखें।
Application integration से पहले checks
Key को environment/secret manager में रखें, response का Base64 decode करें, non-2xx response संभालें, और price को current pricing पर जाँचें। पहले एक result save करें; उसके बाद ही current Docs में supported parameters के साथ integration बढ़ाएँ।
संक्षेप
पहला cycle: BetterToken Image API को POST, synchronous data[0].b64_json पढ़ना, और उसे PNG में decode करना है।