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.
OpenRouterOptions holds all configuration for a provider instance. It is the single source of truth for the API key, base URL, custom HTTP headers, and optional HTTP client override used by every model that the provider creates. Instances are constructed via the static fromArray() factory, which resolves values from the supplied array and falls back to environment variables where appropriate.
Namespace: AiSdk\OpenRouterFile:
src/OpenRouterOptions.php
Constants
'https://openrouter.ai/api/v1' — the base URL used when neither the baseUrl config key nor the OPENROUTER_BASE_URL environment variable is set.'openrouter' — the canonical provider identifier used in model metadata and error messages throughout the SDK.Constructor
fromArray() over direct construction so that environment-variable fallbacks are applied automatically.
fromArray()
OpenRouterOptions instance. Resolves each option from the supplied $config array, falling back to environment variables and built-in defaults.
Parameters
Your OpenRouter API key. When omitted, the value of the
OPENROUTER_API_KEY environment variable is used. An exception is thrown if neither is present.The base URL for all API requests. When omitted, the
OPENROUTER_BASE_URL environment variable is checked first; if that is also unset, DEFAULT_BASE_URL (https://openrouter.ai/api/v1) is used. Trailing slashes are stripped automatically.An associative array of additional HTTP headers sent with every request. Common uses include
HTTP-Referer (required by some OpenRouter policies) and X-OpenRouter-Title (displayed in the OpenRouter dashboard). These are merged with the Authorization header produced by authHeaders().An
AiSdk\Support\Sdk instance wrapping a PSR-18 HTTP client, PSR-17 request factory, and PSR-17 stream factory. When provided, it overrides the default HTTP transport. This option exists primarily for unit testing — supply a FakeHttpClient here instead of making real network calls.self — a fully configured OpenRouterOptions instance.
authHeaders()
Authorization: Bearer <apiKey> header with any entries from the headers array supplied at construction time. Model classes call this method when assembling each outbound HTTP request.
Returns: array<string, string> — an associative array of HTTP header names to values, always containing at minimum Authorization.
Full Configuration Example
Environment Variable Configuration
Testing with a Fake HTTP Client
The
sdk option is intended for testing only. In production, omit it and let the SDK use its default PSR-18 HTTP client.