Rate Limiting Guide
Understand and manage API rate limits for optimal performance.
Rate Limits by Plan​
YODI implements rate limiting to ensure fair usage and service stability.
Rate Limits Per Plan​
| Plan | Requests/Minute | Requests/Hour | Monthly Limit |
|---|---|---|---|
| Freemium | 5 | 300 | 10 API calls |
| Dev Pass | 20 | 1,200 | 1,000 API calls |
| SMME Pass | - | - | 10,000 API calls |
| Pro Pass | 500 | 30,000 | 100,000 API calls |
| Enterprise | Custom | Custom | Unlimited |
Understanding Rate Limit Headers​
Every API response includes rate limit information in the headers:
X-RateLimit-Limit: 20
X-RateLimit-Remaining: 18
X-RateLimit-Reset: 1624881234
Header Meanings​
- X-RateLimit-Limit: Maximum requests allowed in current window
- X-RateLimit-Remaining: Requests remaining before hitting limit
- X-RateLimit-Reset: Unix timestamp when the limit resets
Handling Rate Limit Errors​
429 Too Many Requests​
When you exceed the rate limit, you'll receive a 429 status code:
{
"message": "RATE_LIMITED",
"error": true,
"data": null,
"status": 429
}
How to Handle It​
- Check the response header for
Retry-Aftervalue - Wait the specified time before retrying
- Use exponential backoff for multiple retries
Exponential Backoff Example (Python)​
import time
import requests
def retry_with_backoff(url, headers, data, max_retries=5):
for attempt in range(max_retries):
response = requests.post(url, headers=headers, json=data)
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 2 ** attempt))
print(f"Rate limited. Waiting {retry_after}s...")
time.sleep(retry_after)
continue
return response
raise Exception("Max retries exceeded")
Best Practices​
1. Monitor Your Limits​
response = requests.get(url, headers=headers)
# Check remaining requests
remaining = int(response.headers.get('X-RateLimit-Remaining', 0))
if remaining < 10:
print(f"Warning: Only {remaining} requests remaining!")
2. Batch Requests When Possible​
Instead of making individual requests:
# Bad - Multiple requests
for text in texts:
response = requests.post(url, data={'text': text})
# Good - Batch requests
batch = [{'text': t} for t in texts]
response = requests.post(url, data={'batch': batch})
3. Cache Results​
from functools import lru_cache
@lru_cache(maxsize=128)
def translate_cached(text, language):
return api.translate(text, language)
4. Implement Queuing​
For high-volume applications, use a queue system:
from queue import Queue
import threading
class APIQueue:
def __init__(self, rate_limit_per_sec=5):
self.queue = Queue()
self.rate_limit = rate_limit_per_sec
self.worker = threading.Thread(target=self._process)
self.worker.daemon = True
self.worker.start()
def _process(self):
last_request = 0
while True:
item = self.queue.get()
# Ensure minimum time between requests
time.sleep(max(0, last_request + (1/self.rate_limit) - time.time()))
self._make_request(item)
last_request = time.time()
Upgrade Your Plan​
If you consistently hit rate limits, consider upgrading:
- Dev Pass: 20 req/min ($19/month)
- Pro Pass: 500 req/min ($399/month)
- Enterprise: Custom limits (Contact sales)
Troubleshooting​
Q: Why am I getting 429 errors?​
A: You've exceeded the rate limit for your plan. Either:
- Wait before making more requests
- Upgrade to a higher plan
- Implement request batching
Q: Can I request a higher rate limit?​
A: Yes! Contact our support team or upgrade to Pro/Enterprise plan for higher limits.
Q: Does the rate limit reset hourly or daily?​
A: Rate limits reset on a rolling window basis. The X-RateLimit-Reset header tells you exactly when.