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.
Response Headers
Every API response includes headers to help you monitor your usage and handle rate limits:
Rate Limit Headers
| Header | Description |
|---|---|
x-rate-limit-limit | Maximum requests allowed per minute for your plan |
x-rate-limit-remaining | Remaining requests in the current minute window |
x-rate-limit-reset | Seconds until the rate limit resets (only on 429 responses) |
retry-after | Seconds to wait before retrying (only on 429 responses) |
Token Usage Headers
| Header | Description |
|---|---|
x-api-tokens-used | Total tokens consumed in your current billing period |
x-api-max-tokens | Maximum tokens available for your plan |
x-api-remaining-tokens | Remaining tokens in your current billing period |
x-api-current-plan | Your current subscription plan |
x-api-renewal | Date when your token allocation resets |
Rate Limit Errors
When you exceed rate limits, you'll receive specific error responses:
{
"status": "error",
"error": "Rate limit exceeded. Max 60 requests per minute. Consider upgrading for no rate limits",
"data": null
}{
"status": "error",
"error": "tokens have been depleted",
"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 rateLimitRemaining = response.headers.get('x-rate-limit-remaining');
const tokensRemaining = response.headers.get('x-api-remaining-tokens');
console.log(`Rate limit remaining: ${rateLimitRemaining}, Tokens remaining: ${tokensRemaining}`);
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
rate_limit_remaining = response.headers.get('x-rate-limit-remaining')
tokens_remaining = response.headers.get('x-api-remaining-tokens')
logging.info(f'Rate limit remaining: {rate_limit_remaining}, Tokens remaining: {tokens_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-rate-limit-remaining: (d+)/i', $headers, $matches);
$rateLimitRemaining = isset($matches[1]) ? $matches[1] : 'unknown';
preg_match('/x-api-remaining-tokens: (d+)/i', $headers, $matches);
$tokensRemaining = isset($matches[1]) ? $matches[1] : 'unknown';
error_log("Rate limit remaining: {$rateLimitRemaining}, Tokens remaining: {$tokensRemaining}");
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