Skip to main content
POST
/
v1
/
images
/
generations
GPT-Image-2 | Text To Image
curl --request POST \
  --url https://gptproto.com/v1/images/generations

Authentication

  1. Sign up for a GPTProto account at https://gptproto.com
  2. Navigate to the API Keys section in your dashboard
  3. Generate a new API key (sk-xxxxx)
  4. Copy and securely store your API key For authentication details, please refer to the Authentication section.

Initiate Request

curl --location 'https://gptproto.com/v1/images/generations' \
--header 'Authorization: GPTPROTO_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
  "model": "gpt-image-2",
  "prompt": "a cat",
  "size": "1024x1024"
}'

{
  "created": 1776843003,
  "background": "opaque",
  "data": [
    {
      "b64_json": "<BASE64_DATA>"
    }
  ],
  "output_format": "png",
  "quality": "low",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 8,
    "input_tokens_details": {
      "image_tokens": 0,
      "text_tokens": 8
    },
    "output_tokens": 196,
    "output_tokens_details": {
      "image_tokens": 196,
      "text_tokens": 0
    },
    "total_tokens": 204
  }
}

Parameters

ParameterTypeRequiredDefaultRangeDescription
modelstring✅ Yesgpt-image-1gpt-image-1
gpt-image-1-mini
gpt-image-1.5
gpt-image-2
The model to use for image generation. Defaults to gpt-image-1.
promptstring✅ Yes--A text description of the desired image(s). The maximum length is 32000 characters.
ninteger❌ No11-10The number of images to generate. Must be between 1 and 10.
sizestring❌ Noautoauto
1024x1024
1536x1024
1024x1536
2048x2048
2048x1152
3840x2160
2160x3840
or any valid custom size
The size of the generated images. For gpt-image-1: one of auto, 1024x1024, 1536x1024, or 1024x1536. For gpt-image-2: supports arbitrary resolutions (max edge ≤ 3840px, both sides must be multiples of 16px, aspect ratio ≤ 3:1, total pixels between 655,360 and 8,294,400). Outputs exceeding 2560×1440 are considered experimental.
qualitystring❌ Noautoauto
high
medium
low
The quality of the generated images. One of auto, low, medium, or high. Defaults to auto. Not supported by -plus suffixed models.
backgroundstring❌ Noautoopaque
auto
transparent
Allows to set transparency for the background of the generated image(s). transparent is only supported by gpt-image-1 (not gpt-image-2) and requires output_format to be png or webp. When auto is used, the model will automatically determine the best background.
moderationstring❌ Noautolow
auto
Content moderation level for generated images. low is less restrictive, auto is the default.
output_formatstring❌ Noautoauto
png
jpeg
webp
The output format of the generated image(s). Defaults to auto. jpeg is faster than png for latency-sensitive scenarios.
output_compressioninteger❌ No1000-100The compression level (0-100%) for the output image. Only applicable with webp or jpeg format. Defaults to 100.
streamboolean❌ Nofalsetrue
false
Whether to stream the response in real-time. When enabled, partial images can be received during generation.
partial_imagesinteger❌ No-0-3The number of partial images to receive during streaming. Only used when stream is true. Each partial image incurs an additional 100 image output tokens.
userstring❌ No--A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.

Error Codes

Common Error Codes

Error CodeError NameDescription
401UnauthorizedAPI key is missing or invalid
403ForbiddenYour API key doesn’t have permission to access this resource, or insufficient balance for the requested operation
429Too Many RequestsYou’ve exceeded your rate limit
500Internal server errorAn internal server error occurred
503Content policy violationContent blocked due to safety concerns (actual status code is 400)