diff --git a/src/modules/llms/llm.client.ts b/src/modules/llms/llm.client.ts index 9c8117403..feb0677e9 100644 --- a/src/modules/llms/llm.client.ts +++ b/src/modules/llms/llm.client.ts @@ -38,7 +38,7 @@ export async function callChatGenerateWithFunctions(llmId: DLLMId, messages: VCh } -function getLLMAndVendorOrThrow(llmId: string) { +function getLLMAndVendorOrThrow(llmId: DLLMId) { const llm = useModelsStore.getState().llms.find(llm => llm.id === llmId); const vendor = findVendorById(llm?._source.vId); if (!llm || !vendor) throw new Error(`callChat: Vendor not found for LLM ${llmId}`); diff --git a/src/modules/llms/openai/openai.router.ts b/src/modules/llms/openai/openai.router.ts index d88ff57c3..3a631c735 100644 --- a/src/modules/llms/openai/openai.router.ts +++ b/src/modules/llms/openai/openai.router.ts @@ -203,7 +203,6 @@ async function openaiPOST(access: AccessSchema, body: TBody, apiPat export function openAIAccess(access: AccessSchema, apiPath: string): { headers: HeadersInit, url: string } { // API key const oaiKey = access.oaiKey || process.env.OPENAI_API_KEY || ''; - if (!oaiKey) throw new Error('Missing OpenAI API Key. Add it on the UI (Models Setup) or server side (your deployment).'); // Organization ID const oaiOrg = access.oaiOrg || process.env.OPENAI_API_ORG_ID || ''; @@ -218,9 +217,13 @@ export function openAIAccess(access: AccessSchema, apiPath: string): { headers: // Helicone key const heliKey = access.heliKey || process.env.HELICONE_API_KEY || ''; + // warn if no key - only for OpenAI hosts + if (!oaiKey && oaiHost.indexOf('api.openai.com') !== -1) + throw new Error('Missing OpenAI API Key. Add it on the UI (Models Setup) or server side (your deployment).'); + return { headers: { - Authorization: `Bearer ${oaiKey}`, + ...(oaiKey && { Authorization: `Bearer ${oaiKey}` }), 'Content-Type': 'application/json', ...(oaiOrg && { 'OpenAI-Organization': oaiOrg }), ...(heliKey && { 'Helicone-Auth': `Bearer ${heliKey}` }),