fix: normalize API URL to prevent duplicate /chat/completions path
Users entering the full endpoint URL (e.g. https://openrouter.ai/api/v1/chat/completions) caused a 404 because the code appended /chat/completions again. Now strips any trailing /chat/completions before re-appending, and adds a hint in the UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -37,7 +37,12 @@ export async function callOpenAICompatible(params: AICallerParams): Promise<AICa
|
||||
const https = await import('https');
|
||||
|
||||
const aiResult = await new Promise<{ status: number; body: string }>((resolve, reject) => {
|
||||
const url = new URL(`${apiUrl}/chat/completions`);
|
||||
// Normalize: strip trailing slash and /chat/completions if user included it
|
||||
let baseUrl = apiUrl.replace(/\/+$/, '');
|
||||
if (baseUrl.endsWith('/chat/completions')) {
|
||||
baseUrl = baseUrl.slice(0, -'/chat/completions'.length);
|
||||
}
|
||||
const url = new URL(`${baseUrl}/chat/completions`);
|
||||
|
||||
const options = {
|
||||
hostname: url.hostname,
|
||||
|
||||
Reference in New Issue
Block a user