feat(openrouter): send HTTP-Referer and X-Title headers to identify app (#11857)

* feat(openrouter): send HTTP-Referer and X-Title headers to identify app

Adds `HTTP-Referer: https://www.continue.dev/` and `X-Title: Continue`
headers to all OpenRouter API requests, as recommended by the OpenRouter
docs. This lets OpenRouter attribute requests to Continue in their
dashboard and App Showcase.

Headers are injected via both `requestOptions.headers` (for SDK-based
requests) and `getHeaders()` (for direct fetch calls). User-configured
headers take precedence.

Closes #4049

* refactor: remove redundant getHeaders() override

The OPENROUTER_HEADERS are already injected via requestOptions.headers
in the constructor. Since fetchwithRequestOptions merges
requestOptions.headers into all requests (including direct fetch calls
like fimStream and rerank), the getHeaders() override was redundant.
This commit is contained in:
Dallin Romney 2026-03-25 16:57:33 -07:00 • committed by GitHub
parent d10ee67924
commit 7968dd1069
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,11 +8,23 @@ export interface OpenRouterConfig extends OpenAIConfig {
cachingStrategy?: import("./AnthropicCachingStrategies.js").CachingStrategyName;
}
const OPENROUTER_HEADERS: Record<string, string> = {
"HTTP-Referer": "https://www.continue.dev/",
"X-Title": "Continue",
};
export class OpenRouterApi extends OpenAIApi {
constructor(config: OpenRouterConfig) {
super({
...config,
apiBase: config.apiBase ?? "https://openrouter.ai/api/v1/",
requestOptions: {
...config.requestOptions,
headers: {
...OPENROUTER_HEADERS,
...config.requestOptions?.headers,
},
},
});
}