Skip to content

Interface: KeyStrategy

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / KeyStrategy

Defined in: src/types/provider.ts:33

API key strategy interface for managing multiple keys.

Implement this interface to provide custom key rotation or selection logic when working with multiple API keys.

// Built-in key strategies
const keys = roundRobinKeys(['sk-key-1', 'sk-key-2']);
// Custom implementation
const custom: KeyStrategy = {
getKey(): string {
return pickKeyFromPool();
}
};

getKey(): string | Promise<string>

Defined in: src/types/provider.ts:39

Gets the next API key to use for a request.

string | Promise<string>

The API key string, or a Promise resolving to it