Rate Limiting
Overview
The Relink API implements rate limiting to ensure fair usage and maintain service quality for all users. Rate limits are applied per API key and help prevent abuse.
Rate Limit Response
When you exceed the rate limit, you’ll receive a 429 Too Many Requests
response:
{
"error": "Too many requests, please try again later.",
"status": 429
}
Best Practices
Implement Exponential Backoff
When you receive a 429 response, implement exponential backoff:
async function apiCallWithRetry(url, options, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
const response = await fetch(url, options);
if (response.status === 429) {
// Wait before retrying: 1s, 2s, 4s, etc.
const delay = Math.pow(2, attempt) * 1000;
await new Promise(resolve => setTimeout(resolve, delay));
continue;
}
return response;
}
throw new Error('Max retries exceeded');
}
Batch Operations
For multiple operations, implement proper batching with delays:
async function batchUpdate(updates) {
const results = [];
const batchSize = 5;
for (let i = 0; i < updates.length; i += batchSize) {
const batch = updates.slice(i, i + batchSize);
// Process batch in parallel
const batchPromises = batch.map(update =>
apiCallWithRetry('/api/v1/smartlink', {
method: 'PUT',
headers: {
'Authorization': 'Bearer rlk_your_api_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify(update)
})
);
const batchResults = await Promise.all(batchPromises);
results.push(...batchResults);
// Add delay between batches
if (i + batchSize < updates.length) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
return results;
}
Monitor Your Usage
Keep track of your API usage patterns:
class APIClient {
constructor(apiKey) {
this.apiKey = apiKey;
this.requestCount = 0;
this.lastReset = Date.now();
}
async makeRequest(endpoint, options = {}) {
this.requestCount++;
const response = await fetch(endpoint, {
...options,
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json',
...options.headers
}
});
if (response.status === 429) {
console.warn(`Rate limit hit after ${this.requestCount} requests`);
}
return response;
}
}
Error Handling
Always handle rate limiting gracefully in your application:
async function handleAPICall(apiCall) {
try {
const response = await apiCall();
if (response.status === 429) {
// Show user-friendly message
throw new Error('API rate limit exceeded. Please try again in a moment.');
}
return await response.json();
} catch (error) {
if (error.message.includes('rate limit')) {
// Handle rate limit specifically
console.log('Rate limited - implementing backoff strategy');
// Implement retry logic here
}
throw error;
}
}