Function: roundRobinKeys()
@providerprotocol/ai / @providerprotocol/ai / roundRobinKeys
Function: roundRobinKeys()
Section titled “Function: roundRobinKeys()”roundRobinKeys(
keys):KeyStrategy
Defined in: src/http/keys.ts:38
Creates a key strategy that distributes API requests across multiple keys using round-robin selection.
Each call to getKey() returns the next key in sequence, cycling back to
the first key after reaching the end. This provides even distribution of requests
across all available keys, which is useful for:
- Spreading rate limits across multiple API keys
- Load balancing between different accounts
- Maximizing throughput when multiple keys are available
Parameters
Section titled “Parameters”string[]
Array of API keys to rotate through
Returns
Section titled “Returns”A KeyStrategy that cycles through the provided keys
Throws
Section titled “Throws”When the keys array is empty
Example
Section titled “Example”const keys = roundRobinKeys([ 'sk-key-1', 'sk-key-2', 'sk-key-3']);
keys.getKey(); // Returns 'sk-key-1'keys.getKey(); // Returns 'sk-key-2'keys.getKey(); // Returns 'sk-key-3'keys.getKey(); // Returns 'sk-key-1' (cycles back)