Developer
Rate Limits
Understand API rate limits and how to work within them.
The Cafora Host API enforces rate limits to ensure fair usage and service stability.
Rate Limit Tiers
| Endpoint Type | Rate Limit |
|---|---|
| Read operations | Higher limit (info queries) |
| Write operations | Moderate limit (actions) |
| Backup operations | Lower limit (resource-intensive) |
Exact rate limits are documented in the API response headers. Always check X-RateLimit-Remaining in responses.
Rate Limit Headers
Every API response includes rate limit information:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1642000000Limit: Total requests allowed in the windowRemaining: Requests remaining in the current windowReset: Unix timestamp when the limit resets
Handling Rate Limits
429 Too Many Requests
When you exceed the rate limit, the API returns a 429 status code. Your application should:
- Read the
Retry-Afterheader for the wait time - Wait before making additional requests
- Implement exponential backoff for retries
import time
import requests
def api_request(url, headers):
response = requests.get(url, headers=headers)
if response.status_code == 429:
retry_after = int(response.headers.get("Retry-After", 5))
print(f"Rate limited. Waiting {retry_after}s")
time.sleep(retry_after)
return api_request(url, headers)
return responseBest Practices
- Cache responses when possible to reduce API calls
- Use webhooks instead of polling for status changes
- Batch operations when the API supports it
- Monitor
X-RateLimit-Remainingproactively