Rate Limits
Understanding API rate limits and best practices
Rate Limits
The AltSportsData API implements rate limiting to ensure fair usage and system stability.
Rate Limit Headers
Every API response includes rate limit information in the headers:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1678886400- X-RateLimit-Limit: Maximum requests allowed per window
- X-RateLimit-Remaining: Requests remaining in current window
- X-RateLimit-Reset: Unix timestamp when the limit resets
Rate Limit Tiers
| Tier | Requests/Hour | Requests/Day |
|---|---|---|
| Demo | 100 | 1,000 |
| Free | 1,000 | 10,000 |
| Pro | 10,000 | 100,000 |
| Enterprise | Custom | Custom |
Handling Rate Limits
When you exceed the rate limit, you'll receive a 429 Too Many Requests response:
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded. Please retry after 1678886400",
"retry_after": 1678886400
}
}Best Practices
- Monitor Headers: Check rate limit headers in responses
- Implement Backoff: Use exponential backoff when approaching limits
- Cache Responses: Cache data when appropriate to reduce API calls
- Batch Requests: Use pagination and filtering to minimize requests
- Handle 429s Gracefully: Wait for the
retry_aftertime before retrying
Example Implementation
import requests
import time
def make_request_with_retry(url, headers, max_retries=3):
for attempt in range(max_retries):
response = requests.get(url, headers=headers)
if response.status_code == 429:
retry_after = int(response.headers.get('X-RateLimit-Reset', time.time() + 60))
wait_time = retry_after - int(time.time())
print(f"Rate limited. Waiting {wait_time} seconds...")
time.sleep(wait_time)
continue
return response
raise Exception("Max retries exceeded")async function makeRequestWithRetry(url, headers, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
const response = await fetch(url, { headers });
if (response.status === 429) {
const resetTime = parseInt(response.headers.get('X-RateLimit-Reset'));
const waitTime = resetTime - Math.floor(Date.now() / 1000);
console.log(`Rate limited. Waiting ${waitTime} seconds...`);
await new Promise(resolve => setTimeout(resolve, waitTime * 1000));
continue;
}
return response;
}
throw new Error('Max retries exceeded');
}Increasing Limits
If you need higher rate limits, please contact our sales team to discuss Enterprise plans with custom limits tailored to your needs.