Image Generation
/v1/images/generations calls image generation models from the LLMTR catalog through one JSON endpoint. For OpenAI, openai/gpt-image-2 is supported for text-to-image. For Recraft, V2, V3, and V4 raster/vector models are available for text-to-image. For Google, Imagen 4 (fast/generate/ultra) is text-to-image only, while Gemini image models support both text-to-image and reference-image generation (image-to-image, try-on, image merging). For xAI, xai/grok-imagine-image and xai/grok-imagine-image-quality perform text-to-image; xAI’s image editing flow lives on the separate /v1/images/edits endpoint.
Which endpoint?
Section titled “Which endpoint?”| What you want to do | Endpoint | Supported providers | Key fields |
|---|---|---|---|
| Generate an image from scratch (text-to-image) | /v1/images/generations | OpenAI, Google, Recraft, xAI | prompt |
| Generate from a reference image (image-to-image, try-on, image merging) | /v1/images/generations | Google Gemini image models | file_ids, image_urls |
| Edit an image (xAI image edits) | /v1/images/edits | xAI only (xai/grok-imagine-image, xai/grok-imagine-image-quality) | image |
/v1/images/edits is available only for xAI image models. Calling it with a Google or OpenAI model returns 400 unsupported_operation and the response body steers you to the correct endpoint: Google routes to /v1/images/generations with file_ids; OpenAI and Recraft route to text-to-image. To enumerate every image-capable model from the catalog: GET /api/models?operation=IMAGES_GENERATIONS.
Recraft
Section titled “Recraft”curl "$LLMTR_BASE_URL/v1/images/generations" \ -H "Authorization: Bearer llmtr-your_key" \ -H "Content-Type: application/json" \ -d '{ "model": "recraft/recraft-v4-pro", "prompt": "Premium coffee packaging product visual on a white background with soft shadows", "size": "1:1", "response_format": "url", "n": 1 }'Recraft Parameters
Section titled “Recraft Parameters”| Field | Values | Notes |
|---|---|---|
model | recraft/recraft-v4, recraft/recraft-v4-vector, recraft/recraft-v4-pro, recraft/recraft-v4-pro-vector, recraft/recraft-v3, recraft/recraft-v3-vector, recraft/recraft-v2, recraft/recraft-v2-vector | Canonical LLMTR model ID. |
size | 1:1, 16:9, 9:16, and other Recraft-supported aspect ratios; supported explicit sizes for raster models | Vector models use aspect ratios rather than explicit pixel sizes. |
response_format | url, b64_json | Defaults to url. |
n | 1-6 | Number of images to generate in one request. |
For Recraft, this first version accepts text-to-image JSON requests only. image_url, image_urls, file_id, file_ids, mask, stream, partial_images, style, style_id, negative_prompt, text_layout, and controls are rejected on this endpoint.
OpenAI GPT Image 2
Section titled “OpenAI GPT Image 2”curl "$LLMTR_BASE_URL/v1/images/generations" \ -H "Authorization: Bearer llmtr-your_key" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-image-2", "prompt": "A minimalist product photo of a coffee mug on a white background with natural light", "size": "1024x1024", "quality": "medium", "output_format": "png", "background": "opaque", "moderation": "auto", "n": 1 }'OpenAI Parameters
Section titled “OpenAI Parameters”| Field | Values | Notes |
|---|---|---|
size | 1024x1024, 1024x1536, 1536x1024 | Defaults to 1024x1024. |
quality | low, medium, high | Defaults to medium. |
output_format | png, jpeg, webp | Defaults to png. |
output_compression | 0-100 | Only valid with jpeg and webp. |
background | opaque, auto | transparent is not supported by gpt-image-2. |
moderation | auto, low | Uses the provider default when omitted. |
n | 1-4 | Number of images to generate in one request. |
For OpenAI, image_url, image_urls, file_id, file_ids, mask, stream, and partial_images are rejected on this endpoint. Those fields belong to edits and streaming flows and require separate security and billing support.
Google Models
Section titled “Google Models”Google image models continue to use the same endpoint. Gemini image models accept reference images through file_id, file_ids, image_url, and image_urls. Use the Google image generation page for Google-specific image-to-image and multi-reference examples.
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", "size": "1K", "aspect_ratio": "16:9", "n": 1 }'xAI Grok Imagine
Section titled “xAI Grok Imagine”curl "$LLMTR_BASE_URL/v1/images/generations" \ -H "Authorization: Bearer llmtr-your_key" \ -H "Content-Type: application/json" \ -d '{ "model": "xai/grok-imagine-image", "prompt": "Studio product photo of a matte black mechanical keyboard", "aspect_ratio": "16:9", "resolution": "1k", "response_format": "url", "n": 1 }'xAI image edits send one or more reference images in JSON:
curl "$LLMTR_BASE_URL/v1/images/edits" \ -H "Authorization: Bearer llmtr-your_key" \ -H "Content-Type: application/json" \ -d '{ "model": "xai/grok-imagine-image", "prompt": "Keep the product, replace the background with a clean white studio", "image": { "type": "image_url", "url": "https://example.com/input.png" }, "response_format": "b64_json" }'xAI response url fields (on the imgen.x.ai domain) are short-lived; the TTL is inherited from upstream and LLMTR does not extend it. To display the image persistently in your UI:
- Use
response_format: "b64_json"— the response carries base64-encoded bytes you can store yourself; this is the recommended default shown above. - Or, if you received a
url, download it as soon as the response comes back and mirror it on your own CDN. Do not surface theimgen.x.aiURL directly to end users.
Response
Section titled “Response”{ "created": 1773000000, "model": "openai/gpt-image-2", "data": [ { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA...", "mime_type": "image/png" } ], "usage": { "input_tokens": 20, "output_tokens": 400, "total_tokens": 420, "input_tokens_details": { "text_tokens": 20 } }}Pricing
Section titled “Pricing”gpt-image-2 is billed by tokens: input text, input image, and output image tokens are calculated with separate price rules. Recraft models are billed per image: V4 $0.04, V4 Vector $0.08, V4 Pro $0.25, V4 Pro Vector $0.30, V3 $0.04, V3 Vector $0.08, V2 $0.022, and V2 Vector $0.044. xAI grok-imagine-image is cataloged at $0.02 per image, and grok-imagine-image-quality at $0.04 per image. If xAI returns usage.cost_in_usd_ticks, settlement uses the real provider cost; otherwise the official per-image price is used as a deterministic fallback. Image edit fallback counts both input images and generated output images. LLMTR does not add platform margin to model prices; the 6% platform margin only applies when credits are topped up.