fix: route OpenRouter profiles through v1 API

This commit is contained in:
Tam Nhu Tran
2026-05-05 11:44:58 -04:00
parent fcfd2d279e
commit dc8bbd85e7
5 changed files with 49 additions and 3 deletions
+10
View File
@@ -9,6 +9,11 @@ function ensureSupportedProtocol(parsed: URL): void {
}
}
function isOpenRouterHost(hostname: string): boolean {
const normalized = hostname.toLowerCase();
return normalized === 'openrouter.ai' || normalized.endsWith('.openrouter.ai');
}
function buildResolvedUrl(baseUrl: string, suffix: string): string {
const parsed = new URL(baseUrl);
ensureSupportedProtocol(parsed);
@@ -18,6 +23,11 @@ function buildResolvedUrl(baseUrl: string, suffix: string): string {
return parsed.toString();
}
if (isOpenRouterHost(parsed.hostname) && pathname.endsWith('/api')) {
parsed.pathname = `${pathname}/v1${suffix}`;
return parsed.toString();
}
if (pathname.endsWith('/v1') || pathname.endsWith('/api')) {
parsed.pathname = `${pathname}${suffix.startsWith('/') ? suffix : `/${suffix}`}`;
return parsed.toString();