Skip to main content

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.

OpenRouter exposes provider-level controls such as preferred provider routing and reasoning effort that have no equivalent in the standard AI SDK builder interface. These are passed through the providerOptions('openrouter', [...]) builder method and merged directly into the outgoing request body, giving you access to any OpenRouter-specific top-level field without losing the type-safe builder API.

Basic example

use AiSdk\Generate;
use AiSdk\OpenRouter;

$result = Generate::text('Hello')
    ->model(OpenRouter::model('anthropic/claude-sonnet-4'))
    ->providerOptions('openrouter', [
        'raw' => [
            'provider' => ['order' => ['Anthropic']],
            'reasoning' => ['effort' => 'medium'],
        ],
    ])
    ->run();

echo $result->text;

The raw key

Everything placed inside the raw array is merged directly into the top-level JSON request body that is sent to OpenRouter. This means you can set any OpenRouter-specific field — provider, reasoning, transforms, and so on — without the SDK needing explicit support for each one. Fields inside raw take effect for both text and image generation requests.
->providerOptions('openrouter', [
    'raw' => [
        // Any OpenRouter top-level field goes here
        'transforms' => ['middle-out'],
    ],
])

Common use cases

Provider routing

Control which upstream providers OpenRouter is allowed to route your request to, and in what priority order:
->providerOptions('openrouter', [
    'raw' => [
        'provider' => ['order' => ['Anthropic', 'AWS Bedrock']],
    ],
])
OpenRouter will try each provider in the list in order and fall back to the next if one is unavailable.

Reasoning effort

For models that support extended thinking, set the reasoning effort level to balance quality against cost and latency:
->providerOptions('openrouter', [
    'raw' => [
        'reasoning' => ['effort' => 'medium'],
    ],
])
Accepted values are 'low', 'medium', and 'high'.

Image style options (Recraft)

Provider-level style options for image models are also passed through raw. The following example sets the Recraft style to vector:
use AiSdk\Generate;
use AiSdk\OpenRouter;

$result = Generate::image()
    ->model(OpenRouter::image('recraft/recraft-v4.1-vector'))
    ->prompt('A vector bird')
    ->count(1)
    ->aspectRatio('1:1')
    ->providerOptions('openrouter', [
        'raw' => [
            'provider' => [
                'options' => [
                    'recraft' => ['style' => 'vector'],
                ],
            ],
        ],
    ])
    ->run();
The provider.options.recraft.style field is forwarded as a top-level provider key in the request body, exactly as OpenRouter expects.
For the complete list of supported raw options — including all routing strategies, model transforms, and extended thinking parameters — see the OpenRouter API documentation.

Build docs developers (and LLMs) love