Rate Limiting
Managing API usage with PayOS rate limits
Overview
Rate limiting is used to control the number of API requests a merchant can make within a specific period. This ensures system stability, prevents abuse, and maintains high performance across the PayOS platform. It is essential for merchants to monitor their API usage and implement strategies to manage rate limits effectively.
How Rate Limiting Works
-
Rate Limit Threshold:
- PayOS sets a maximum number of requests per minute for each API key.
- Exceeding the threshold will result in
429 Too Many Requests
responses.
-
Rate Limit Scope:
- Rate limits are applied per API key.
- Limits may vary between sandbox and production environments to allow more flexibility during development.
Example Rate Limit Error Response
If your API key exceeds the rate limit, you will receive a response like the following:
Handling Rate Limits in Your Integration
-
Monitor API Usage:
- Use the PayOS dashboard to track your API request volume in real-time.
-
Implement Exponential Backoff:
- Use exponential backoff when retrying requests to avoid further rate limit violations.
-
Handle 429 Responses Gracefully:
- If you encounter a
429 Too Many Requests
response, use theRetry-After
header to determine when it is safe to retry the request.
- If you encounter a
Example of Exponential Backoff in JavaScript
Monitoring API Limits via Webhooks
PayOS can also notify merchants via webhooks if their API usage approaches predefined thresholds. Example webhook payload:
Best Practices for Managing Rate Limits
-
Batch Requests:
- Where possible, batch multiple API calls into a single request to minimize usage.
-
Use Caching:
- Cache responses from the PayOS API to avoid redundant requests.
-
Monitor Usage Trends:
- Regularly review your API usage patterns and adjust your implementation to stay within limits.
Conclusion
Rate limiting ensures that PayOS remains stable and responsive for all merchants. By following best practices, merchants can efficiently manage their API usage, avoid disruptions, and maintain smooth operations across their payment systems.