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 sends generation requests to the /images endpoint and parses the base64-encoded image data returned by the API. It uses the shared ImageRequestBuilder and ImageResponseParser from the OpenAI-compatible adapter, with a few OpenRouter-specific adjustments handled automatically.
Basic usage
Pass an image model identifier toOpenRouter::image() and chain it with the Generate::image() builder. Call ->run() to execute the request and receive an ImageResponse.
Saving the output
Callsave() on the output object with a local file path to write the image to disk:
Response fields
Generate::image()->run() returns an ImageResponse. The output is available under $result->output:
| Field | Type | Description |
|---|---|---|
$result->output->base64 | string | Raw base64-encoded image data returned by the API. |
$result->output->mimeType | string | MIME type of the image (e.g. image/png, image/svg+xml). |
$result->usage->totalTokens | int | Total tokens consumed by the request. |
Supported parameters
TheGenerate::image() builder supports the following methods when targeting OpenRouter:
| Method | Description |
|---|---|
prompt(string) | The text description of the image to generate. |
size(string) | Image dimensions, e.g. '1024x1024'. |
count(int) | Number of images to generate (n in the request body). |
aspectRatio(string) | Aspect ratio sent as the aspect_ratio parameter (e.g. '1:1', '16:9'). |
providerOptions(string, array) | Arbitrary provider-level options merged into the request body. |
OpenRouter does not accept a
response_format field in image requests. The SDK omits it automatically — you should never pass response_format manually when using this provider. Aspect ratio is sent as the aspect_ratio parameter (not aspectRatio) to match the OpenRouter API contract.Recraft vector example
The test suite confirms the full request flow for Recraft models. Theaspect_ratio parameter and provider-level style options are both forwarded correctly:
aspect_ratio as a top-level request parameter and merges the provider block from raw directly into the request body. The response_format key is never included.