1. SDK
  2. Stateless Image API

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.

WorkflowInputsVerification
Text → imagecontent onlyLive-tested.
Image → imageinput_image="photo.png"Live-tested.
Multiple images → imageinput_references=["subject.png", "style.png"]Implemented; model/endpoint reference limits apply. Not separately live-tested.
Base image + references → imageinput_image plus input_referencesImplemented; their combined count must fit the endpoint’s limit. Not separately live-tested.
Audio/video → imageNot accepted by stateless image generationUse 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 fieldPurpose
resolutionNamed output resolution, such as 1K when supported.
aspect_ratioOutput ratio, such as 16:9 when supported.
sizeModel-supported explicit output size.
qualityModel-specific quality setting.
nNumber of generated images, within the endpoint’s range.
seedInteger seed, if supported; not a universal reproducibility guarantee.
backgroundBackground mode, if supported.
output_formatModel-supported output format.
output_compressionCompression setting, when supported; not accepted with output_format="png".
providerRouting 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 conversational files or document IDs.
  • Do not send input_last_frame or input_video for 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.