Image Generation
Generate images using AI models through the OpenAI-compatible images API or chat completions API
LLMGateway supports image generation through two APIs:
/v1/images/generations— OpenAI-compatible images endpoint (recommended for simple image generation)/v1/images/edits— OpenAI-compatible image editing endpoint/v1/chat/completions— Chat completions with image generation models (for conversational image generation and editing)
For asynchronous video generation, see Video Generation.
Available Models
You can find all available image generation models on our models page.
OpenAI Images API
The /v1/images/generations endpoint provides a drop-in replacement for OpenAI's image generation API. It works with any OpenAI-compatible client library.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
prompt | string | required | A text description of the desired image(s) |
model | string | "auto" | The model to use. auto resolves to gemini-3-pro-image |
n | integer | 1 | Number of images to generate (1-10) |
size | string | — | Image dimensions. Supported sizes depend on the model/provider — see Image Configuration |
quality | string | — | Image quality. Supported values depend on the model/provider — see Image Configuration |
moderation | string | "auto" | Content filtering strictness for models that support it: auto or low — see Moderation |
complexity | string | — | low, medium, or high for supported models — see Complexity |
frame_count | integer | — | GIF frames, 2–16; requires output_format: "gif" |
frame_duration_ms | integer | — | GIF frame duration in milliseconds, 20–2000 |
response_format | string | "b64_json" | Only b64_json is supported |
style | string | — | Image style: vivid or natural |
output_format | string | "png" | GPT Image models: png, jpeg, webp, svg, or gif — see SVG output |
output_compression | integer | — | GPT Image models: 0–100, for jpeg and webp output |
service_tier | string | — | Processing tier for mappings that offer one: flex, priority, or default — see Service Tiers |
curl
curl -X POST "https://api.llmgateway.io/v1/images/generations" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-pro-image",
"prompt": "A cute cat wearing a tiny top hat",
"n": 1,
"size": "1024x1024"
}'Usage and cost
Both /v1/images/generations and /v1/images/edits return a usage object with the token counts and the billed cost of the request, in USD:
"usage": {
"input_tokens": 10,
"input_tokens_details": { "image_tokens": 0, "text_tokens": 10 },
"output_tokens": 229,
"output_tokens_details": { "image_tokens": 229, "text_tokens": 0 },
"total_tokens": 239,
"cost": 0.00692,
"cost_details": { "input_cost": 0.00005, "image_output_cost": 0.00687 }
}cost_details has the same fields as usage.cost_details on chat completions.
GIF output
GPT Image 2.6 Sunburst and Flare support output_format: "gif" on generations and edits, including multipart edits. Set frame_count (2–16) and frame_duration_ms (20–2000) to control the animation. Omit them to use OpenAI's defaults. output_compression is not supported for GIF.
data[0].b64_json contains the GIF bytes, and the response echoes output_format: "gif". In chat completions, put these options in image_config; the image URL uses data:image/gif;base64,.... The gateway requests GIFs synchronously from the provider, including for streaming chat clients.
{
"model": "openai/gpt-image-2.6-flare",
"prompt": "Animate a bouncing ball",
"output_format": "gif",
"frame_count": 8,
"frame_duration_ms": 100
}SVG output
GPT Image 2.6 (openai/gpt-image-2.6-sunburst and openai/gpt-image-2.6-flare) returns vector graphics when you set output_format: "svg". Use it for icons, logos, stickers, and illustrations that need editable paths, shapes, and colors.
curl -X POST "https://api.llmgateway.io/v1/images/generations" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-image-2.6-flare",
"prompt": "A flat bakery logo: a golden loaf above the words Field & Flour",
"output_format": "svg",
"svg": { "model": "gpt-5.4-mini", "reasoning": { "effort": "low" } },
"quality": "medium"
}' | jq -r '.data[0].b64_json' | base64 --decode > logo.svgdata[0].b64_json holds the base64-encoded SVG document (UTF-8 XML), and the response echoes "output_format": "svg". The document contains static vector content only: no scripts, external resources, or embedded raster images.
nmust be1, andoutput_compressionis not accepted./v1/images/editsreturns SVG too, drawn from your input images, with the samesvgoptions (multipart:svg[model]andsvg[reasoning][effort]). An SVG is not accepted as an edit input. The gateway requests SVG from OpenAI without streaming.qualitycontrols the reference image the SVG is drawn from.- If your OpenAI account has SVG model selection enabled, supply
svg.modelas in the example; otherwise omitsvg. Optionalsvg.reasoning.effortcontrols the author independently of image quality. - On
/v1/images/generationsand/v1/images/edits, requestingsvgfrom a model without SVG output, or fromauto, returns a400before any provider is called. In chat completions, the provider judges the value.
OpenAI draws a reference image with the image model, then a separate authoring model writes the SVG. The request is billed for both: the image tokens at the image model's rates, and the authoring model's tokens at that model's catalogue rates, included in input_cost and output_cost. Each component uses its own model's applicable discount. If the authoring model's rates are unknown, its authoring cost is omitted and logged for reconciliation; the reference image is still billed.
In chat completions, set image_config.output_format to "svg" and pass author settings in image_config.svg; the image arrives as a data:image/svg+xml;base64,... URL.
OpenAI SDK
Works with the standard OpenAI client library — just point the base URL to LLMGateway.
import OpenAI from "openai";
import { writeFileSync } from "fs";
const client = new OpenAI({
baseURL: "https://api.llmgateway.io/v1",
apiKey: process.env.LLM_GATEWAY_API_KEY,
});
const response = await client.images.generate({
model: "gemini-3-pro-image",
prompt: "A futuristic city skyline at sunset with flying cars",
n: 1,
size: "1024x1024",
});
response.data.forEach((image, i) => {
if (image.b64_json) {
const buf = Buffer.from(image.b64_json, "base64");
writeFileSync(`image-${i}.png`, buf);
}
});Vercel AI SDK
Use the @llmgateway/ai-sdk-provider with generateImage.
import { createLLMGateway } from "@llmgateway/ai-sdk-provider";
import { generateImage } from "ai";
import { writeFileSync } from "fs";
const llmgateway = createLLMGateway({
apiKey: process.env.LLM_GATEWAY_API_KEY,
});
const result = await generateImage({
model: llmgateway.image("gemini-3-pro-image"),
prompt:
"A cozy cabin in a snowy mountain landscape at night with aurora borealis",
size: "1024x1024",
n: 1,
// aspectRatio and quality are model-specific — only some providers honor them.
// aspectRatio works on Gemini image models; OpenAI gpt-image-2 ignores it
// (use a literal WxH `size` instead).
aspectRatio: "16:9",
// quality works on OpenAI gpt-image-2 ("low" | "medium" | "high" | "auto").
// The AI SDK only forwards it through providerOptions.
providerOptions: {
llmgateway: { quality: "high" },
},
});
result.images.forEach((image, i) => {
const buf = Buffer.from(image.base64, "base64");
writeFileSync(`image-${i}.png`, buf);
});OpenAI Images Edit API
The /v1/images/edits endpoint is OpenAI-compatible and supports a focused subset of images.edit parameters.
When /v1/chat/completions is converted to an OpenAI-compatible multipart image edit, remote input images must return an image content type and stay within the caller's image size limit. The gateway checks downloaded bytes even when Content-Length is missing or understated, stops oversized downloads, and returns a 400 error.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
images | array of { image_url } | yes | Input images. image_url supports HTTPS URLs and base64 data URLs |
prompt | string | yes | A text description of the desired image edit |
model | string | no | Image editing model |
background | enum | no | transparent, opaque, or auto — see Transparency |
input_fidelity | enum | no | high or low |
n | integer | no | Number of edited images to generate |
output_format | enum | no | png, jpeg, webp, gif, or svg — see SVG output |
svg | object | no | SVG author model and reasoning.effort — see SVG output |
output_compression | integer | no | Compression level for jpeg/webp |
quality | enum | no | low, medium, high, or auto; GPT Image 2.5 also supports xhigh and max |
moderation | enum | no | auto or low — see Moderation |
complexity | enum | no | low, medium, or high — see Complexity |
frame_count | integer | no | GIF frames, 2–16; requires output_format: "gif" |
frame_duration_ms | integer | no | GIF frame duration in milliseconds, 20–2000 |
size | string | no | Output size. Examples: 1024x1024, 1536x1024, 1K, 2K, 4K |
aspect_ratio | string | no | Aspect ratio override. Examples: 1:1, 16:9, 4:3, 5:4 |
service_tier | enum | no | flex, priority, or default — see Service Tiers |
mask is not supported yet on /v1/images/edits.
multipart/form-data requests upload one image file instead of images. input_fidelity, aspect_ratio, and service_tier are JSON-only.
Edit markup
Send a markup PNG to guide a focused edit. For JSON requests, pass markup: { "image_url": "https://example.com/markup.png" } (a PNG data URL also works). For multipart edits, upload it as the separate markup file field. Markup is forwarded separately, not added as a reference image.
Use a PNG under the current image upload limit, with the same dimensions as the first input image. Markup is forwarded to OpenAI and Azure image models; availability depends on the model. It cannot be combined with the multipart mask field. Provider file IDs are not accepted for markup.
Transparency
On /v1/images/edits and in chat image_config, background, output_format, and output_compression are sent to OpenAI and Azure, which return a 4xx for values the model does not support. /v1/images/generations accepts output_format and output_compression but not background. For a transparent image, use openai/gpt-image-2.5-sunburst or openai/gpt-image-2.5-flare with background: "transparent" and output_format: "png" or "webp".
Other providers do not receive these as parameters. /v1/images/edits adds them to the prompt instead, so their output can be opaque. When a request sets output_format, the response reports the format the provider returned if the gateway can detect it, and otherwise omits the field.
curl (HTTPS image URL)
curl -X POST "https://api.llmgateway.io/v1/images/edits" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"images": [
{
"image_url": "https://example.com/source-image.png"
}
],
"prompt": "Add a watercolor effect to this image",
"model": "gemini-3-pro-image",
"aspect_ratio": "16:9",
"quality": "high",
"size": "4K"
}'curl (base64 data URL)
curl -X POST "https://api.llmgateway.io/v1/images/edits" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"images": [
{
"image_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
],
"prompt": "Turn this into a pixel-art style image"
}'Chat Completions API
Image generation also works through the /v1/chat/completions endpoint, which is useful for conversational image generation, image editing with vision, and multi-turn interactions.
Making Requests
Simply use an image generation model and provide a text prompt describing the image you want to create.
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-pro-image",
"messages": [
{
"role": "user",
"content": "Generate an image of a cute golden retriever puppy playing in a sunny meadow"
}
]
}'Response Format
Image generation models return responses in the standard chat completions format, with generated images included in the images array within the assistant message:
{
"id": "chatcmpl-1756234109285",
"object": "chat.completion",
"created": 1756234109,
"model": "gemini-3-pro-image",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Here's an image of a cute dog for you: ",
"images": [
{
"type": "image_url",
"image_url": {
"url": "data:image/png;base64,<base64_encoded_image_data>"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 1303,
"total_tokens": 1311
}
}A request stopped by the gateway content filter returns finish_reason: "content_filter" on the Chat Completions API and an empty data array on the Images API.
A provider's own safety rejection is returned the same way, and it is billed the way the provider bills us: a rejection the provider returns as an error carries no usage and costs nothing, apart from a rejection fee the provider publishes (currently only xAI's chat models). A block the provider serves as a normal response with usage, as Gemini image models do, is charged for the input tokens it reports, never for the blocked image.
Vision support
You can edit or modify images by combining image generation with vision models by including the image in the messages array.
Response Structure
Images Array
The images array contains one or more generated images with the following structure:
type: Always"image_url"for generated imagesimage_url.url: A data URL containing the base64-encoded image data (format:data:image/png;base64,<data>)
Content Field
The content field may contain descriptive text about the generated image, depending on the model's behavior.
AI SDK (Chat Completions)
You can use the AI SDK to generate images with your existing generateText or streamText calls using the LLMGateway provider.
Example
import { streamText, type UIMessage, convertToModelMessages } from "ai";
import { createLLMGateway } from "@llmgateway/ai-sdk-provider";
interface ChatRequestBody {
messages: UIMessage[];
}
export async function POST(req: Request) {
const body = await req.json();
const { messages }: ChatRequestBody = body;
const llmgateway = createLLMGateway({
apiKey: "llmgateway_api_key",
baseUrl: "https://api.llmgateway.io/v1",
});
try {
const result = streamText({
model: llmgateway.chat("gemini-3-pro-image"),
messages: convertToModelMessages(messages),
});
return result.toUIMessageStreamResponse();
} catch {
return new Response(
JSON.stringify({ error: "LLM Gateway request failed" }),
{
status: 500,
},
);
}
}Then you can render the image in your frontend using the Image component from the ai-elements.
Here is a full example of how to use the AI SDK to generate images in your frontend:
"use client";
import { useState, useRef } from "react";
import { useChat } from "@ai-sdk/react";
import { parseImagePartToDataUrl } from "@/lib/image-utils";
import {
PromptInput,
PromptInputBody,
PromptInputButton,
PromptInputSubmit,
PromptInputTextarea,
PromptInputToolbar,
} from "@/components/ai-elements/prompt-input";
import {
Conversation,
ConversationContent,
} from "@/components/ai-elements/conversation";
import { Image } from "@/components/ai-elements/image";
import { Loader } from "@/components/ai-elements/loader";
import { Message, MessageContent } from "@/components/ai-elements/message";
import { Response } from "@/components/ai-elements/response";
export const ChatUI = () => {
const textareaRef = useRef<HTMLTextAreaElement | null>(null);
const [text, setText] = useState("");
const { messages, status, stop, regenerate, sendMessage } = useChat();
return (
<>
<div className="flex-1 overflow-y-auto px-4 pb-24">
<Conversation>
<ConversationContent>
{messages.length === 0 ? (
<div className="mb-6 text-center">
<h2 className="text-3xl font-semibold tracking-tight">
How can I help you?
</h2>
</div>
) : (
messages.map((m, messageIndex) => {
const isLastMessage = messageIndex === messages.length - 1;
if (m.role === "assistant") {
const textContent = m.parts
.filter((p) => p.type === "text")
.map((p) => p.text)
.join("");
// Combine all image parts (both image_url and file types)
const imageParts = m.parts.filter(
(p) =>
p.type === "file" && p.mediaType?.startsWith("image/"),
);
return (
<div key={m.id}>
{textContent ? <Response>{textContent}</Response> : null}
{imageParts.length > 0 ? (
<div className="mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2">
{imageParts.map((part, idx: number) => {
const { base64Only, mediaType } =
parseImagePartToDataUrl(part);
if (!base64Only) {
return null;
}
return (
<Image
key={idx}
base64={base64Only}
mediaType={mediaType}
alt={part.name || "Generated image"}
/>
);
})}
</div>
) : null}
{isLastMessage &&
(status === "submitted" || status === "streaming") && (
<Loader />
)}
</div>
);
} else {
return (
<Message key={m.id} from={m.role}>
<MessageContent variant="flat">
{m.parts.map((p, i) => {
if (p.type === "text") {
return <div key={i}>{p.text}</div>;
}
return null;
})}
</MessageContent>
{isLastMessage &&
(status === "submitted" || status === "streaming") && (
<Loader />
)}
</Message>
);
}
})
)}
</ConversationContent>
</Conversation>
</div>
<div className="sticky bottom-0 left-0 right-0 px-4 pb-[max(env(safe-area-inset-bottom),1rem)] pt-2 bg-gradient-to-t from-background via-background/95 to-transparent backdrop-blur supports-[backdrop-filter]:bg-background/60">
<PromptInput
aria-disabled={status === "streaming"}
onSubmit={async (message) => {
if (status === "streaming") {
return;
}
try {
const textContent = message.text ?? "";
if (!textContent.trim()) {
return;
}
setText(""); // Clear input immediately
const parts = [{ type: "text", text: textContent }];
// Call sendMessage which will handle adding the user message and API request
sendMessage({
role: "user",
parts,
});
} catch (error) {
// Throw error here
}
}}
>
<PromptInputBody>
<PromptInputTextarea
ref={textareaRef}
value={text}
onChange={(e) => setText(e.currentTarget.value)}
placeholder="Message"
/>
</PromptInputBody>
<PromptInputToolbar>
<div className="flex items-center gap-2">
{status === "streaming" ? (
<PromptInputButton onClick={() => stop()} variant="ghost">
Stop
</PromptInputButton>
) : null}
<PromptInputSubmit
status={status === "streaming" ? "streaming" : "ready"}
/>
</div>
</PromptInputToolbar>
</PromptInput>
</div>
</>
);
};/**
* Parses a file object containing image data and returns a properly formatted data URL
* and normalized media type.
*
* Handles:
* - Normalizing mediaType from various property names (mediaType, mime_type)
* - Detecting existing data: URLs
* - Detecting base64-looking content
* - Stripping whitespace from base64 content
* - Building proper data:...;base64,... URLs
*/
export function parseImageFile(file: {
url?: string;
mediaType?: string;
mime_type?: string;
}): { dataUrl: string; mediaType: string } {
const mediaType = file.mediaType || file.mime_type || "image/png";
let url = String(file.url || "");
const isDataUrl = url.startsWith("data:");
const looksLikeBase64 =
!isDataUrl && /^[A-Za-z0-9+/=\s]+$/.test(url.slice(0, 200));
if (looksLikeBase64) {
url = url.replace(/\s+/g, "");
}
const dataUrl = isDataUrl
? url
: looksLikeBase64
? `data:${mediaType};base64,${url}`
: url;
return { dataUrl, mediaType };
}
/**
* Extracts base64-only content from a data URL.
* Returns empty string if the input is not a valid data URL.
*/
export function extractBase64FromDataUrl(dataUrl: string): string {
if (!dataUrl.startsWith("data:")) {
return "";
}
const comma = dataUrl.indexOf(",");
return comma >= 0 ? dataUrl.slice(comma + 1) : "";
}
/**
* Parses an image part (either image_url or file type) and returns
* dataUrl, base64Only, and mediaType ready for rendering.
*
* Handles error cases gracefully by returning empty base64Only string
* when parsing fails, allowing the renderer to skip invalid images.
*/
export function parseImagePartToDataUrl(part: any): {
dataUrl: string;
base64Only: string;
mediaType: string;
} {
try {
// Handle image_url parts
if (part.type === "image_url" && part.image_url?.url) {
const url = part.image_url.url;
const mediaType = "image/png"; // Default for image_url parts
if (url.startsWith("data:")) {
// Extract media type from data URL if present
const match = url.match(/data:([^;]+)/);
const extractedMediaType = match?.[1] || mediaType;
return {
dataUrl: url,
base64Only: extractBase64FromDataUrl(url),
mediaType: extractedMediaType,
};
}
return {
dataUrl: url,
base64Only: "",
mediaType,
};
}
// Handle file parts (AI SDK format)
if (part.type === "file") {
const { dataUrl, mediaType } = parseImageFile(part);
return {
dataUrl,
base64Only: extractBase64FromDataUrl(dataUrl),
mediaType,
};
}
return {
dataUrl: "",
base64Only: "",
mediaType: "image/png",
};
} catch {
return {
dataUrl: "",
base64Only: "",
mediaType: "image/png",
};
}
}Image Configuration
You can customize the generated image using the optional image_config parameter (for chat completions) or size/quality/style parameters (for the images API). The supported parameters vary by provider.
Google Models
Available Google models:
| Model | Description |
|---|---|
gemini-3-pro-image | Gemini 3 Pro with native image generation. Supports aspect ratios and 1K–4K sizes. |
gemini-3.1-flash-image | Gemini 3.1 Flash with native image generation. Supports 0.5K–4K sizes (default 1K). |
gemini-nano-banana-2.1 | Nano Banana 2.1, the Flash-tier successor to Nano Banana 2. Supports 1K–4K sizes (default 1K). |
gemini-2.5-flash-image | Gemini 2.5 Flash Image (Nano Banana). Supports aspect ratios; always 1K, image_size ignored. |
gemini-3-pro-image
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-pro-image",
"messages": [
{
"role": "user",
"content": "Generate an image of a mountain landscape at sunset"
}
],
"image_config": {
"aspect_ratio": "16:9",
"image_size": "4K"
}
}'| Parameter | Type | Description |
|---|---|---|
aspect_ratio | string | The aspect ratio of the generated image. Options: "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9" |
image_size | string | The resolution of the generated image. Options: "1K" (1024x1024), "2K" (2048x2048), "4K" (4096x4096) |
gemini-3.1-flash-image
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"messages": [
{
"role": "user",
"content": "Generate an image of a mountain landscape at sunset"
}
],
"image_config": {
"image_size": "1K"
}
}'| Parameter | Type | Description |
|---|---|---|
aspect_ratio | string | The aspect ratio of the generated image. Options: "1:1", "1:4", "1:8", "2:3", "3:2", "3:4", "4:1", "4:3", "4:5", "5:4", "8:1", "9:16", "16:9", "21:9" |
image_size | string | The resolution of the generated image. Options: "0.5K" (512x512), "1K" (1024x1024, default), "2K" (2048x2048), "4K" (4096x4096) |
gemini-3.1-flash-image uniquely supports "0.5K" resolution, which is not
available on other Google image models.
Meta Models
Muse Image uses Meta's Responses API for generation and editing. It reasons before rendering and can use reference images across refinement turns.
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "meta/muse-image-1.0",
"messages": [
{
"role": "user",
"content": "Create a product photo on a warm studio background"
}
],
"image_config": {
"image_size": "1024x1536"
}
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | One of "1024x1024", "1024x1536", or "1536x1024". Defaults to square. |
Muse Image does not expose a quality setting. Use image_size to choose square,
portrait, or landscape output.
fal Models
fal serves fast text-to-image models. They do not accept input images.
| Model | Description |
|---|---|
fal-ai/flux-2-klein-4b | FLUX.2 Klein 4B, Black Forest Labs' fastest. |
fal-ai/flux-3-klein | FLUX 3 Klein with built-in prompt expansion. |
fal-ai/z-image-turbo | Z-Image Turbo, photorealistic with text. |
fal-ai/recraft-v4.1-flash | Recraft V4.1 Flash for photo and illustration |
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "fal-ai/flux-2-klein-4b",
"messages": [{ "role": "user", "content": "A lighthouse at dusk" }],
"image_config": { "image_size": "1536x1024", "n": 2 }
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | One of "1024x1024" (default), "1536x1024", "1024x1536", "1344x768", "768x1344", or "2048x2048". Price varies by size. |
n | integer | Number of images. Not supported by Recraft. |
seed | integer | Random seed. Not supported by Recraft. |
output_format | string | png, jpeg, or webp. Not supported by Recraft. |
Images flagged by fal's safety checker are removed; if none remain, the response
returns finish_reason: "content_filter".
Alibaba Models
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "alibaba/qwen-image-3.0",
"messages": [
{
"role": "user",
"content": "Generate an image of a mountain landscape at sunset"
}
],
"image_config": {
"image_size": "1024x1536",
"n": 1,
"seed": 42
}
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | Image dimensions in WIDTHxHEIGHT format. Examples: "1024x1024", "1024x1536", "1536x1024" |
n | integer | Number of images to generate (1-4) |
seed | integer | Random seed for reproducible generation |
Available Alibaba models (see the models page for current pricing):
| Model | Description |
|---|---|
alibaba/qwen-image-2.1-pro | Generation and editing from up to 10 reference images, flat price per output image |
alibaba/qwen-image-2.1-turbo | Fast, low-cost generation and editing from up to 10 reference images, flat price per output image |
alibaba/qwen-image-3.0 | Third-generation image generation and editing |
alibaba/qwen-image-3.0-pro | Highest quality third-generation generation and editing. Priced per output size tier |
alibaba/wan-2-7-image | Fast Wan 2.7 generation and editing from up to 9 input images, up to 2K, flat price per image |
alibaba/wan-2-7-image-pro | Flagship Wan 2.7 generation up to 4K (text-to-image only) and editing up to 2K, flat price per image |
Alibaba models use explicit pixel dimensions (e.g., "1024x1536") instead of
aspect ratios. For portrait orientation use "1024x1536", for landscape use
"1536x1024". Wan 2.7 models also accept the tiers "1K" and "2K"
(default), plus "4K" on wan-2-7-image-pro for text-to-image; tiers without
an input image produce square output.
Z.AI Models
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "zai/cogview-4",
"messages": [
{
"role": "user",
"content": "Generate an image of a futuristic city skyline"
}
],
"image_config": {
"image_size": "1024x1024"
}
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | Image dimensions in WIDTHxHEIGHT format. Examples: "1024x1024", "2048x1024", "1024x2048" |
n | integer | Number of images to generate |
Available Z.AI models (see the models page for current pricing):
| Model | Description |
|---|---|
zai/cogview-4 | CogView-4 with bilingual support and excellent text rendering |
zai/glm-image | GLM-Image with hybrid auto-regressive architecture, excellent for text-rendering and knowledge-intensive generation |
CogView-4 supports both Chinese and English prompts and excels at generating images with embedded text.
OpenAI Models
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-image-2",
"messages": [
{
"role": "user",
"content": "Generate a photo-real cinematic landscape at golden hour"
}
],
"image_config": {
"image_size": "3072x2160",
"image_quality": "low"
}
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | Image dimensions in WIDTHxHEIGHT format, or "auto" to let the model choose. |
image_quality | string | "low", "medium", "high", or "auto"; GPT Image 2.5 and 2.6 also support "xhigh" and "max". Defaults to "auto" when omitted. |
moderation | string | "auto" or "low" — see Moderation. Defaults to "auto" when omitted. |
complexity | string | low, medium, or high — see Complexity. |
frame_count | integer | GIF frames, 2–16; requires output_format: "gif". |
frame_duration_ms | integer | GIF frame duration in milliseconds, 20–2000. |
background | string | "transparent", "opaque", or "auto" — see Transparency. |
output_format | string | "png", "jpeg", or "webp"; GPT Image 2.6 also supports "svg" and "gif" — see SVG output. |
output_compression | number | 0–100, for jpeg and webp output. |
OpenAI image models do not accept aspect_ratio. Always specify
image_size as WIDTHxHEIGHT (e.g. "1024x1024", "3072x2160"). OpenAI
requires both width and height to be divisible by 16, the longest edge to be ≤
3840, and the total pixel count to fit within the model's pixel budget;
requests outside these bounds are rejected with HTTP 400.
Available OpenAI image models:
| Model | Description |
|---|---|
openai/gpt-image-2 | OpenAI's next-generation image model with improved quality and prompt adherence, supporting text and vision. |
openai/gpt-image-2.5-sunburst | Image generation and precise editing with text and image inputs; adds xhigh and max quality. |
openai/gpt-image-2.5-flare | Fast everyday image generation and editing with text and image inputs; adds xhigh and max quality. |
openai/gpt-image-2.6-sunburst | Detailed image generation and editing; adds xhigh and max quality and SVG output. |
openai/gpt-image-2.6-flare | Fast image generation and editing for iteration; adds xhigh and max quality and SVG output. |
OpenAI shuts off gpt-image-2 on February 10, 2027; openai/gpt-image-2
requests fail from that date. Migrate to GPT Image 2.6 Sunburst or Flare.
GPT Image 2.5 supports 1024x1024, 1536x1024, 1024x1536, auto, and
custom sizes within the limits above. Its aspect ratio must stay between 1:3
and 3:1, with 655,360–8,294,400 total pixels. Resolutions above 2560x1440
are experimental.
Both variants use the same per-token rates as GPT Image 2. Actual image token usage varies by model, size, quality, and input; billing uses the provider's reported usage. See the models page for current pricing.
GPT Image 2.6 uses the same per-token rates; OpenAI serves it directly only.
GPT Image 2 and both GPT Image 2.5 variants are also served through Azure at
the same rates — swap the openai/ prefix for azure/ to pin that route, or
send the bare model id and let the gateway pick.
ByteDance Models
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "bytedance/seedream-4-5",
"messages": [
{
"role": "user",
"content": "Generate an image of a futuristic cyberpunk city at night"
}
],
"image_config": {
"image_size": "2048x2048"
}
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | Image dimensions in WIDTHxHEIGHT format. Examples: "1024x1024", "2048x2048", "4096x4096" |
Available ByteDance models (see the models page for current pricing):
| Model | Description |
|---|---|
bytedance/seedream-4-0 | High-quality text-to-image generation with 2K default output |
bytedance/seedream-4-5 | Enhanced quality and consistency with improved prompt adherence |
bytedance/seedream-5-0-pro | Precise generation and reference-image editing at 1K or 2K |
bytedance/seedream-5-0-flash | Fast, low-cost generation and reference-image editing up to 2K |
Seedream models support up to 2-10 reference images for multi-image fusion and generation. The default output resolution is 2048×2048 (2K). Seedream 4.0 and 4.5 support up to 4096×4096 (4K); Seedream 5.0 Pro and Flash top out at 2K.
Tencent Models
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tencent/hy-image-v3.5-preview",
"messages": [
{
"role": "user",
"content": "A neon sign reading \"Open Late\" above a rainy storefront"
}
],
"image_config": {
"image_size": "4096x2304"
}
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | Exact output size in WIDTHxHEIGHT format. Each side 256–8192. Omit it to let the model pick the size from the prompt (~1.5K) |
seed | integer | Seed for reproducible output |
| Model | Description |
|---|---|
tencent/hy-image-v3.5-preview | Generation and editing from up to 20 reference images, up to 4K, strong text in images |
Each request returns one image. Tencent bills a fixed token count per image (more at 4K); billing uses the token count Tencent reports. See the models page for current pricing.
MiniMax Models
curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "minimax/minimax-h3-image",
"messages": [
{
"role": "user",
"content": "A red apple on a weathered wooden table, soft window light"
}
],
"image_config": {
"image_size": "2K",
"aspect_ratio": "16:9"
}
}'| Parameter | Type | Description |
|---|---|---|
image_size | string | 1K, 2K or 4K area tier (default 4K), or an exact WIDTHxHEIGHT between 655,360 and 20,000,000 pixels |
aspect_ratio | string | auto (default, picked by prompt enhancement) or X:Y between 1:3 and 3:1. Ignored when image_size is WIDTHxHEIGHT |
n | number | 1–10 images |
| Model | Description |
|---|---|
minimax/minimax-h3-image | Generation and editing from up to 16 reference images, up to 4K, with prompt enhancement |
MiniMax always enhances the prompt, and bills it as input tokens. Images that
fail MiniMax's content safety check are dropped; the request returns
content_filter when none remain. Billing uses the text, reference-image and
output-image token counts MiniMax reports. See the
models page for
current pricing.
Complexity
GPT Image 2.6 Sunburst and Flare accept complexity: "low" | "medium" | "high" on /v1/images/generations and /v1/images/edits (JSON or multipart). For chat completions, use image_config.complexity. If omitted, OpenAI defaults both models to high; the gateway does not override this default.
Complexity controls planning before rendering, independently of quality. Lower values can suit focused edits such as changing an outfit or background; higher values can help with dense text and complex layouts. See OpenAI's image complexity guide.
Moderation
GPT Image models expose a moderation parameter that controls how strict the
provider's content filtering is:
auto(default) — standard filtering, which limits certain categories of potentially age-inappropriate content.low— less restrictive filtering. OpenAI's content policy still applies.
Send it as a top-level parameter on /v1/images/generations and
/v1/images/edits, or inside image_config on /v1/chat/completions:
curl -X POST "https://api.llmgateway.io/v1/images/generations" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-image-2.5-flare",
"prompt": "A cute cat wearing a tiny top hat",
"moderation": "low"
}'curl -X POST "https://api.llmgateway.io/v1/chat/completions" \
-H "Authorization: Bearer $LLM_GATEWAY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-image-2.5-flare",
"messages": [{ "role": "user", "content": "A cute cat wearing a tiny top hat" }],
"image_config": { "moderation": "low" }
}'Models without a moderation control ignore the parameter.
Usage Notes
Image generation models typically have higher token costs compared to text-only models due to the computational requirements of image synthesis.
Generated images are returned as base64-encoded data URLs, which can be large. Consider the payload size when integrating image generation into your applications.
How is this guide?
Last updated on