diff --git a/src/main/apiServer/routes/knowledge/handlers.ts b/src/main/apiServer/routes/knowledge/handlers.ts index 6af64725e0..990fa5625f 100644 --- a/src/main/apiServer/routes/knowledge/handlers.ts +++ b/src/main/apiServer/routes/knowledge/handlers.ts @@ -142,8 +142,12 @@ async function getProviderConfig(providerId: string): Promise<{ apiKey: string; baseURL = baseURL.replace(/\/+$/, '') baseURL = baseURL.replace(/#$/, '') + // If multiple API keys are configured (comma-separated), use the first one. + // Matches the main-process convention in OpenClawService. + const apiKey = provider.apiKey ? provider.apiKey.split(',')[0].trim() : '' + return { - apiKey: provider.apiKey || '', + apiKey, baseURL } } diff --git a/src/main/apiServer/services/chat-completion.ts b/src/main/apiServer/services/chat-completion.ts index 644bd2778f..9ad08b3f00 100644 --- a/src/main/apiServer/services/chat-completion.ts +++ b/src/main/apiServer/services/chat-completion.ts @@ -67,9 +67,13 @@ export class ChatCompletionService { const modelId = modelValidation.modelId! + // If multiple API keys are configured (comma-separated), use the first one. + // Matches the main-process convention in OpenClawService. + const apiKey = provider.apiKey ? provider.apiKey.split(',')[0].trim() : '' + const client = new OpenAI({ baseURL: provider.apiHost, - apiKey: provider.apiKey + apiKey }) return {