Rate Limits
APIVerve implements rate limiting to ensure fair usage and maintain service quality for all users.
How Rate Limiting Works
APIVerve uses a token bucket algorithm to ensure fair usage and maintain service quality. Rate limits vary based on your subscription plan.
For detailed information about rate limits and pricing for each plan, visit our pricing page.
Rate Limit Errors
When you exceed rate limits, you'll receive specific error responses:
{
"status": "error",
"error": "Rate limit exceeded. Try again in 60 seconds.",
"data": null
}
{
"status": "error",
"error": "Monthly quota exceeded. Upgrade your plan or wait for next billing cycle.",
"data": null
}
Handling Rate Limits in Code
Implement proper rate limit handling with exponential backoff:
class APIVerveClient {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseURL = 'https://api.apiverve.com/v1';
}
async makeRequest(endpoint, params = {}, maxRetries = 3) {
for (let attempt = 0; attempt <= maxRetries; attempt++) {
try {
const response = await fetch(`${this.baseURL}/${endpoint}?${new URLSearchParams(params)}`, {
headers: {
'X-API-Key': this.apiKey
}
});
// Check for rate limiting
if (response.status === 429) {
const retryAfter = parseInt(response.headers.get('Retry-After')) || Math.pow(2, attempt);
console.log(`Rate limited. Retrying after ${retryAfter} seconds...`);
if (attempt < maxRetries) {
await this.sleep(retryAfter * 1000);
continue;
}
}
const data = await response.json();
// Log usage information
const remaining = response.headers.get('X-RateLimit-Remaining');
const quotaRemaining = response.headers.get('X-Monthly-Quota-Remaining');
console.log(`Requests remaining: ${remaining}, Monthly quota: ${quotaRemaining}`);
return data;
} catch (error) {
if (attempt === maxRetries) throw error;
await this.sleep(Math.pow(2, attempt) * 1000);
}
}
}
sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
import requests
import time
import logging
class APIVerveClient:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = 'https://api.apiverve.com/v1'
self.session = requests.Session()
self.session.headers.update({'X-API-Key': api_key})
def make_request(self, endpoint, params=None, max_retries=3):
params = params or {}
for attempt in range(max_retries + 1):
try:
response = self.session.get(
f'{self.base_url}/{endpoint}',
params=params,
timeout=30
)
# Handle rate limiting
if response.status_code == 429:
retry_after = int(response.headers.get('Retry-After', 2 ** attempt))
logging.warning(f'Rate limited. Retrying after {retry_after} seconds...')
if attempt < max_retries:
time.sleep(retry_after)
continue
response.raise_for_status()
# Log usage information
remaining = response.headers.get('X-RateLimit-Remaining')
quota_remaining = response.headers.get('X-Monthly-Quota-Remaining')
logging.info(f'Requests remaining: {remaining}, Monthly quota: {quota_remaining}')
return response.json()
except requests.exceptions.RequestException as e:
if attempt == max_retries:
raise
time.sleep(2 ** attempt)
raise Exception('Max retries exceeded')
<?php
class APIVerveClient {
private $apiKey;
private $baseUrl = 'https://api.apiverve.com/v1';
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}
public function makeRequest($endpoint, $params = [], $maxRetries = 3) {
for ($attempt = 0; $attempt <= $maxRetries; $attempt++) {
$url = $this->baseUrl . '/' . $endpoint;
if (!empty($params)) {
$url .= '?' . http_build_query($params);
}
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => [
'X-API-Key: ' . $this->apiKey
],
CURLOPT_TIMEOUT => 30,
CURLOPT_HEADER => 1
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $headerSize);
$body = substr($response, $headerSize);
curl_close($ch);
// Handle rate limiting
if ($httpCode === 429) {
preg_match('/Retry-After: (d+)/', $headers, $matches);
$retryAfter = isset($matches[1]) ? (int)$matches[1] : pow(2, $attempt);
error_log("Rate limited. Retrying after {$retryAfter} seconds...");
if ($attempt < $maxRetries) {
sleep($retryAfter);
continue;
}
}
// Log usage information
preg_match('/X-RateLimit-Remaining: (d+)/', $headers, $matches);
$remaining = isset($matches[1]) ? $matches[1] : 'unknown';
error_log("Requests remaining: {$remaining}");
return json_decode($body, true);
}
throw new Exception('Max retries exceeded');
}
}
?>
Best Practices
Follow these recommendations to optimize your API usage and avoid rate limiting issues:
- Monitor Usage: Track your API usage through response headers and dashboard analytics to avoid unexpected limits
- Implement Caching: Cache responses when appropriate to reduce API calls and stay within limits
- Respect Retry-After: Always honor the Retry-After header value when receiving 429 responses
- Distribute Load: Spread requests over time instead of making bulk requests simultaneously
- Plan Upgrades: Upgrade your plan proactively if you're consistently hitting limits
Implement exponential backoff in your retry logic to automatically handle temporary rate limiting and improve your application's resilience.
Monitoring Your Usage
Keep track of your API usage through multiple channels:
- Dashboard: Real-time usage statistics and historical data in your APIVerve dashboard
- Response Headers: Check rate limit headers in every API response for current status
- Usage Alerts: Set up email alerts when approaching 80% and 95% of your limits
- Analytics API: Programmatically access usage data through our Analytics API
Enable usage alerts in your dashboard to receive notifications before you hit your rate limits. This proactive approach helps prevent service interruptions.
Was this page helpful?
Help us improve our documentation