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/jsongpt-image-2 request fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | - | Use gpt-image-2 |
prompt | string | Yes | - | Image description, up to 32,000 characters |
n | integer | No | 1 | Number of images, from 1 to 10 |
size | string | No | auto | auto, a standard size, or a valid custom WIDTHxHEIGHT size |
quality | string | No | auto | auto, low, medium, or high |
background | string | No | auto | auto or opaque; transparent backgrounds are not supported |
output_format | string | No | png | png or jpeg |
output_compression | integer | No | 100 | JPEG compression quality from 0 to 100 |
moderation | string | No | auto | auto or low |
user | string | No | - | End-user identifier |
Size rules
- Standard sizes:
1024x1024,1536x1024, and1024x1536. - With
auto, read the final dimensions from the responsesizefield. - Custom size examples:
1280x720and1536x864. Width and height must be divisible by 16, with an aspect ratio between1:3and3:1. - Sizes above
2560x1440are experimental. The maximum is3840x2160, 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.
