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}| Parameter | Required | Description |
|---|---|---|
model | ✔ | Model name; use suffixes to select aspect ratio/resolution/speed (-fast, -portrait, -2k, -4k, etc.) |
prompt | ✔ | Image description, supports both Chinese and English as well as composite instructions |
n | Number of images to generate, default 1; for batching, multiple requests are recommended instead of a large n | |
response_format | url (default) or b64_json |
Response
{ "created": 1735900000, "data": [ { "url": "https://…/xxx.png" } ]}- When
response_format: "b64_json"is used, theb64_jsonfield 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
- Per-generation billing: one charge for each successful image, no charge for failures;
- For timeout and disconnection handling, see Connection Drop Troubleshooting;
- For image editing, see Image Editing API.