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.

The OpenRouter API supports optional custom HTTP headers that identify the calling application. The two most common are HTTP-Referer (your site URL) and X-OpenRouter-Title (your application name). When provided, these values appear in the Activity section of your OpenRouter dashboard, making it straightforward to trace usage back to a specific app or environment.

Adding custom headers

Pass a headers array to OpenRouter::create() alongside your API key:
use AiSdk\OpenRouter;

OpenRouter::create([
    'apiKey' => 'or-...',
    'headers' => [
        'HTTP-Referer' => 'https://example.com',
        'X-OpenRouter-Title' => 'Example App',
    ],
]);
These headers are merged with the Authorization header inside OpenRouterOptions::authHeaders() and sent on every request:
public function authHeaders(): array
{
    return array_merge(['Authorization' => 'Bearer '.$this->apiKey], $this->headers);
}
Because the merge places the Authorization header first, custom headers can never accidentally override authentication.

Supported headers

HeaderDescription
HTTP-RefererYour website or application URL. Shown in the OpenRouter activity dashboard.
X-OpenRouter-TitleYour application name. Shown in the OpenRouter activity dashboard.
Any valid HTTP header name can be passed in the headers array and will be forwarded on every request.

Test verification

In integration tests, the headers attached to the last outgoing request are accessible via the fake HTTP client used by the test suite. For example, asserting that HTTP-Referer was forwarded correctly looks like this:
expect($client->lastRequest->getHeaderLine('HTTP-Referer'))->toBe('https://example.com');
This pattern mirrors how the OpenRouter test suite verifies header propagation end-to-end.
Setting HTTP-Referer and X-OpenRouter-Title is optional but recommended for production applications. They improve observability in the OpenRouter dashboard and help OpenRouter’s support team assist you if usage questions arise.

Build docs developers (and LLMs) love