Docs

Rate Limits

Understand API rate limits and implement proper throttling to ensure reliable integration.

Rate Limit Overview

Rate limits prevent abuse and ensure fair usage of the Zyhap SMM API. They are applied per API key and reset at regular intervals.

Standard Limits

  • • 1,000 requests/hour for read operations
  • • 200 requests/hour for write operations
  • • 50 posts/hour for publishing
  • • 10 files/minute for media uploads

Premium Limits

  • • 5,000 requests/hour for read operations
  • • 1,000 requests/hour for write operations
  • • 500 posts/hour for publishing
  • • 100 files/minute for media uploads

Rate Limit Headers

Every API response includes headers that help you track your rate limit status:

Response Headers:
X-RateLimit-Limit: 1000          // Total requests allowed per window
X-RateLimit-Remaining: 995        // Requests remaining in current window  
X-RateLimit-Reset: 1640995200     // Unix timestamp when window resets
X-RateLimit-Window: 3600          // Window duration in seconds
Retry-After: 1800                 // Seconds to wait if rate limited

Important

Always check these headers to avoid hitting rate limits. Monitor X-RateLimit-Remaining and slow down when it gets low.

Handling Rate Limits

1. Monitor Rate Limit Headers

JavaScript Example:
async function makeAPIRequest(url, options) {
  const response = await fetch(url, options);
  
  // Check rate limit headers
  const remaining = parseInt(response.headers.get('X-RateLimit-Remaining'));
  const resetTime = parseInt(response.headers.get('X-RateLimit-Reset'));
  
  // Log rate limit status
  console.log(`Rate limit: ${remaining} requests remaining`);
  
  // Slow down if getting close to limit
  if (remaining < 10) {
    console.warn('Approaching rate limit, slowing down...');
    await delay(2000); // Wait 2 seconds
  }
  
  return response;
}

2. Implement Exponential Backoff

Retry Logic Example:
async function apiRequestWithRetry(url, options, maxRetries = 3) {
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
    try {
      const response = await fetch(url, options);
      
      if (response.status === 429) {
        // Rate limited - check Retry-After header
        const retryAfter = response.headers.get('Retry-After');
        const delay = retryAfter ? parseInt(retryAfter) * 1000 : Math.pow(2, attempt) * 1000;
        
        console.log(`Rate limited. Waiting ${delay/1000} seconds...`);
        await new Promise(resolve => setTimeout(resolve, delay));
        continue;
      }
      
      if (response.ok) {
        return response;
      }
      
      throw new Error(`HTTP ${response.status}: ${response.statusText}`);
    } catch (error) {
      if (attempt === maxRetries) {
        throw error;
      }
      
      // Exponential backoff for other errors
      const delay = Math.pow(2, attempt) * 1000;
      await new Promise(resolve => setTimeout(resolve, delay));
    }
  }
}

3. Queue and Batch Requests

Request Queue Example:
class APIRequestQueue {
  constructor(requestsPerSecond = 1) {
    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);
      }
      
      // Wait before processing next request
      await new Promise(resolve => setTimeout(resolve, this.interval));
    }
    
    this.processing = false;
  }
}

// Usage
const apiQueue = new APIRequestQueue(0.5); // 0.5 requests per second

// Queue requests instead of making them directly
const result = await apiQueue.add(() => 
  fetch('/api/posts', { method: 'POST', body: JSON.stringify(postData) })
);

Best Practices

Cache API Responses

Cache frequently accessed data to reduce API calls. Use appropriate cache expiration times.

Batch Operations

Group multiple operations into single requests when the API supports it.

Use Webhooks

Set up webhooks for real-time notifications instead of polling for status updates.

Monitor Usage

Track your API usage patterns to optimize request timing and identify bottlenecks.

Common Scenarios

❌ Bad Practice


posts.forEach(post => createPost(post));

This will quickly hit rate limits and cause errors.

✅ Good Practice


for (const post of posts) {
  await createPost(post);
  await delay(1000);
}

This respects rate limits and processes reliably.

📊 Rate Limit Monitoring

Track Metrics

  • • Requests per hour/minute
  • • Rate limit violations
  • • Average response times
  • • Success/error rates

Set Alerts

  • • When approaching 80% of limit
  • • When receiving 429 errors
  • • For unusual usage spikes
  • • When retry attempts exceed threshold