HAI Gateway Docs

OpenAI

OpenAI Image Generation

Creates an image given a prompt. Returns a URL or base64-encoded JSON of the generated image(s).

POSTv1/images/generations

Authorizations

Authorizationstringheaderrequired

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

modelstringbodyrequired

Image model, e.g. gpt-image-2

promptstringbodyrequired

Text description of the image

nintegerbody

Number of images to generate, default 1

sizestringbody

1024x1024 / 1536x1024 / 1024x1536 / auto

qualitystringbody

low / medium / high / auto

backgroundstringbody

Background mode: transparent / opaque / auto, default auto, GPT image series only

output_formatstringbody

Image encoding format: png / jpeg / webp, default png, GPT image series only

output_compressionintegerbody

JPEG / WebP compression level (0 – 100), default 100, only effective when output_format is jpeg / webp

response_formatstringbody

url / b64_json, DALL-E series only; GPT image series always returns base64

moderationstringbody

Content filtering: auto / low, GPT image series only

streambooleanbody

Whether to enable streaming (partial images), default false, GPT image series only

For full parameter descriptions, refer to the OpenAI official documentation.

cURL
cURL:Default
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"
  }'
200
200:Default
{
  "created": 1713833628,
  "data": [
    {
      "b64_json": "..."
    }
  ],
  "usage": {
    "total_tokens": 100,
    "input_tokens": 50,
    "output_tokens": 50,
    "input_tokens_details": {
      "text_tokens": 10,
      "image_tokens": 40
    }
  }
}