Skip to content

KeyPool

Defined in: core/src/key-pool.ts:83

new KeyPool(label, opts): KeyPool;

Defined in: core/src/key-pool.ts:91

Parameter Type
label string
opts KeyPoolOptions

KeyPool

get size(): number;

Defined in: core/src/key-pool.ts:106

number

status(): object[];

Defined in: core/src/key-pool.ts:113

Each key’s tier and when it is back (0 = serving now): free keys in config order, then the paid one. Never the key itself, so a status page can show it as is.

object[]


with<T>(fn, opts?): Promise<T>;

Defined in: core/src/key-pool.ts:133

Run fn with the next available key, rotating on key-specific and transient failures. Everything else (a bad request, a content block) throws straight through: it would fail identically on every key, and spending the pool on it only turns one bad request into an outage.

Set maxAttempts: 1 for a paid request that must not be sent again. Only actual callback invocations count, not keys skipped during cooldown. At the cap the key is still benched as usual, but its original error is thrown instead of trying another key. This does not limit retries inside fn or in a wrapper around with.

Type Parameter
T
Parameter Type
fn (apiKey, tier) => Promise<T>
opts KeyPoolCallOptions

Promise<T>