Text to image
Generate images from a text prompt with the Cheapest Imagen API, and choose the model, size, quality, number of images and output file format.
Send a prompt to POST /v1/images/generations. Only model and prompt are required.
curl https://api.cheapestimagen.com/v1/images/generations \
-H "Authorization: Bearer $YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "a lighthouse at dusk, oil painting",
"n": 2,
"size": "1536x1024",
"quality": "high"
}'Options
| Field | What it does | Values |
|---|---|---|
n | Number of images | 1 to 10, default 1 |
size | Width and height | auto or a 1K, 2K or 4K size, see Ratios and sizes |
quality | Rendering quality, same price for all | auto, low, medium, high; xhigh, max on gpt-image-2.5-sunburst |
background | Transparent or solid background | auto, opaque, transparent |
output_format | File format | png (default), jpeg, webp on every model; gif on gpt-image-2.6 and its flare and sunburst variants; svg on gpt-image-2.6 |
output_compression | Quality for jpeg and webp | 0 to 100, default 100 |
moderation | How strict content checks are | auto, low |
response_format | Image data or a link | b64_json (default), url |
No model makes a transparent background at the moment: OpenAI withdrew its transparency preview for the GPT Image models, and they now return a solid background. A request with background: transparent returns a 400 with code unsupported_parameter. To get a cut-out, ask for a plain single-colour background in the prompt and remove it afterwards.
Output formats
PNG, JPEG and WebP work on every model, as on OpenAI’s API. Most models make a PNG, and we convert it to the JPEG or WebP you asked for inside Cloudflare’s network (about 0.1 to 0.4 seconds; a 2 MB PNG becomes a JPEG or WebP of about 250 KB). gpt-image-2.6-flare and gpt-image-2.6-sunburst make JPEG and WebP themselves.
| Model | PNG | JPEG | WebP | GIF | SVG |
|---|---|---|---|---|---|
gpt-image-2, gpt-image-2.5, gpt-image-2-adobe | Yes | Yes | Yes | – | – |
gpt-image-2.6 | Yes | Yes | Yes | Yes | Yes |
gpt-image-2.5-flare, gpt-image-2.5-sunburst | Yes | Yes | Yes | – | – |
gpt-image-2.6-flare, gpt-image-2.6-sunburst | Yes | Yes | Yes | Yes | – |
| Nano Banana (all versions) | Yes | Yes | Yes | – | – |
“–” returns a 400. output_compression sets the JPEG or WebP quality on every model (default 100). A GIF can take three to five minutes. The file’s real type is in the link’s extension and its Content-Type.
How many credits a request uses
A request uses n times the model’s credits: 8 per image for GPT Image 2, 2.5 and 2.6, 12 for Nano Banana 2 and 2.1, 20 for Nano Banana Pro, gpt-image-2-adobe and the flare variants, 25 for the sunburst variants, 60 to 180 for the Nano Banana stable channels. If fewer images come back than you asked for, you pay only for the images you received.
Sending the same request twice
Add an Idempotency-Key header with a value of your choice. If the same key arrives again while the first request is running or after it succeeded, the API answers 409 and does not generate or charge again. After a failed request you can reuse the key.