Skip to content

Image Generation

Google Gemini image generation models are exposed through /v1/images/generations for text-to-image, image-to-image, and multi-reference image generation. Imagen models run as text-to-image through this gateway. For OpenAI gpt-image-2 text-to-image usage, see Gateway image generation.

Terminal window
curl "$LLMTR_BASE_URL/v1/images/generations" \
-H "Authorization: Bearer llmtr-your_key" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.1-flash-image",
"prompt": "A minimalist modern workspace with warm light",
"size": "1K",
"aspect_ratio": "16:9",
"n": 1
}'

Upload a source image via Files API first, then pass the file_id. This singular field remains supported for backward compatibility:

Terminal window
curl "$LLMTR_BASE_URL/v1/images/generations" \
-H "Authorization: Bearer llmtr-your_key" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.1-flash-image",
"prompt": "Turn this product photo into an ad poster",
"file_id": "file_xxx",
"size": "1K",
"aspect_ratio": "1:1",
"n": 1
}'

Use file_ids to send more than one reference image to Gemini image models. The total reference image limit is 8 across file_id, file_ids, image_url, and image_urls.

Terminal window
curl "$LLMTR_BASE_URL/v1/images/generations" \
-H "Authorization: Bearer llmtr-your_key" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.1-flash-image",
"prompt": "Combine these two product photos into one ad composition",
"file_ids": ["file_front", "file_back"],
"size": "1K",
"aspect_ratio": "16:9",
"n": 1
}'

For remote or inline image references, image_url and image_urls are also supported. File-based references are recommended for larger images and references reused across requests.

file_ids vs image_urls — when to use which

Section titled “file_ids vs image_urls — when to use which”
Dimensionfile_ids (upload via /v1/files first)image_urls (data URL or https URL)
HTTP round tripsTwo (upload + generations)One
Large images (> 1–2 MB)Preferred — JSON body stays smallBase64 in JSON inflates by ~33%
Reusing the same reference across requestsPreferred — upload once, reuse file_id for 7 daysResent on every request
One-off, fast experimentsSlower (two requests)Preferred — pass the data URL or https URL directly
Referencing a public hosted imageRequires download + uploadPass the https URL directly
CleanupFiles are deleted automatically after 7 daysNo storage; per-request only

Rule of thumb: for try-on, image-to-image and repeated compositions with large references use file_ids; for one-off compositions or direct public-URL references use image_urls. A single request can combine both; the total reference image limit is 8.

To dress a person from a model photo with a separate garment photo, compose a product into a scene, or otherwise merge two reference images, pass both file_ids in a single /v1/images/generations request. The flow is three steps: upload each image through /v1/files, collect the returned file_ids, and send them as a file_ids array.

Terminal window
# 1) Upload the model photo, capture the file_id
curl "$LLMTR_BASE_URL/v1/files" \
-H "Authorization: Bearer llmtr-your_key" \
-F "provider=google" \
-F "purpose=vision_reference" \
-F "file=@./model.jpg"
# → {"id": "file_model_xxx", ...}
# 2) Upload the garment photo, capture the file_id
curl "$LLMTR_BASE_URL/v1/files" \
-H "Authorization: Bearer llmtr-your_key" \
-F "provider=google" \
-F "purpose=vision_reference" \
-F "file=@./garment.jpg"
# → {"id": "file_garment_yyy", ...}
# 3) Merge both references in one request
curl "$LLMTR_BASE_URL/v1/images/generations" \
-H "Authorization: Bearer llmtr-your_key" \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemini-3.1-flash-image",
"prompt": "Dress the person in the first image with the t-shirt from the second image. Keep the lighting and shadows consistent with the model photo, and preserve the pattern and colors from the garment photo.",
"file_ids": ["file_model_xxx", "file_garment_yyy"],
"n": 1
}'

All reference-image flows, including try-on, run through /v1/images/generations. On LLMTR, /v1/images/edits is open only for xAI image models; calling it with a Google model returns a 400 whose response body points back to this flow. Imagen models support text-to-image only and cannot be called with file_ids.

FieldValues
size512, 1K, 2K
aspect_ratio1:1, 3:4, 4:3, 9:16, 16:9
n1-4
file_idOptional single reference image
file_idsOptional list of reference images
image_urlOptional single remote or inline reference image
image_urlsOptional list of remote or inline reference images

When file_id, file_ids, image_url, and image_urls are combined, duplicate values are deduplicated. Google Imagen models do not support reference image fields on this gateway; send prompt-only text-to-image requests.

{
"created": 1739200000,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"revised_prompt": "A minimalist modern..."
}
]
}

Billed per image by native unit. See the model card in Dashboard > Models.