Generate an image
Changed onGenerates an image from a text prompt via the image generation router
Request
- Base URLhttps://openrouter.ai/api/v1
- AuthHTTP bearer
Request body
Image generation request input
Normalized aspect ratio of the generated image. Providers clamp to their supported subset.
Background treatment. transparent requires an output_format that supports alpha (png or webp).
Number of animation frames (2-64) when output_format is gif. Only honored by models that produce animations; each accepts its own range and rejects values outside it. Ignored otherwise.
Display time of each animation frame in milliseconds (20-2000) when output_format is gif. Ignored by models that do not produce animations.
Reference images to guide image-to-image generation, as base64 data URLs or HTTP(S) URLs.
A transparent PNG overlay (arrows, circles, annotations) with the same dimensions as the first reference image, as a base64 data URL or HTTP(S) URL, guiding where an edit applies. Image-to-image requests only; honored by models with markup-guided editing (OpenAI gpt-image-2.6) and ignored otherwise.
The image generation model to use
Upper bound on the number of images to generate (1-10). Providers may return fewer images, and providers that only support single-image generation reject n > 1.
Compression level (0-100) for jpeg/webp output. Ignored by providers without a compression knob; providers that honor it may reject it with other output formats (e.g. OpenAI requires output_format "jpeg" or "webp").
Encoding of the returned image bytes. Most models produce raster formats (png, jpeg, webp). SVG is supported by vectorization models (e.g. Quiver) — the SVG markup is UTF-8 base64-encoded in b64_json. GIF produces an animation on models that support it (OpenAI gpt-image-2.6; see frame_count).
Text description of the desired image
Provider routing preferences and provider-specific passthrough configuration.
Rendering quality. Providers without a quality knob ignore this.
Normalized resolution tier of the generated image. Concrete pixel dimensions are derived per-provider.
b64_json (default) returns the image bytes inline. url stores each output in OpenRouter storage and returns a signed download URL in place of the bytes. The URL is a bearer link: anyone holding it can download the image until it expires, up to 24 hours after the image was stored (use expires_at); the stored copy is deleted by the storage lifecycle within the following day. The response falls back to b64_json when a URL cannot be issued: streaming responses, zero-data-retention requests (account settings, guardrails or provider.zdr) or endpoints, or storage being unavailable.
If specified, the generation will sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed for all providers.
A unique identifier for grouping related requests (e.g., a conversation or agent workflow). Used for observability grouping in Broadcast and private logging; never sent to the provider. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters.
Optional. A convenience shorthand for output dimensions — pass a tier ("2K", "4K") or explicit pixels ("2048x2048"). A tier size is equivalent to setting resolution and combines with aspect_ratio. Explicit pixel sizes are provider-dependent: providers that accept them treat the value as authoritative and reject a mismatched resolution or aspect_ratio alongside it with a 400. xAI and Sourceful V2/V2.5 reject explicit pixel sizes (use resolution and aspect_ratio there); Sourceful V2.6 supports them within its dimension limits and does not allow combining them with resolution or aspect_ratio.
If true, partial images are streamed as SSE events as they become available. Only supported by providers with native streaming (currently OpenAI). Non-streaming providers ignore this flag and return a buffered response.
Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations.
A stable identifier for your end-users. Used to help detect and prevent abuse. Never sent to providers verbatim: for providers whose data policy requires user IDs, it is folded into a hashed, per-account upstream user identifier.
Example request
{
"model": "bytedance-seed/seedream-4.5",
"prompt": "a red panda astronaut floating in space, studio lighting",
"response_format": "url"
}Response
Image generation response
Image generation response
Unix timestamp (seconds) when the image was generated
Generated images
Unix timestamp (seconds) of the earliest expiry among the urls in data; treat every URL as expired after it. Present only when URLs were issued.
Token and cost usage for the image generation request, when available
Example response
{
"created": 1748372400,
"data": [
{
"media_type": "image/png",
"url": "https://storage.googleapis.com/openrouter-generated-media-us/v1/..."
}
],
"expires_at": 1748458800,
"usage": {
"completion_tokens": 4175,
"cost": 0.04,
"prompt_tokens": 0,
"total_tokens": 4175
}
}Changes
- info
added the new optional request property
provider/options/allOf[#/components/schemas/ProviderOptions]/celeris - info
added the new
Celerisenum value to the request propertyprovider/ignore/items/anyOf[#/components/schemas/ProviderName] - info
added the new
Celerisenum value to the request propertyprovider/only/items/anyOf[#/components/schemas/ProviderName]
1 more change in this revision
- info