Rate Limits
Understand Metigan's rate limits and quotas to ensure your application handles them gracefully. Learn about different rate limit tiers and best practices.
Rate Limit Overview
Metigan uses rate limiting to ensure fair usage and maintain service quality. Rate limits vary based on your plan and are typically measured in requests per minute or per hour.
Free Plan
100
emails per day
Pro Plan
10,000
emails per day
Enterprise
Unlimited
custom limits
Rate Limit Headers
The API includes rate limit information in response headers:
rate-limit-headers.tsTypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Rate limit headers in API responses
{
'x-ratelimit-limit': '100', // Maximum requests allowed
'x-ratelimit-remaining': '95', // Remaining requests in window
'x-ratelimit-reset': '1640995200', // Unix timestamp when limit resets
'retry-after': '60' // Seconds to wait before retrying (if exceeded)
}
// Check rate limit status
async function checkRateLimit() {
const response = await fetch('https://api.metigan.com/v1/emails', {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
const limit = response.headers.get('x-ratelimit-limit');
const remaining = response.headers.get('x-ratelimit-remaining');
const reset = response.headers.get('x-ratelimit-reset');
console.log(`Rate limit: ${remaining}/${limit}`);
console.log(`Resets at: ${new Date(parseInt(reset!) * 1000).toLocaleString()}`);
}Handling Rate Limits
Implement proper handling for rate limit exceeded errors:
handle-rate-limit.tsTypeScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Metigan from 'metigan';
async function sendEmailWithRateLimitHandling() {
try {
const result = await metigan.email.sendEmail({
from: 'sender@example.com',
recipients: ['recipient@example.com'],
subject: 'Test',
content: '<p>Hello</p>'
});
if ('success' in result && result.success) {
return result;
}
// Handle rate limit error
if ('error' in result && result.error === 'rate_limit_exceeded') {
const retryAfter = result.retryAfter || 60; // Default to 60 seconds
console.log(`Rate limit exceeded. Retrying after ${retryAfter} seconds...`);
// Wait and retry
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
// Retry the request
return await metigan.email.sendEmail({
from: 'sender@example.com',
recipients: ['recipient@example.com'],
subject: 'Test',
content: '<p>Hello</p>'
});
}
return result;
} catch (error) {
console.error('Error:', error);
throw error;
}
}Best Practice
Monitor rate limit headers and implement exponential backoff for retries. Consider using a queue system for high-volume applications to avoid hitting rate limits.