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.