OpenAI
OpenAI Image Generation
Creates an image given a prompt. Returns a URL or base64-encoded JSON of the generated image(s).
v1/images/generationsAuthorizations
Use the following format for authentication: Bearer sk-pat-YourAccessToken
The key value is your HAI Gateway Personal Access Token (starting with sk-pat-). No separate API key from OpenAI is required.
Base URL
Body Parameters
Image model, e.g. gpt-image-2
Text description of the image
Number of images to generate, default 1
1024x1024 / 1536x1024 / 1024x1536 / auto
low / medium / high / auto
Background mode: transparent / opaque / auto, default auto, GPT image series only
Image encoding format: png / jpeg / webp, default png, GPT image series only
JPEG / WebP compression level (0 – 100), default 100, only effective when output_format is jpeg / webp
url / b64_json, DALL-E series only; GPT image series always returns base64
Content filtering: auto / low, GPT image series only
Whether to enable streaming (partial images), default false, GPT image series only
For full parameter descriptions, refer to the OpenAI official documentation.
curl https://api.hai.network/openai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-pat-YourAccessToken" \
-d '{
"model": "gpt-image-2",
"prompt": "A children'\''s book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter.",
"n": 1,
"size": "1024x1024",
"quality": "high"
}'{
"created": 1713833628,
"data": [
{
"b64_json": "..."
}
],
"usage": {
"total_tokens": 100,
"input_tokens": 50,
"output_tokens": 50,
"input_tokens_details": {
"text_tokens": 10,
"image_tokens": 40
}
}
}