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.

By default the SDK sends all requests to https://openrouter.ai/api/v1. This base URL can be overridden when you need to route traffic through a proxy in front of the OpenRouter API, or when running tests against a local mock server.

Default URL

The default base URL is declared as a constant on OpenRouterOptions:
public const string DEFAULT_BASE_URL = 'https://openrouter.ai/api/v1';
This value is used automatically unless you provide an alternative via an environment variable or the config array.

Override via environment variable

Set OPENROUTER_BASE_URL in your environment or .env file to replace the default for all requests:
OPENROUTER_BASE_URL=https://your-proxy.example.com/api/v1
The SDK reads this variable through Env::loadOptionalSetting() inside OpenRouterOptions::fromArray(), so no code changes are required.

Override via config array

You can also supply the base URL programmatically when calling OpenRouter::create():
use AiSdk\OpenRouter;

OpenRouter::create([
    'apiKey' => 'or-...',
    'baseUrl' => 'https://your-proxy.example.com/api/v1',
]);

Trailing slash handling

Trailing slashes are stripped automatically. Internally the SDK calls Url::withoutTrailingSlash() on whatever value you provide, so https://your-proxy.example.com/api/v1/ and https://your-proxy.example.com/api/v1 are treated identically.

Appended endpoints

The SDK appends a fixed path segment to the base URL depending on the operation being performed:
OperationPath appendedFull default URL
Text generation/chat/completionshttps://openrouter.ai/api/v1/chat/completions
Image generation/imageshttps://openrouter.ai/api/v1/images
Changing the base URL is only necessary when using an OpenRouter-compatible proxy or during local testing with a mock server. Leave it at the default for standard usage against the OpenRouter API.

Build docs developers (and LLMs) love