keymanager

package
v1.0.29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2025 License: MIT Imports: 6 Imported by: 0

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL