If you see 429 Too Many Requests, you're hitting the API too frequently. Here's how to handle it properly.
The error
HTTP 429 Too Many Requests
{
"error": "Limit exceed."
}
Why this happens
Rate limits protect the API from excessive use:
Too many requests in a short time
Aggressive polling or scraping
No delay between requests
Concurrent requests without throttling
Exponential backoff strategy
The best way to handle rate limits is exponential backoff - wait longer after each retry:
async function fetchWithBackoff(url, options, maxRetries = 5) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
const response = await fetch(url, options);
if (response.status === 429) {
const waitTime = Math.pow(2, attempt) * 1000; // 1s, 2s, 4s, 8s, 16s
console.log(`Rate limited. Waiting ${waitTime}ms before retry ${attempt + 1}/${maxRetries}`);
await new Promise(resolve => setTimeout(resolve, waitTime));
continue;
}
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return await response.json();
} catch (error) {
if (attempt === maxRetries - 1) throw error;
}
}
throw new Error('Max retries exceeded');
}
Preventing rate limits
Add delays between requests:
// Bad: Rapid-fire requests
for (const id of mediaIds) {
await api.getResource(id); // No delay
}
// Good: Throttled requests
for (const id of mediaIds) {
await api.getResource(id);
await sleep(500); // 500ms delay
}
Batch your operations:
// Process in batches of 10 with delays
const batchSize = 10;
for (let i = 0; i < mediaIds.length; i += batchSize) {
const batch = mediaIds.slice(i, i + batchSize);
await Promise.all(batch.map(id => api.getResource(id)));
if (i + batchSize < mediaIds.length) {
await sleep(2000); // 2s between batches
}
}
Cache responses:
const cache = new Map();
async function getCachedResource(mediaId) {
if (cache.has(mediaId)) {
return cache.get(mediaId);
}
const data = await api.getResource(mediaId);
cache.set(mediaId, data);
return data;
}
What NOT to do
❌ Retry immediately without delay
❌ Make parallel requests without limit
❌ Ignore 429 errors
❌ Use fixed short delays (always use exponential backoff)
If problems persist
Contact developer support if you legitimately need higher rate limits for your use case. Provide details about:
Your application and use case
Expected request volume
Current implementation (with backoff)