Rate Limits¶
Fasiri enforces rate limits to ensure fair usage and API stability.
Default limits¶
| Endpoint | Limit |
|---|---|
POST /api/v1/translate |
60 requests/minute per API key |
POST /api/v1/translate/batch |
10 requests/minute per API key |
POST /api/v1/speech/stt |
60 requests/minute per API key |
POST /api/v1/speech/tts |
60 requests/minute per API key |
Limits are per API key, using a sliding window algorithm.
Rate limit headers¶
When you are rate limited, the response includes:
HTTP/1.1 429 Too Many Requests
Retry-After: 42
Content-Type: application/json
{
"detail": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit of 60 requests/minute exceeded. Retry after 42 seconds.",
"retry_after_seconds": 42
}
}
Handling rate limits¶
import asyncio
from fasiri import Fasiri, RateLimitError
client = Fasiri(api_key="fsri_...")
async def translate_with_retry(text, target, max_attempts=5):
for attempt in range(max_attempts):
try:
return await client.async_translate(text, target=target)
except RateLimitError as e:
if attempt == max_attempts - 1:
raise
await asyncio.sleep(e.retry_after)
Best practices¶
Use batch translation
Instead of 50 individual translate calls, make one batch call:
Cache translations
Cache results for repeated translations of the same text: