Rate Limiting
Understanding API rate limits and best practices
Reading time: 4 minutes
Rate Limiting
Learn about API rate limits and how to handle them effectively.
Overview
Rate limiting protects our API from abuse and ensures fair usage for all developers. Each endpoint has specific rate limits based on the operation type and your plan.
Rate Limit Headers
Every API response includes rate limit information in headers:
| Parameter | Type | Required | Description |
|---|---|---|---|
X-RateLimit-Limit | integer | No | Maximum number of requests allowed per window |
X-RateLimit-Remaining | integer | No | Number of requests remaining in current window |
X-RateLimit-Reset | integer | No | Unix timestamp when the rate limit window resets |
Example Response Headers
Rate Limit Headers Examplehttp
HTTP/1.1 200 OK
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1704124800
Content-Type: application/jsonRate Limits by Endpoint
Message Endpoints
| Endpoint | Limit | Window |
|---|---|---|
| Send Text Message | 1000 | 1 hour |
| Send Media Message | 500 | 1 hour |
| Send Template Message | 100 | 1 hour |
| Send Button Message | 1000 | 1 hour |
| Send List Message | 1000 | 1 hour |
Data Retrieval Endpoints
| Endpoint | Limit | Window |
|---|---|---|
| List Contacts | 200 | 1 minute |
| List Conversations | 200 | 1 minute |
| List Orders | 200 | 1 minute |
| Get Template | 500 | 1 minute |
Management Endpoints
| Endpoint | Limit | Window |
|---|---|---|
| Create Contact | 100 | 1 minute |
| Update Contact | 100 | 1 minute |
| Create Branch | 50 | 1 hour |
| Update Branch | 50 | 1 hour |
Rate Limit Responses
429 Too Many Requests
When you exceed the rate limit, you'll receive a 429 status code:
Rate Limit Exceeded Responsehttp
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1704128400
Retry-After: 3600
Content-Type: application/json
{
"error": "Rate limit exceeded",
"message": "You have exceeded the rate limit for this endpoint",
"retry_after": 3600
}| Parameter | Type | Required | Description |
|---|---|---|---|
Retry-After | integer | No | Number of seconds to wait before retrying |
Handling Rate Limits
Exponential Backoff
Implement exponential backoff when you receive a 429 response:
Exponential Backoff Examplejavascript
async function makeRequestWithRetry(url, options, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
const response = await fetch(url, options);
if (response.status === 429) {
const retryAfter = parseInt(response.headers.get('Retry-After') || '60');
const waitTime = retryAfter * Math.pow(2, attempt);
console.log(`Rate limited. Waiting ${waitTime} seconds...`);
await new Promise(resolve => setTimeout(resolve, waitTime * 1000));
continue;
}
return response;
} catch (error) {
if (attempt === maxRetries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, 1000 * Math.pow(2, attempt)));
}
}
}Queue-Based Approach
For high-volume applications, use a queue system:
Queue-Based Rate Limitingjavascript
class RateLimitedQueue {
constructor(requestsPerSecond = 10) {
this.queue = [];
this.processing = false;
this.interval = 1000 / requestsPerSecond;
}
async add(requestFn) {
return new Promise((resolve, reject) => {
this.queue.push({ requestFn, resolve, reject });
this.process();
});
}
async process() {
if (this.processing || this.queue.length === 0) return;
this.processing = true;
while (this.queue.length > 0) {
const { requestFn, resolve, reject } = this.queue.shift();
try {
const result = await requestFn();
resolve(result);
} catch (error) {
reject(error);
}
await new Promise(resolve => setTimeout(resolve, this.interval));
}
this.processing = false;
}
}
// Usage
const queue = new RateLimitedQueue(10); // 10 requests per second
for (let i = 0; i < 100; i++) {
queue.add(() => sendMessage({ phone: '96650000000', body: `Message ${i}` }));
}Best Practices
ā
Best Practices
- Monitor Headers: Always check rate limit headers in responses
- Implement Caching: Cache frequently accessed data to reduce API calls
- Batch Operations: Use batch endpoints when available
- Plan Ahead: Design your application to handle rate limits gracefully
- Use Webhooks: Subscribe to webhooks instead of polling
Caching Example
Caching Examplejavascript
// Cache templates to avoid repeated API calls
const templateCache = new Map();
const CACHE_TTL = 3600000; // 1 hour
async function getTemplate(templateId) {
const cached = templateCache.get(templateId);
if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
return cached.data;
}
const template = await fetchTemplate(templateId);
templateCache.set(templateId, {
data: template,
timestamp: Date.now()
});
return template;
}Rate Limit by Plan
Free Plan
- Messages: 100 per hour
- Data Retrieval: 50 per minute
- Management: 20 per hour
Basic Plan
- Messages: 1,000 per hour
- Data Retrieval: 200 per minute
- Management: 100 per hour
Professional Plan
- Messages: 10,000 per hour
- Data Retrieval: 500 per minute
- Management: 500 per hour
Enterprise Plan
- Messages: Custom limits
- Data Retrieval: Custom limits
- Management: Custom limits
Upgrade Your Plan: Need higher limits? Contact us to discuss enterprise options.
Monitoring Rate Limits
Track Usage
Monitor your rate limit usage in real-time:
Rate Limit Monitoringjavascript
function trackRateLimit(response) {
const limit = parseInt(response.headers.get('X-RateLimit-Limit'));
const remaining = parseInt(response.headers.get('X-RateLimit-Remaining'));
const reset = parseInt(response.headers.get('X-RateLimit-Reset'));
const usage = {
limit,
remaining,
used: limit - remaining,
percentage: ((limit - remaining) / limit) * 100,
resetTime: new Date(reset * 1000)
};
// Log or send to monitoring service
console.log('Rate limit usage:', usage);
// Alert if usage is high
if (usage.percentage > 80) {
console.warn('Rate limit usage is high:', usage.percentage + '%');
}
return usage;
}Related Sections
Technical Support
Need help with rate limits?
- š§ Email: support@awalchat.com
- š¬ Live Chat: Available in the dashboard
- š± WhatsApp: Contact us directly via WhatsApp
- š Examples: Check Code Examples