Rate Limits
Understanding API usage limits and best practices for TinyRebrand's OAuth 2.0 API
Rate limits protect TinyRebrand's API infrastructure and ensure fair usage across all users. Understanding these limits helps you build resilient applications that handle rate limiting gracefully.
Current Rate Limits
Token Requests
Authentication
5 requests per minute
API Requests
General API
60 requests per minute
Rate Limit Headers
Every API response includes rate limit information in the headers:
HTTP/1.1 200 OK
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1640995200
X-RateLimit-Used: 15
{
"status": 200,
"code": "OK",
"message": "Success",
"data": { ... }
}
Header | Description |
---|---|
X-RateLimit-Limit | Maximum requests per minute |
X-RateLimit-Remaining | Remaining requests in current window |
X-RateLimit-Reset | Unix timestamp when limit resets |
X-RateLimit-Used | Requests used in current window |
Rate Limit Exceeded Response
When you exceed the rate limit, you'll receive a 429 Too Many Requests response:
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1640995200
X-RateLimit-Used: 60
Retry-After: 60
{
"status": 429,
"code": "RATE_LIMIT_ERROR",
"message": "Too many requests from this IP, please try again later.",
"meta": {
"message": "Too many requests from this IP, please try again later."
}
}
Best Practices
Implement Exponential Backoff: When rate limited, wait before retrying. Increase wait time exponentially for subsequent failures.
Cache Responses: Cache API responses when possible to reduce the number of requests needed.
Monitor Usage: Track rate limit headers to understand your usage patterns and optimize accordingly.
Implementation Examples
JavaScript with Exponential Backoff
async function makeRequestWithBackoff(url, options, maxRetries = 3) {
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
const response = await fetch(url, options);
if (response.status === 429) {
const retryAfter = response.headers.get('Retry-After');
const waitTime = retryAfter ? parseInt(retryAfter) * 1000 : Math.pow(2, attempt) * 1000;
console.log(`Rate limited. Waiting ${waitTime}ms before retry ${attempt + 1}`);
await new Promise(resolve => setTimeout(resolve, waitTime));
continue;
}
return response;
} catch (error) {
if (attempt === maxRetries) throw error;
const waitTime = Math.pow(2, attempt) * 1000;
await new Promise(resolve => setTimeout(resolve, waitTime));
}
}
}
Python with Rate Limit Handling
import time
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
def create_session_with_backoff():
session = requests.Session()
# Configure retry strategy
retry_strategy = Retry(
total=3,
backoff_factor=1,
status_forcelist=[429, 500, 502, 503, 504],
method_whitelist=["HEAD", "GET", "OPTIONS", "POST", "PUT", "DELETE"]
)
adapter = HTTPAdapter(max_retries=retry_strategy)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session
def make_api_request(url, headers):
session = create_session_with_backoff()
try:
response = session.get(url, headers=headers)
# Check rate limit headers
remaining = response.headers.get('X-RateLimit-Remaining')
if remaining and int(remaining) < 5:
print(f"Rate limit warning: {remaining} requests remaining")
return response.json()
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
return None
Avoiding Rate Limits
- Batch requests: Group multiple operations when possible
- Use webhooks: Instead of polling, use webhooks for real-time updates
- Optimize queries: Use query parameters to fetch only needed data
- Cache strategically: Cache responses with appropriate TTL values
- Implement circuit breakers: Stop making requests temporarily when errors occur
Rate Limit Monitoring
Monitor your application's rate limit usage to optimize performance:
// Track rate limit usage
function trackRateLimit(response) {
const limit = response.headers.get('X-RateLimit-Limit');
const remaining = response.headers.get('X-RateLimit-Remaining');
const reset = response.headers.get('X-RateLimit-Reset');
console.log(`Rate Limit: ${limit - remaining}/${limit} used`);
console.log(`Resets at: ${new Date(reset * 1000).toISOString()}`);
// Log to monitoring service
monitor.gauge('api.rate_limit.used', limit - remaining);
monitor.gauge('api.rate_limit.remaining', remaining);
}
Need Higher Limits?
If your application requires higher rate limits, please reach out to us via Twitter or Telegram with details about your use case.