Documentation Index
Fetch the complete documentation index at: https://mintlify.com/phpaisdk/openrouter/llms.txt
Use this file to discover all available pages before exploring further.
OpenRouterImageModel implements ImageModelInterface and handles image generation requests routed through OpenRouter. It serialises requests with ImageRequestBuilder from aisdk/openai-compatible, applying OpenRouter-specific builder options: aspect ratio is sent under the aspect_ratio key, size is not inferred from the aspect ratio, and the response_format field is omitted from the request body entirely. Responses are parsed by ImageResponseParser, which extracts the base64-encoded image, MIME type, and token usage from the API payload.
Namespace: AiSdk\OpenRouter\ModelsFile:
src/Models/OpenRouterImageModel.php
Constructor
The OpenRouter model identifier for an image-capable model, e.g.
'recraft/recraft-v4.1-vector'.The provider configuration, including API key, base URL, and extra headers. See
OpenRouterOptions.An optional model registry for runtime capability overrides. When
null, capability lookups use the bundled resources/models.json catalog.OpenRouterImageModel instances are not normally created directly. Use OpenRouter::image() or OpenRouterProvider::imageModel() instead.Methods
provider()
string — always 'openrouter'.
modelId()
string — the model ID, e.g. 'recraft/recraft-v4.1-vector'.
capabilities()
- The injected
ModelRegistry, if one was provided. - The bundled
resources/models.jsoncatalog.
array<int, Capability> — an array of Capability enum cases supported by the model.
capability()
- Any capability override configured directly on the model instance.
- The injected
ModelRegistry. - The bundled
resources/models.jsoncatalog.
The
Capability enum case to check, e.g. Capability::ImageGeneration.CapabilitySupport — the support level for the requested capability.
generate()
-
ImageRequestBuilder::build()serialises$requestinto a JSON body using the following OpenRouter-specific options:Option Value Effect aspectRatioParameter'aspect_ratio'Aspect ratio is serialised under the aspect_ratiokey instead ofsize.inferSizeFromAspectRatiofalseThe builder does not attempt to derive a sizevalue from the aspect ratio.includeResponseFormatfalseThe response_formatfield is not included in the request body. -
The body is POSTed to
Url::joinPath($options->baseUrl, '/images')with the headers from$options->authHeaders(). -
ImageResponseParser::parse()maps the JSON payload to anImageResponse.
The image generation request, including the prompt, count, aspect ratio, and any provider-specific options.
ImageResponse — contains:
The base64-encoded image data.
The MIME type of the generated image, e.g.
'image/svg+xml' or 'image/png'.The total number of tokens consumed by the request (prompt + completion combined).
Endpoint
All requests are sent to:Usage Example
Passing Provider-specific Options
OpenRouter supports forwarding raw provider options (for example, Recraft style settings) viaproviderOptions():
For a broader introduction to image generation, see the Image Generation usage guide.