- SDK
- Stateless Image API
SDK
Stateless Image API
Text-to-image, image editing, and multi-image references.
Use operation="generate_image" with image_model_provider="openrouter", image_model_name, and optional image_config. No chat model is needed. Start with the client setup and response handling.
Choose an input pattern
content is required in every request. Arrows below describe the media inputs in addition to that prompt.
| Workflow | Inputs | Verification |
|---|---|---|
| Text → image | content only | Live-tested. |
| Image → image | input_image="photo.png" | Live-tested. |
| Multiple images → image | input_references=["subject.png", "style.png"] | Implemented; model/endpoint reference limits apply. Not separately live-tested. |
| Base image + references → image | input_image plus input_references | Implemented; their combined count must fit the endpoint’s limit. Not separately live-tested. |
| Audio/video → image | Not accepted by stateless image generation | Use image inputs only. |
Live-tested image examples used google/gemini-3.1-flash-image, with streaming and non-streaming in both production and dev environments. This is not certification of every model or setting.
Text to image
result = await client.send_message(
"A blue robot watering plants, watercolor style.",
operation="generate_image",
image_model_provider="openrouter",
image_model_name="google/gemini-3.1-flash-image",
image_config={"resolution": "1K", "aspect_ratio": "16:9"},
)
print(result.generated_media)
Image to image
Supply the edit input explicitly; the prompt only needs to describe the edit.
result = await client.send_message(
"Keep the composition, but change the blue ball to red.",
operation="generate_image",
image_model_provider="openrouter",
image_model_name="google/gemini-3.1-flash-image",
image_config={"resolution": "1K"},
input_image="photo.png",
)
Multiple image references
Choose a model/endpoint that accepts the total number of references. input_image and input_references are combined as image references by the generation backend; they are not separate masks or editing layers.
result = await client.send_message(
"Use the subject from the first reference in the visual style of the second.",
operation="generate_image",
image_model_provider="openrouter",
image_model_name="google/gemini-3.1-flash-image",
image_config={"resolution": "1K"},
input_references=["subject.png", "style.png"],
)
For an edit with extra guidance, replace the last line with:
input_image="photo.png",
input_references=["style.png"],
This supplies two references, not one. Describe the role of each in content. There is no dedicated mask/inpainting file field in this API.
JavaScript and HTTP uploads
The same fields work for every image recipe; change only content, the files, and supported config values.
const result = await client.sendMessage({
content: "Change the blue ball to red.",
operation: "generate_image",
image_model_provider: "openrouter",
image_model_name: "google/gemini-3.1-flash-image",
image_config: { resolution: "1K" },
input_image: "photo.png",
// For multiple references instead: input_references: ["subject.png", "style.png"],
});
For multiple references in HTTP, replace input_image with repeated fields:
-F 'input_references=@subject.png;type=image/png' \
-F 'input_references=@style.png;type=image/png'
Image configuration
Use only fields and values supported by the selected model and an eligible provider endpoint. These are available control names, not settings guaranteed for every model.
image_config field | Purpose |
|---|---|
resolution | Named output resolution, such as 1K when supported. |
aspect_ratio | Output ratio, such as 16:9 when supported. |
size | Model-supported explicit output size. |
quality | Model-specific quality setting. |
n | Number of generated images, within the endpoint’s range. |
seed | Integer seed, if supported; not a universal reproducibility guarantee. |
background | Background mode, if supported. |
output_format | Model-supported output format. |
output_compression | Compression setting, when supported; not accepted with output_format="png". |
provider | Routing object: only, order, ignore, sort, allow_fallbacks. Image endpoints may also expose options with an allowlist of provider-specific keys. |
Transparent backgrounds require a compatible format: png or webp if an output format is supplied. No single provider endpoint supporting the full config and reference count means rejection, even if the model’s combined catalog lists individual settings.
Find candidate models with GET /models/image/all?provider=openrouter. Image-input capability is necessary for editing but does not establish reference counts, every supported config combination, or provider-specific limits. The backend validates against the selected model’s generation capabilities.
Common mistakes
- Use
input_image/input_references, not conversationalfilesor document IDs. - Do not send
input_last_frameorinput_videofor image generation. - Do not assume image generation accepts audio/video just because a related chat model does.
- Keep the returned
generated_media; don’t extract URLs from assistant prose.
For streaming, timeouts, billing, and error handling, see Stateless Calls.