Promise.all over 5000 ids fires 5000 requests at once, the setTimeout doesn't change that. 60/min is one per second, so this import takes ~85 minutes no matter what. Accept that and make it robust:
for (const id of ids) {
const res = await fetchWithRetry(id);
await save(res);
await new Promise(r => setTimeout(r, 1100));
}
async function fetchWithRetry(id, tries = 5) {
const res = await fetch(url(id), { headers });
if (res.status === 429 && tries > 0) {
const wait = Number(res.headers.get("retry-after") ?? 10) * 1000;
await new Promise(r => setTimeout(r, wait));
return fetchWithRetry(id, tries - 1);
}
return res.json();
}Save progress as you go so a crash doesn't restart from zero. And no key rotation, you're right that it violates most ToS.