Rate Limits

API usage limits and best practices

Rate Limits

To ensure fair usage and service stability, the API implements rate limiting.

Public API Limits

LimitValue
Max quotes per request10
Max requests per minute10
Max quotes per hour200

Rate Limit Headers

Every response includes rate limit information in the headers:

X-RateLimit-Limit-Requests: 10
X-RateLimit-Limit-Quotes: 200
X-RateLimit-Remaining: 150
X-RateLimit-Reset: 2024-01-15T11:00:00Z
HeaderDescription
X-RateLimit-Limit-RequestsMax requests per minute
X-RateLimit-Limit-QuotesMax quotes per hour
X-RateLimit-RemainingRemaining quota
X-RateLimit-ResetWhen the limit resets (ISO 8601)

Rate Limit Exceeded

When you exceed the rate limit, you'll receive a 429 Too Many Requests response:

{
  "statusCode": 429,
  "statusMessage": "Too Many Requests",
  "message": "Rate limit exceeded. You have 0 quotes remaining. Limit resets at 2024-01-15T11:00:00Z (in 45 seconds). Limits: 10 requests/min, 200 quotes/hour."
}

Best Practices

Optimize your API usage:

1. Cache Responses

Store API responses locally to reduce repeated requests:

const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
let cache = { data: null, timestamp: 0 };

async function getQuotes() {
  const now = Date.now();
  if (cache.data && now - cache.timestamp < CACHE_DURATION) {
    return cache.data;
  }
  
  const response = await fetch('https://quotegallery.nl/api/quotes?limit=10');
  cache.data = await response.json();
  cache.timestamp = now;
  return cache.data;
}

2. Batch Your Requests

Request multiple quotes at once instead of making individual requests:

# Good: One request for 10 quotes
curl "https://quotegallery.nl/api/quotes?limit=10"

# Bad: 10 separate requests
# curl "https://quotegallery.nl/api/quotes?limit=1" (x10)

3. Use Exclusion Lists

For "load more" functionality, use exclude_ids to avoid fetching duplicates:

let seenIds = [];

async function loadMore() {
  const params = new URLSearchParams({
    limit: '10',
    exclude_ids: seenIds.join(',')
  });
  
  const response = await fetch(`https://quotegallery.nl/api/v1/quotes?${params}`);
  const { data } = await response.json();
  
  seenIds.push(...data.map(q => q.id));
  return data;
}

4. Handle Rate Limits Gracefully

async function fetchWithRetry(url, retries = 3) {
  const response = await fetch(url);
  
  if (response.status === 429 && retries > 0) {
    const resetTime = response.headers.get('X-RateLimit-Reset');
    const waitTime = new Date(resetTime) - Date.now();
    
    await new Promise(resolve => setTimeout(resolve, Math.max(waitTime, 1000)));
    return fetchWithRetry(url, retries - 1);
  }
  
  return response;
}

Need Higher Limits?

Contact us if you need higher rate limits for your application.