Skip to content

Rate Limiting

The SDK supports both traditional rate limiting and an advanced adaptive system that dynamically allocates API capacity based on real-time user activity. Rate limiting is provided by @http-client-toolkit store packages.

import ComicVine from 'comic-vine-sdk';
import { InMemoryRateLimitStore } from '@http-client-toolkit/store-memory';
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
rateLimit: new InMemoryRateLimitStore({
defaultConfig: { limit: 200, windowMs: 3600000 }, // 200 req/hour
}),
},
});

The adaptive system dynamically allocates API capacity between user requests (interactive, time-sensitive) and background requests (bulk operations, scheduled tasks):

import ComicVine from 'comic-vine-sdk';
import { AdaptiveRateLimitStore } from '@http-client-toolkit/store-memory';
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
rateLimit: new AdaptiveRateLimitStore(),
},
});
// User-facing requests get priority
const character = await client.character.retrieve(1443, {
priority: 'user',
});
// Background processing gets remaining capacity
for await (const issue of client.issue.list({ priority: 'background' })) {
// Process issues in background
}

The system monitors activity in real-time and transitions between four strategies:

StrategyUser ActivityUser CapacityBackground Capacity
Night ModeZero0%100% (200/200)
Low ActivityLow30% reserved70%
Moderate ActivityModerateDynamic scalingDynamic scaling
High ActivityHigh90% priority10% (paused on increasing trend)

Use priority: 'user' for:

  • Interactive user requests (searches, detail views)
  • Real-time features (autocomplete, live updates)
  • Time-sensitive operations

Use priority: 'background' for:

  • Bulk data processing
  • Scheduled synchronization
  • Cache warming
  • Analytics and reporting
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
rateLimit: new AdaptiveRateLimitStore({
adaptiveConfig: {
highActivityThreshold: 15, // Requests per 15min for high activity
moderateActivityThreshold: 5, // Requests per 15min for moderate
monitoringWindowMs: 20 * 60 * 1000, // 20 minute monitoring window
sustainedInactivityThresholdMs: 45 * 60 * 1000, // 45min before full background
recalculationIntervalMs: 60000, // Recalculate every 60 seconds
maxUserScaling: 1.5, // Max user capacity multiplier
minUserReserved: 10, // Minimum guaranteed user requests
backgroundPauseOnIncreasingTrend: true, // Pause background on rising activity
},
}),
},
});

Check the current adaptive status:

const status = await client.getRateLimitStatus('characters');
console.log(status);
// {
// remaining: 120,
// resetTime: Date,
// limit: 200,
// }

Use SQLite stores for rate limiting that survives application restarts:

import { SqliteAdaptiveRateLimitStore } from '@http-client-toolkit/store-sqlite';
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
rateLimit: new SqliteAdaptiveRateLimitStore({
database: './comic-vine.db',
}),
},
});

Existing code works unchanged — requests without a priority are treated as 'background' by default:

// Existing code - no changes needed
const issue = await client.issue.retrieve(1);
const issues = await client.issue.list();
// Gradually add priority where beneficial
const userSearch = await client.character.list({
filter: { name: searchTerm },
priority: 'user',
});

The client supports two modes for handling rate limit violations:

const client = new ComicVine({
apiKey: 'your-api-key',
client: { throwOnRateLimit: true },
});
const client = new ComicVine({
apiKey: 'your-api-key',
client: {
throwOnRateLimit: false,
maxWaitTime: 60000, // Wait up to 1 minute
},
});