Documentation
¶
Overview ¶
Package keymanager provides API key management with load balancing and failover capabilities. It includes health tracking, circuit breakers, and intelligent key rotation for AI providers.
Index ¶
- type KeyManager
- func (m *KeyManager) ExecuteWithFailover(ctx context.Context, ...) (string, *types.Usage, error)
- func (m *KeyManager) ExecuteWithFailoverMessage(ctx context.Context, ...) (types.ChatMessage, *types.Usage, error)
- func (m *KeyManager) GetKeys() []string
- func (m *KeyManager) GetNextKey() (string, error)
- func (m *KeyManager) ReportFailure(key string, err error)
- func (m *KeyManager) ReportSuccess(key string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyManager ¶
type KeyManager struct {
// contains filtered or unexported fields
}
KeyManager manages multiple API keys with load balancing and failover
func NewKeyManager ¶
func NewKeyManager(providerName string, keys []string) *KeyManager
NewKeyManager creates a new multi-key manager
func (*KeyManager) ExecuteWithFailover ¶
func (m *KeyManager) ExecuteWithFailover(ctx context.Context, operation func(context.Context, string) (string, *types.Usage, error)) (string, *types.Usage, error)
ExecuteWithFailover attempts an operation with automatic failover to next key on failure
func (*KeyManager) ExecuteWithFailoverMessage ¶ added in v1.0.11
func (m *KeyManager) ExecuteWithFailoverMessage(ctx context.Context, operation func(context.Context, string) (types.ChatMessage, *types.Usage, error)) (types.ChatMessage, *types.Usage, error)
ExecuteWithFailoverMessage attempts an operation with automatic failover (message variant)
func (*KeyManager) GetKeys ¶
func (m *KeyManager) GetKeys() []string
GetKeys returns a copy of the keys slice
func (*KeyManager) GetNextKey ¶
func (m *KeyManager) GetNextKey() (string, error)
GetNextKey returns the next available API key using round-robin load balancing
func (*KeyManager) ReportFailure ¶
func (m *KeyManager) ReportFailure(key string, err error)
ReportFailure reports that an API call failed with this key
func (*KeyManager) ReportSuccess ¶
func (m *KeyManager) ReportSuccess(key string)
ReportSuccess reports that an API call succeeded with this key