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:
parent
d10ee67924
commit
7968dd1069
1 changed files with 12 additions and 0 deletions
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue