diff --git a/web-app/src/lib/completion.ts b/web-app/src/lib/completion.ts index 68cc7183c..3834cb68f 100644 --- a/web-app/src/lib/completion.ts +++ b/web-app/src/lib/completion.ts @@ -187,9 +187,10 @@ export const sendCompletion = async ( if (!secretKey) { throw new Error('Encryption key unavailable: cannot decrypt API key.') } - const apiKey = provider.api_key - ? decryptApiKey(provider.api_key, secretKey) - : (secretKey ?? '') + if (!provider.api_key) { + throw new Error('API key is missing for the selected provider.'); + } + const apiKey = decryptApiKey(provider.api_key, secretKey); const tokenJS = new TokenJS({ apiKey,