Skip to content
Lumean

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.

TaskEndpointBody format
An image from a descriptionPOST /v1/images/generationsJSON
An image from a description and referencesPOST /v1/images/editsmultipart/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"
  }'
FieldRequiredWhat it sets
modelyesA model of kind image
promptyesThe image description
sizenoSize in pixels, WxH, or auto. See "Size and aspect ratio"
aspect_rationoAspect ratio, W:H, or auto. See "Size and aspect ratio"
response_formatnob64_json returns the image in the response body instead of a link
nnoOnly 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_options is the request field name (size or aspect_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 ratiosize
1:11024x1024
16:91536x864
9:16864x1536
4:31280x960
3:4960x1280
3:21536x1024
2:31024x1536
the model choosesauto

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
FieldRequiredWhat it sets
model, promptyesAs in generation from a description
image or image[]yesReference files, 1 to 4. One goes in the image field, several in image[]
masknoA PNG mask: the model redraws the transparent areas and keeps the rest
size, aspect_ratio, response_format, nnoAs 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: ![image](https://…).

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:

CodecodeCauseWhat to do
400invalid_request_bodyNo model or prompt, or the body isn't JSONAdd the fields
400unsupported_nn is greater than 1Send several requests
400model_not_imageThe model can't drawPick a model of kind image
400invalid_image_referenceNo references, more than four, a file isn't an image or is over 20 MiBAttach 1 to 4 PNG, JPEG, WEBP or GIF files up to 20 MiB
400endpoint_not_supportedAn image model was called through /v1/responses or /v1/messagesUse 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 rulesTake a size from the catalog, rewrite the description
502image_missingThe provider answered without an imageRetry the request, and if it repeats, rewrite the description
503images_unavailableImage generation is temporarily unavailableRetry later

This page for AI

Open .mdllm.md

Updated 12/01/2026 · API version 1.0.0