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.
Text-to-image
Section titled “Text-to-image”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 }'Image-to-image (reference image)
Section titled “Image-to-image (reference image)”Upload a source image via Files API first, then pass the file_id. This singular field remains supported for backward compatibility:
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 }'Multiple reference images
Section titled “Multiple reference images”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.
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”| Dimension | file_ids (upload via /v1/files first) | image_urls (data URL or https URL) |
|---|---|---|
| HTTP round trips | Two (upload + generations) | One |
| Large images (> 1–2 MB) | Preferred — JSON body stays small | Base64 in JSON inflates by ~33% |
| Reusing the same reference across requests | Preferred — upload once, reuse file_id for 7 days | Resent on every request |
| One-off, fast experiments | Slower (two requests) | Preferred — pass the data URL or https URL directly |
| Referencing a public hosted image | Requires download + upload | Pass the https URL directly |
| Cleanup | Files are deleted automatically after 7 days | No 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.
Try-on: merging two images
Section titled “Try-on: merging two images”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.
# 1) Upload the model photo, capture the file_idcurl "$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_idcurl "$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 requestcurl "$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.
Parameters
Section titled “Parameters”| Field | Values |
|---|---|
size | 512, 1K, 2K |
aspect_ratio | 1:1, 3:4, 4:3, 9:16, 16:9 |
n | 1-4 |
file_id | Optional single reference image |
file_ids | Optional list of reference images |
image_url | Optional single remote or inline reference image |
image_urls | Optional 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.
Response
Section titled “Response”{ "created": 1739200000, "data": [ { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA...", "revised_prompt": "A minimalist modern..." } ]}Pricing
Section titled “Pricing”Billed per image by native unit. See the model card in Dashboard > Models.