diff --git a/.changeset/many-phones-call.md b/.changeset/many-phones-call.md new file mode 100644 index 00000000..cf0b3d3b --- /dev/null +++ b/.changeset/many-phones-call.md @@ -0,0 +1,5 @@ +--- +"syncia": patch +--- + +API key validation with /modals endpoint diff --git a/src/lib/validApiKey.ts b/src/lib/validApiKey.ts index 7269b533..ed0033fb 100644 --- a/src/lib/validApiKey.ts +++ b/src/lib/validApiKey.ts @@ -1,19 +1,18 @@ -import { HumanMessage } from '@langchain/core/messages' -import { ChatOpenAI } from '@langchain/openai' - export const validateApiKey = async ( openAIApiKey: string, baseURL: string, ): Promise => { - const model = new ChatOpenAI({ - openAIApiKey: openAIApiKey, - configuration: { - baseURL: baseURL || 'https://api.openai.com/v1', - }, - }) try { - await model.invoke([new HumanMessage('Say Ok')]) - return true + const response = await fetch( + `${baseURL || 'https://api.openai.com/v1'}/models`, + { + headers: { + Authorization: `Bearer ${openAIApiKey}`, + 'Content-Type': 'application/json', + }, + }, + ) + return response.status === 200 } catch (e) { console.error(e) return false