Skip to main content

What Are Rate Limits?

Rate limits control how many requests you can make per minute. This prevents API abuse and ensures fair usage for all users.

Rate Limits by Tier

Each subscription tier has different rate limits:
TierRequests per MinuteRequests per HourRequests per Day
FREE1060014,400
PROUnlimitedUnlimitedUnlimited
Rate limits are per API key. FREE tier has a 10 requests per minute limit. PRO tier has unlimited requests.

Rate Limit Headers

Every response includes rate limit information in the headers:
X-RateLimit-Limit: 10
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1704326400
HeaderDescriptionExample
X-RateLimit-LimitTotal requests allowed per minute10 (FREE) or 999999 (PRO)
X-RateLimit-RemainingRequests remaining in current window45
X-RateLimit-ResetUnix timestamp when limit resets1704326400

Example in Code

const response = await fetch('https://api.scriptbase.app/api/v1/videos/abc123', {
  headers: { 'X-API-Key': 'sk_your_key' }
});

const rateLimit = {
  limit: parseInt(response.headers.get('X-RateLimit-Limit') || '0'),
  remaining: parseInt(response.headers.get('X-RateLimit-Remaining') || '0'),
  resetAt: parseInt(response.headers.get('X-RateLimit-Reset') || '0')
};

console.log(`${rateLimit.remaining}/${rateLimit.limit} requests remaining`);

if (rateLimit.remaining < 10) {
  console.warn('Approaching rate limit!');
}

Rate Limit Exceeded

When you exceed the rate limit, you’ll receive: HTTP Status: 429 Too Many Requests
{
  "success": false,
  "error": {
    "code": "RATE_LIMIT_EXCEEDED",
    "message": "Too many requests. Please try again in 45 seconds."
  }
}
The response also includes:
Retry-After: 45
This header tells you how many seconds to wait before retrying.

Handling Rate Limits

Basic Retry with Exponential Backoff

async function fetchWithRetry(url: string, apiKey: string, maxRetries = 3) {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    const response = await fetch(url, {
      headers: { 'X-API-Key': apiKey }
    });

    if (response.status === 429) {
      const retryAfter = parseInt(response.headers.get('Retry-After') || '60');
      console.log(`Rate limited. Waiting ${retryAfter} seconds...`);
      
      await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
      continue; // Retry
    }

    return response.json();
  }

  throw new Error('Max retries exceeded');
}

Rate Limiter with Token Bucket

For high-volume applications, implement a client-side rate limiter:
class RateLimiter {
  private tokens: number;
  private lastRefill: number;
  private readonly maxTokens: number;
  private readonly refillRate: number; // tokens per second

  constructor(requestsPerMinute: number) {
    this.maxTokens = requestsPerMinute;
    this.refillRate = requestsPerMinute / 60;
    this.tokens = requestsPerMinute;
    this.lastRefill = Date.now();
  }

  private refill() {
    const now = Date.now();
    const timePassed = (now - this.lastRefill) / 1000;
    this.tokens = Math.min(
      this.maxTokens,
      this.tokens + timePassed * this.refillRate
    );
    this.lastRefill = now;
  }

  async acquire() {
    this.refill();

    if (this.tokens >= 1) {
      this.tokens -= 1;
      return;
    }

    // Wait for token to be available
    const waitTime = (1 - this.tokens) / this.refillRate * 1000;
    await new Promise(resolve => setTimeout(resolve, waitTime));
    this.tokens = 0;
  }

  async execute<T>(fn: () => Promise<T>): Promise<T> {
    await this.acquire();
    return fn();
  }
}

// Usage
const limiter = new RateLimiter(60); // 60 requests per minute

for (const videoId of videoIds) {
  await limiter.execute(() => 
    fetch(`/api/v1/videos/${videoId}`, {
      headers: { 'X-API-Key': apiKey }
    })
  );
}

Best Practices

Always check the Retry-After header and wait the specified time before retrying.
If Retry-After isn’t available, use exponential backoff: wait 1s, then 2s, then 4s, etc.
Track X-RateLimit-Remaining and slow down requests when approaching the limit.
Batch endpoints process multiple items in one request, reducing total API calls.
Prevent hitting rate limits by controlling request rate on your end.
If you have multiple API keys, distribute requests across them to increase effective rate limit.

Checking Current Rate Limit

You can check your rate limit without consuming credits:
curl "https://api.scriptbase.app/api/v1/account" \
  -H "X-API-Key: sk_your_key"
The response includes your rate limit tier:
{
  "success": true,
  "data": {
    "plan": "PRO",
    "rateLimit": {
      "requestsPerMinute": 300,
      "requestsPerHour": 18000
    }
  }
}

Upgrading for Higher Limits

Need unlimited requests? Upgrade to Pro:
UpgradeRequests/minCredits/monthPrice
FREE → PRO10 → Unlimited200 → 10,000$19/mo
Upgrade Plan

Pro Tier Benefits

Pro plans include unlimited rate limits:
  • No request throttling
  • Handle traffic spikes
  • Build high-volume applications
  • 10,000 credits/month included
  • Auto-recharge available ($5/1,000 credits)
Upgrade to Pro