HomeUser GuidesAPI Reference
Get Started
HomeAPI Reference
Authentication
Branches
Contact Groups
Contacts
Conversations
Error HandlingInvoices
Messages
Orders
Rate LimitingSDKs & Code ExamplesTemplatesTicketsAPI VersioningWABA NumbersWebhooks
User GuideAPI ReferenceRate Limiting

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:

ParameterTypeRequiredDescription
X-RateLimit-LimitintegerNoMaximum number of requests allowed per window
X-RateLimit-RemainingintegerNoNumber of requests remaining in current window
X-RateLimit-ResetintegerNoUnix 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/json

Rate Limits by Endpoint

Message Endpoints

EndpointLimitWindow
Send Text Message10001 hour
Send Media Message5001 hour
Send Template Message1001 hour
Send Button Message10001 hour
Send List Message10001 hour

Data Retrieval Endpoints

EndpointLimitWindow
List Contacts2001 minute
List Conversations2001 minute
List Orders2001 minute
Get Template5001 minute

Management Endpoints

EndpointLimitWindow
Create Contact1001 minute
Update Contact1001 minute
Create Branch501 hour
Update Branch501 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
}
ParameterTypeRequiredDescription
Retry-AfterintegerNoNumber 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

  1. Monitor Headers: Always check rate limit headers in responses
  2. Implement Caching: Cache frequently accessed data to reduce API calls
  3. Batch Operations: Use batch endpoints when available
  4. Plan Ahead: Design your application to handle rate limits gracefully
  5. 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

Authentication

Learn about API authentication

View Guide
View

Messages

Send messages efficiently

View Guide
View

Webhooks

Use webhooks to reduce API calls

View Guide
View

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