I’m integrating OpenAI’s GPT API using Node.js. My app runs fine for a while, but then randomly throws:
Error: 429 - You exceeded your current quota, please check your plan and billing details.
Even with very low traffic (1–2 requests/min).
Here’s my sample code:
import OpenAI from "openai";
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
async function ask(question) {
const res = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: question }]
});
console.log(res.choices[0].message.content);
}
ask("Hello, world!");
Questions:
What causes random 429 errors even under low usage?
Should I add retry logic or a delay between requests?
Is there a way to check my actual request usage via API?