Skip to content
Main Site News Console

Text-to-Image API Reference

Interface reference for GPT-Image series text-to-image generation. For overview and model selection, see GPT-Image Image Generation.

Request

POST https://api.4allapi.com/v1/images/generations
{
"model": "gpt-image-2",
"prompt": "Minimalist coffee brand poster, cream-colored background, a latte in the center of the image",
"n": 1
}
ParameterRequiredDescription
modelModel name; use suffixes to select aspect ratio/resolution/speed (-fast, -portrait, -2k, -4k, etc.)
promptImage description, supports both Chinese and English as well as composite instructions
nNumber of images to generate, default 1; for batching, multiple requests are recommended instead of a large n
response_formaturl (default) or b64_json

Response

{
"created": 1735900000,
"data": [
{ "url": "https://…/xxx.png" }
]
}
  • When response_format: "b64_json" is used, the b64_json field is returned; note that the response body is larger;
  • The URL is time-limited. Save it immediately after obtaining it; see Compression and Output Resolution.

Python Example

resp = client.images.generate(
model="gpt-image-2-portrait-2k",
prompt="Tokyo rainy-night street, neon reflections, cinematic feel",
)
print(resp.data[0].url)

Billing and Failures