Smart Key Distribution
Bifrost’s key management system goes beyond simple API key storage. It provides intelligent load balancing, model-specific key filtering, and weighted distribution to optimize performance and manage costs across multiple API keys. When you configure multiple keys for a provider, Bifrost automatically distributes requests using sophisticated selection algorithms that consider key weights, model compatibility, and deployment mappings.How Key Selection Works
Bifrost follows a precise selection process for every request:- Context Override Check: First checks if a key is explicitly provided in context (bypassing management)
- Provider Key Lookup: Retrieves all configured keys for the requested provider
- Model Filtering: Filters keys that support the requested model
- Deployment Validation: For Azure/Bedrock, validates deployment mappings
- Weighted Selection: Uses weighted random selection among eligible keys
Implementation Examples
- Gateway
- Go SDK
Weighted Load Balancing
Bifrost uses weighted random selection to distribute requests across multiple keys. This allows you to: Control Traffic Distribution:- Assign higher weights to premium keys with better rate limits
- Balance between production and backup keys
- Gradually migrate traffic during key rotation
- Calculate total weight of all eligible keys
- Generate random number between 0 and total weight
- Select key based on cumulative weight ranges
- If selected key fails, automatic fallback to next available key
Model Whitelisting and Filtering
Keys can be restricted to specific models for access control and cost management: Model Filtering Logic:- Empty
modelsarray: Key supports ALL models for that provider - Populated
modelsarray: Key only supports listed models - Model mismatch: Key is excluded from selection for that request
- Premium Models: Dedicated keys for expensive models (GPT-4, Claude-3)
- Team Separation: Different keys for different teams or projects
- Cost Control: Restrict access to specific model tiers
- Compliance: Separate keys for different security requirements
Deployment Mapping (Azure & Bedrock)
For cloud providers with deployment-based routing, Bifrost validates deployment availability: Azure OpenAI:- Keys must have deployment mappings for specific models
- Deployment name maps to actual Azure deployment identifier
- Missing deployment excludes key from selection
- Supports model profiles and direct model access
- Deployment mappings enable inference profile routing
- ARN configuration determines URL formation
- Check if provider uses deployments (Azure/Bedrock)
- Verify deployment exists for requested model
- Exclude keys without proper deployment mapping
- Continue with standard weighted selection
Direct Key Bypass
For scenarios requiring explicit key control, Bifrost supports bypassing the entire key management system: Go SDK Context Override: Pass a key directly in the request context usingschemas.BifrostContextKeyDirectKey. This completely bypasses provider key lookup and selection.
Gateway Header-based Keys:
Send API keys in Authorization (Bearer), x-api-key or x-goog-api-key headers. Requires allow_direct_keys setting to be enabled.
Enable Direct Keys:
- Web UI
- config.json

- Navigate to Configuration page
- Toggle “Allow Direct Keys” to enabled
- Save configuration
If a Bifrost virtual key (
sk-bf-*) is attached in the auth header, direct key bypass will be skipped.- Per-user API key scenarios
- External key management systems
- Testing with specific keys
- Debugging key-related issues

