HasteKit supports managing multiple API keys for a single provider. This is useful for:Documentation Index
Fetch the complete documentation index at: https://hastekit.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
- Load Balancing: Distribute requests across multiple API keys to avoid rate limits.
- Redundancy: Ensure high availability by having fallback keys.
- Cost Management: Allocate traffic based on usage quotas or costs associated with different keys.
Weighted Random Selection
When multiple API keys with weights are configured for a provider, HasteKit uses weighted random selection to choose which key to use for each request. Each API key must be assigned aWeight. The probability of a key being selected is proportional to its weight relative to the sum of all weights for that provider.
How it Works
- HasteKit retrieves all enabled API keys for the requested provider.
- It extracts the
Weightfrom eachAPIKeyConfig. - If multiple keys exist, it performs a weighted random selection.
- The request is then executed using the selected API key.
1 or not specified), the selection becomes uniformly random.
Configuration Example
When using the HasteKit SDK in direct mode, you can configure multiple keys using theInMemoryConfigStore.