const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
})
export const checkConnection = action({
args: {},
handler: async () => {
try {
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// Make a simple API call to list models
const response = await openai.models.list();
// If we get here without throwing an error, the connection is working
return { success: true, message: "Connection to OpenAI API is working" };
} catch (error) {
// If there's an error, the connection failed
return {
success: false,
message: "Failed to connect to OpenAI API",
error: error instanceof Error ? error.message : String(error)
};
}
},
});
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
})
export const checkConnection = action({
args: {},
handler: async () => {
try {
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// Make a simple API call to list models
const response = await openai.models.list();
// If we get here without throwing an error, the connection is working
return { success: true, message: "Connection to OpenAI API is working" };
} catch (error) {
// If there's an error, the connection failed
return {
success: false,
message: "Failed to connect to OpenAI API",
error: error instanceof Error ? error.message : String(error)
};
}
},
});