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.
OpenRouterProvider extends BaseProvider and is responsible for constructing model instances bound to a specific configuration. It is normally obtained via OpenRouter::create() or OpenRouter::default(), but can be instantiated directly when you need multiple named provider configurations — for example, routing different requests through different API keys or base URLs within the same process.
Namespace: AiSdk\OpenRouterFile:
src/OpenRouterProvider.php
Constructor
OpenRouterOptions instance and exposes it as a public readonly property.
The options object that carries the API key, base URL, extra headers, and optional HTTP client override for all models created by this provider. See
OpenRouterOptions for details.Methods
name()
string — always 'openrouter' (the value of OpenRouterOptions::PROVIDER_NAME).
textModel()
OpenRouterTextModel configured with this provider’s options and model registry.
The OpenRouter model identifier, e.g.
'openai/gpt-4o' or 'anthropic/claude-sonnet-4'.TextModelInterface — an OpenRouterTextModel instance ready to call generate() or stream().
imageModel()
OpenRouterImageModel configured with this provider’s options and model registry.
The OpenRouter model identifier for an image-capable model, e.g.
'recraft/recraft-v4.1-vector'.ImageModelInterface — an OpenRouterImageModel instance ready to call generate().
Direct Instantiation Example
UsingOpenRouterProvider directly is useful when you want to maintain multiple independent provider configurations — for example, one per environment or tenant.
Multiple Configurations
When you only need a single global provider, prefer the
OpenRouter facade, which manages the singleton lifecycle for you.