GPT Image API b64_json Workflow for Developers
· 2 min de lectura
Image generation SEO is competitive, but developer-specific phrases are much more focused. A phrase like GPT image API b64_json targets someone who already has code open and wants an implementation detail.
AI Supermarket exposes OpenAI-compatible image generation through:
https://aisupermarket.work/v1/images/generations
curl Example
curl -s -X POST "https://aisupermarket.work/v1/images/generations" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A clean SaaS dashboard hero image for an AI API gateway",
"size": "1024x1024",
"quality": "medium",
"n": 1,
"response_format": "b64_json"
}' | jq -r '.data[0].b64_json' | base64 --decode > ai-image.png
Python Example
from openai import OpenAI
import base64
client = OpenAI(
api_key="your-api-key",
base_url="https://aisupermarket.work/v1",
)
response = client.images.generate(
model="gpt-image-2",
prompt="A clean SaaS dashboard hero image for an AI API gateway",
size="1024x1024",
n=1,
)
image_bytes = base64.b64decode(response.data[0].b64_json)
with open("ai-image.png", "wb") as f:
f.write(image_bytes)
Troubleshooting
If the request fails:
- confirm the Key group supports image generation
- check the model name with
/v1/models - start with one image and medium quality
- confirm your JSON body is valid
- confirm the response actually contains
data[0].b64_json
