The error message you're seeing indicates that you've exceeded the rate limit for your account. The rate limit for free trial users is 20 requests per minute (RPM) and 40000 tokens per minute (TPM) as per the extract (https://community.openai.com/t/498517) from the OpenAI community forum.
In your case, the error message shows that your limit is 3 RPM, and you've already used up those 3 requests. This is why you're seeing the rate limit exceeded error.
Your current polling interval is set to 5 seconds (or 12 requests per minute), which exceeds your limit of 3 RPM. To avoid hitting the rate limit, you need to adjust your polling interval to fit within your rate limit. For example, if your limit is 3 RPM, you should poll no more than once every 20 seconds.
Here's how you can adjust your code:
const run = await openai.beta.threads.runs.create(thread.id, {
assistant_id: assistant.id,
});
let completedRun = await openai.beta.threads.runs.retrieve(
thread.id,
run.id
);
const timeout = new Promise((_, reject) =>
setTimeout(() => reject(new Error("Request timed out")), 30000)
);
while (["in_progress", "queued"].includes(completedRun.status)) {
await Promise.race([
new Promise((resolve) => setTimeout(resolve, 20000)),
timeout,
]);
completedRun = await openai.beta.threads.runs.retrieve(
thread.id,
run.id
);
console.log(completedRun);
}
Remember, the rate limit is there to prevent abuse and ensure fair usage among all users. If you need a higher rate limit, consider upgrading your account or contacting OpenAI support.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: