I’m experiencing ongoing timeout issues when trying to use OpenAI’s API with the Node.js library version 4.20.1. Even for very simple queries, like basic math questions, I keep running into timeouts.
Here’s the implementation I’m currently working with:
const { OpenAI } = require('openai');
async function handleChatRequest(request, response) {
try {
const client = new OpenAI({
apiKey: process.env.OPENAI_SECRET_KEY,
});
const userInput = request.body.message;
const completion = await client.chat.completions.create({
model: "gpt-4",
messages: [{ role: 'user', content: userInput }],
});
response.json(completion.choices);
} catch (err) {
console.log('OpenAI request failed:', err);
response.status(500).json({ error: 'Request failed' });
}
}
exports.handleChatRequest = handleChatRequest;
What am I missing? I’m attempting to create a simple ChatGPT clone using the official OpenAI API, but these timeout errors are really hindering progress. Any suggestions on what might be going wrong?