AI API: images
How to generate an image through the AI API, from a description or from a reference. Size and aspect ratio, response format, price per image and common refusals.
Images are made by models of kind image, for example gpt-image-2.5 or nano-banana-pro. The
key, base URL and common errors are the same as for chat, see
AI API: connecting and requests.
| Task | Endpoint | Body format |
|---|---|---|
| An image from a description | POST /v1/images/generations | JSON |
| An image from a description and references | POST /v1/images/edits | multipart/form-data |
Both endpoints work like OpenAI's, so the OpenAI SDK fits too: client.images.generate and
client.images.edit.
Image from a description
curl https://api.lumean.app/v1/images/generations \
-H "Authorization: Bearer $LUMEAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5",
"prompt": "Sunset over the sea, watercolor",
"size": "1536x864"
}'| Field | Required | What it sets |
|---|---|---|
model | yes | A model of kind image |
prompt | yes | The image description |
size | no | Size in pixels, WxH, or auto. See "Size and aspect ratio" |
aspect_ratio | no | Aspect ratio, W:H, or auto. See "Size and aspect ratio" |
response_format | no | b64_json returns the image in the response body instead of a link |
n | no | Only 1. If you need several images, send several requests |
The model also gets the fields quality, style, background, output_format,
output_compression and moderation, if it understands them. Other fields don't reach the model.
Python (OpenAI SDK)
from openai import OpenAI
client = OpenAI(base_url="https://api.lumean.app/v1", api_key="LUMEAN_API_KEY")
image = client.images.generate(
model="gpt-image-2.5",
prompt="Sunset over the sea, watercolor",
size="1536x864",
)
print(image.data[0].url)Size and aspect ratio
Each model has its own set of sizes. The model catalog returns it in the
capabilities.image_options field:
curl -s "https://api.lumean.app/api/public/ai/models/gpt-image-2.5" \
-H "X-API-KEY: $LUMEAN_API_KEY""capabilities": {
"image_output": true,
"image_options": {
"size": ["auto", "1024x1024", "1536x864", "864x1536", "1280x960", "960x1280", "1536x1024", "1024x1536"]
}
}- A key in
image_optionsis the request field name (sizeoraspect_ratio), and the value is the allowed options. The first option applies when the field isn't sent. - Pass a value from the list in the same field: in JSON for
/v1/images/generations, as a text form field for/v1/images/edits. - If a model has no
image_options, or the one you need isn't in it, the model doesn't choose this parameter. Don't send the field. - A value not from the list goes to the provider as is, and it may answer
400. Such a refusal isn't charged.
Aspect ratios and sizes for the GPT Image family of models:
| Aspect ratio | size |
|---|---|
| 1:1 | 1024x1024 |
| 16:9 | 1536x864 |
| 9:16 | 864x1536 |
| 4:3 | 1280x960 |
| 3:4 | 960x1280 |
| 3:2 | 1536x1024 |
| 2:3 | 1024x1536 |
| the model chooses | auto |
The set may change. Check the catalog before you hardcode a size.
Note
The models nano-banana-2, nano-banana-pro, gemini-3-pro-image-preview and
gemini-3.1-flash-image draw through chat and don't accept a size: size and aspect_ratio are
silently ignored for them, and the catalog has no image_options. You can ask for the shape in
words in prompt, but there's no guarantee.
Image from a reference
/v1/images/edits takes a description and from one to four reference images: a character to keep,
a photo to edit, a style. The body is multipart/form-data.
curl https://api.lumean.app/v1/images/edits \
-H "Authorization: Bearer $LUMEAN_API_KEY" \
-F model=gpt-image-2.5 \
-F prompt="The same character on the beach" \
-F size=1536x864 \
-F image=@character.png| Field | Required | What it sets |
|---|---|---|
model, prompt | yes | As in generation from a description |
image or image[] | yes | Reference files, 1 to 4. One goes in the image field, several in image[] |
mask | no | A PNG mask: the model redraws the transparent areas and keeps the rest |
size, aspect_ratio, response_format, n | no | As in generation from a description, as text form fields |
References are PNG, JPEG, WEBP or GIF, up to 20 MiB each. The request body with the files is up to 32 MiB.
# Several references
curl https://api.lumean.app/v1/images/edits \
-H "Authorization: Bearer $LUMEAN_API_KEY" \
-F model=gpt-image-2.5 \
-F prompt="The character from the first image in the costume from the second" \
-F "image[]=@character.png" \
-F "image[]=@costume.png"Response
{
"created": 1764601200,
"data": [{"url": "https://…"}]
}data[0].url is a link to the finished image in Lumean storage. It's valid for 7 days. If you
need the image longer, download it.
With "response_format": "b64_json", you get the image itself in base64 instead of a link:
"data": [{"b64_json": "iVBORw0…"}].
Image through chat
You can call an image model through POST /v1/chat/completions too. The description is then taken
from the last user message, and the images in it (image_url, up to four) become references. The
response is a regular chat message with a link in Markdown: .
You can't choose the size through chat. If you need a specific size, use
/v1/images/generations or /v1/images/edits.
Price
An image is always charged one price per call: the price.request.per_call_* field in the
catalog. The price is the same for any size, aspect ratio and quality. If generation fails, no
money is charged.
An image model without a per-call price can't be used for paid requests right now: a request to it
gets 404 model_disabled.
The price follows the provider's, so check the catalog before expensive generations. How to do that from code is in AI API: prices and spending.
Image errors
Common AI API errors are in AI API: connecting and requests. These occur only with images:
| Code | code | Cause | What to do |
|---|---|---|---|
400 | invalid_request_body | No model or prompt, or the body isn't JSON | Add the fields |
400 | unsupported_n | n is greater than 1 | Send several requests |
400 | model_not_image | The model can't draw | Pick a model of kind image |
400 | invalid_image_reference | No references, more than four, a file isn't an image or is over 20 MiB | Attach 1 to 4 PNG, JPEG, WEBP or GIF files up to 20 MiB |
400 | endpoint_not_supported | An image model was called through /v1/responses or /v1/messages | Use the image endpoints or /v1/chat/completions |
400 | — | The provider rejected the request: the size isn't from the list, or the description breaks its rules | Take a size from the catalog, rewrite the description |
502 | image_missing | The provider answered without an image | Retry the request, and if it repeats, rewrite the description |
503 | images_unavailable | Image generation is temporarily unavailable | Retry later |
This page for AI
Updated 12/01/2026 · API version 1.0.0