Skip to content

Image Generation (Image 2)

Generate images from text through the OpenAI-compatible API. gpt-image-2 returns Base64-encoded images together with the actual dimensions, format, quality, and token usage.

Endpoint

http
POST https://api.ezmodel.cloud/v1/images/generations
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

gpt-image-2 request fields

FieldTypeRequiredDefaultDescription
modelstringYes-Use gpt-image-2
promptstringYes-Image description, up to 32,000 characters
nintegerNo1Number of images, from 1 to 10
sizestringNoautoauto, a standard size, or a valid custom WIDTHxHEIGHT size
qualitystringNoautoauto, low, medium, or high
backgroundstringNoautoauto or opaque; transparent backgrounds are not supported
output_formatstringNopngpng or jpeg
output_compressionintegerNo100JPEG compression quality from 0 to 100
moderationstringNoautoauto or low
userstringNo-End-user identifier

Size rules

  • Standard sizes: 1024x1024, 1536x1024, and 1024x1536.
  • With auto, read the final dimensions from the response size field.
  • Custom size examples: 1280x720 and 1536x864. Width and height must be divisible by 16, with an aspect ratio between 1:3 and 3:1.
  • Sizes above 2560x1440 are experimental. The maximum is 3840x2160, subject to the model's pixel and edge limits.

Standard request

bash
curl https://api.ezmodel.cloud/v1/images/generations \
  -H "Authorization: Bearer $EZMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A cinematic Hong Kong street after rain, neon reflections",
    "size": "1024x1024",
    "quality": "low",
    "output_format": "png",
    "n": 1
  }'

Custom landscape JPEG

bash
curl https://api.ezmodel.cloud/v1/images/generations \
  -H "Authorization: Bearer $EZMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Minimal seaside product photography in a wide composition",
    "size": "1280x720",
    "quality": "medium",
    "output_format": "jpeg",
    "output_compression": 60,
    "n": 1
  }'

Python

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.ezmodel.cloud/v1",
)

response = client.images.generate(
    model="gpt-image-2",
    prompt="A cinematic Hong Kong street after rain, neon reflections",
    size="1024x1024",
    quality="low",
    n=1,
)

image_base64 = response.data[0].b64_json
print(image_base64[:80])

Response

The image is returned in data[].b64_json. Use the response output_format when choosing the file extension.

json
{
  "created": 1710000000,
  "background": "opaque",
  "data": [{ "b64_json": "iVBORw0KGgo..." }],
  "output_format": "png",
  "quality": "low",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 20,
    "input_tokens_details": { "image_tokens": 0, "text_tokens": 20 },
    "output_tokens": 196,
    "output_tokens_details": { "image_tokens": 196, "text_tokens": 0 },
    "total_tokens": 216
  }
}

To create a new version from existing images, use the image edits endpoint.

企业合作联系:service@ezmodel.cloud