- IntroductionGetting startedApi referenceBest practives
Rate Limiting
On this page
Understanding rate limits for Swiftia API
The Swiftia API employs a rate limit to ensure fair usage and prevent abuse. This limit applies to all API users.
Current Rate Limit
- Requests per Second: 2
Future Plans
Swiftia plans to introduce more sophisticated rate limiting, including tiered limits based on subscription plans and burst handling, in the future. This documentation will be updated when these changes are implemented.
Exceeding the Rate Limit
If you exceed the rate limit, you will receive a 429 Too Many Requests
error response:
{
"status": 429,
"message": "Rate limit exceeded. Please try again later.",
"code": "RATE_LIMIT_EXCEEDED"
}
The response will also include a Retry-After
header indicating how many seconds to wait before retrying the request.
Handling Rate Limits
- Implement retry logic: If you receive a 429 error, use the
Retry-After
header to determine when to retry the request. - Optimize your requests: Avoid unnecessary API calls to stay within your rate limit.
- Contact support: If you consistently exceed your rate limit, contact Swiftia support to discuss your needs.
Example Retry Logic (Python)
import requests
import time
def make_request(url):
response = requests.get(url, headers=headers)
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 1)) # Default to 1 second if header is missing
print(f"Rate limit exceeded. Retrying in {retry_after} seconds...")
time.sleep(retry_after)
return make_request(url) # Retry the request
return response
# ...