Interface ApiKeyPoolConfig

Configuration for an ApiKeyPool instance.

interface ApiKeyPoolConfig {
    cooldownMs?: number;
    primaryWeight?: number;
    strategy?: "round-robin" | "ordered";
    recheckMs?: number;
    maxRecheckMs?: number;
    maxRetryAfterMs?: number;
    probeTimeoutMs?: number;
    loadTimeoutMs?: number;
    storeTimeoutMs?: number;
    probe?: ((key, kind) => Promise<KeyProbeResult>);
    store?: KeyPoolStateStore;
    id?: string;
    logger?: ILogger;
}

Properties

cooldownMs?: number

Cooldown before retrying a quota-exhausted key, a positive number of milliseconds. Default: 15 minutes.

primaryWeight?: number

Weight multiplier for the first key under round-robin, a positive whole number. Default: 2. Set to 1 for equal weighting.

strategy?: "round-robin" | "ordered"

round-robin (default, the first version's behaviour) or ordered (the earliest usable key in the configured order).

recheckMs?: number

The first recheck delay of a key failed for auth or billing; doubles on each failed return. Default: 30 minutes.

maxRecheckMs?: number

The recheck delay's ceiling. Default: 6 hours.

maxRetryAfterMs?: number

The longest rest a Retry-After may ask for, a positive number of milliseconds. Default: 1 hour.

probeTimeoutMs?: number

How long a probe may run before it counts as unknown. Default: 10 seconds.

loadTimeoutMs?: number

How long ready() waits for the store's load before it carries on with a fresh state. Default: 10 seconds.

storeTimeoutMs?: number

How long flush() and close() wait for the store's writes. Default: 5 seconds.

probe?: ((key, kind) => Promise<KeyProbeResult>)

Probes a failed key off the request path, told the kind of its last failure; without one, failed keys return by time.

Type declaration

Persists the pool's state; used only with id.

id?: string

The pool's identity for its store and its log lines.

logger?: ILogger

The logger the pool writes its state changes to. Default: the library's key-pool logger.