Versions in this module Expand all Collapse all v0 v0.14.0 Mar 16, 2026 Changes in this version + const EnvVarGLMAPIKey + const EnvVarKimiAPIKey + const EnvVarQwenAPIKey + const ModelGLM4_5 + const ModelGLM4_5Flash + const ModelGLM4_7 + const ModelGLM4_7Flash + const ModelGLM4_7FlashX + const ModelGLM5 + const ModelKimiK2Thinking + const ModelKimiK2Turbo + const ModelKimiK2_5 + const ModelMoonshotV1_128K + const ModelMoonshotV1_32K + const ModelMoonshotV1_8K + const ModelQwQ32B + const ModelQwen2_5_72B + const ModelQwen3Max + const ModelQwen3_235B + const ModelQwen3_32B + const ModelQwenFlash + const ModelQwenMax + const ModelQwenPlus type ProviderName + const ProviderNameGLM + const ProviderNameKimi + const ProviderNameQwen v0.13.0 Feb 28, 2026 Changes in this version + const EnvVarAnthropicAPIKey + const EnvVarGeminiAPIKey + const EnvVarOpenAIAPIKey + const EnvVarXAIAPIKey + const ModelBedrockClaude3Opus + const ModelBedrockClaude3Sonnet + const ModelBedrockClaudeOpus4 + const ModelBedrockTitan + const ModelClaude3Haiku + const ModelClaude3Opus + const ModelClaude3Sonnet + const ModelClaude3_5Haiku + const ModelClaude3_7Sonnet + const ModelClaudeOpus4 + const ModelClaudeOpus4_1 + const ModelClaudeSonnet4 + const ModelGPT35Turbo + const ModelGPT4Turbo + const ModelGPT4_1 + const ModelGPT4_1Mini + const ModelGPT4_1Nano + const ModelGPT4o + const ModelGPT4oMini + const ModelGPT5 + const ModelGPT5ChatLatest + const ModelGPT5Mini + const ModelGPT5Nano + const ModelGemini1_5Flash + const ModelGemini1_5Pro + const ModelGemini2_5Flash + const ModelGemini2_5Pro + const ModelGeminiLive2_5Flash + const ModelGeminiPro + const ModelGrok2_1212 + const ModelGrok2_Vision + const ModelGrok3 + const ModelGrok3Mini + const ModelGrok4FastNonReasoning + const ModelGrok4FastReasoning + const ModelGrok4_0709 + const ModelGrok4_1FastNonReasoning + const ModelGrok4_1FastReasoning + const ModelGrokBeta + const ModelGrokCodeFast1 + const ModelGrokVision + const ModelOllamaCodeLlama + const ModelOllamaDeepSeek + const ModelOllamaGemma2B + const ModelOllamaGemma7B + const ModelOllamaLlama3_70B + const ModelOllamaLlama3_8B + const ModelOllamaMistral7B + const ModelOllamaMixtral8x7B + const ModelOllamaQwen2_5 + const ModelVertexClaudeOpus4 + const RoleAssistant + const RoleSystem + const RoleTool + const RoleUser + var ErrBedrockExternal = errors.New(...) + var ErrEmptyAPIKey = errors.New("API key cannot be empty") + var ErrEmptyMessages = errors.New("messages cannot be empty") + var ErrEmptyModel = errors.New("model cannot be empty") + var ErrInvalidConfiguration = errors.New("invalid configuration") + var ErrInvalidRequest = errors.New("invalid request") + var ErrInvalidResponse = errors.New("invalid response format") + var ErrModelNotFound = errors.New("model not found") + var ErrNetworkError = errors.New("network error") + var ErrNoProviders = errors.New("at least one provider must be configured") + var ErrQuotaExceeded = errors.New("quota exceeded") + var ErrRateLimitExceeded = errors.New("rate limit exceeded") + var ErrServerError = errors.New("server error") + var ErrStreamClosed = errors.New("stream is closed") + var ErrUnsupportedProvider = errors.New("unsupported provider") + func EstimatePromptTokens(model string, messages []provider.Message) (int, error) + func GetModelContextWindow(model string) int + func IsNonRetryableError(err error) bool + func IsRetryableError(err error) bool + type APIError struct + Code string + Message string + Provider ProviderName + StatusCode int + Type string + func NewAPIError(provider ProviderName, statusCode int, message, errorType, code string) *APIError + func (e *APIError) Error() string + type CacheConfig struct + CacheableModels []string + ExcludeParameters []string + IncludeSeed bool + IncludeTemperature bool + KeyPrefix string + SkipStreaming bool + TTL time.Duration + func DefaultCacheConfig() CacheConfig + type CacheEntry struct + CachedAt time.Time + ExpiresAt time.Time + Model string + RequestHash string + Response *provider.ChatCompletionResponse + func (e *CacheEntry) IsExpired() bool + type CacheHitError struct + Entry *CacheEntry + func (e *CacheHitError) Error() string + type CacheManager struct + func NewCacheManager(kvsClient kvs.Client, config CacheConfig) *CacheManager + func (m *CacheManager) BuildCacheKey(req *provider.ChatCompletionRequest) string + func (m *CacheManager) Config() CacheConfig + func (m *CacheManager) Delete(ctx context.Context, req *provider.ChatCompletionRequest) error + func (m *CacheManager) Get(ctx context.Context, req *provider.ChatCompletionRequest) (*CacheEntry, error) + func (m *CacheManager) Set(ctx context.Context, req *provider.ChatCompletionRequest, ...) error + func (m *CacheManager) ShouldCache(req *provider.ChatCompletionRequest) bool + type CacheStats struct + Hits int64 + Misses int64 + type ChatClient struct + func NewClient(config ClientConfig) (*ChatClient, error) + func (c *ChatClient) AppendMessage(ctx context.Context, sessionID string, message provider.Message) error + func (c *ChatClient) Cache() *CacheManager + func (c *ChatClient) Close() error + func (c *ChatClient) CreateChatCompletion(ctx context.Context, req *provider.ChatCompletionRequest) (*provider.ChatCompletionResponse, error) + func (c *ChatClient) CreateChatCompletionStream(ctx context.Context, req *provider.ChatCompletionRequest) (provider.ChatCompletionStream, error) + func (c *ChatClient) CreateChatCompletionStreamWithMemory(ctx context.Context, sessionID string, req *provider.ChatCompletionRequest) (provider.ChatCompletionStream, error) + func (c *ChatClient) CreateChatCompletionWithMemory(ctx context.Context, sessionID string, req *provider.ChatCompletionRequest) (*provider.ChatCompletionResponse, error) + func (c *ChatClient) CreateConversationWithSystemMessage(ctx context.Context, sessionID, systemMessage string) error + func (c *ChatClient) DeleteConversation(ctx context.Context, sessionID string) error + func (c *ChatClient) GetConversationMessages(ctx context.Context, sessionID string) ([]provider.Message, error) + func (c *ChatClient) HasCache() bool + func (c *ChatClient) HasMemory() bool + func (c *ChatClient) LoadConversation(ctx context.Context, sessionID string) (*ConversationMemory, error) + func (c *ChatClient) Logger() *slog.Logger + func (c *ChatClient) Memory() *MemoryManager + func (c *ChatClient) Provider() provider.Provider + func (c *ChatClient) SaveConversation(ctx context.Context, conversation *ConversationMemory) error + func (c *ChatClient) TokenEstimator() TokenEstimator + type ChatCompletionChoice = provider.ChatCompletionChoice + type ChatCompletionChunk = provider.ChatCompletionChunk + type ChatCompletionRequest = provider.ChatCompletionRequest + type ChatCompletionResponse = provider.ChatCompletionResponse + type ChatCompletionStream = provider.ChatCompletionStream + type CircuitBreaker struct + func NewCircuitBreaker(config CircuitBreakerConfig) *CircuitBreaker + func (cb *CircuitBreaker) AllowRequest() bool + func (cb *CircuitBreaker) RecordFailure() + func (cb *CircuitBreaker) RecordSuccess() + func (cb *CircuitBreaker) Reset() + func (cb *CircuitBreaker) State() CircuitState + func (cb *CircuitBreaker) Stats() CircuitBreakerStats + type CircuitBreakerConfig struct + FailureRateThreshold float64 + FailureThreshold int + MinimumRequests int + SuccessThreshold int + Timeout time.Duration + func DefaultCircuitBreakerConfig() CircuitBreakerConfig + type CircuitBreakerStats struct + ConsecutiveFailures int + ConsecutiveSuccesses int + FailureRate float64 + LastFailure time.Time + LastStateChange time.Time + State CircuitState + TotalFailures int + TotalRequests int + type CircuitOpenError struct + LastFailure time.Time + Provider string + RetryAfter time.Duration + State CircuitState + func (e *CircuitOpenError) Error() string + type CircuitState int + const CircuitClosed + const CircuitHalfOpen + const CircuitOpen + func (s CircuitState) String() string + type ClientConfig struct + Cache kvs.Client + CacheConfig *CacheConfig + CircuitBreakerConfig *CircuitBreakerConfig + Logger *slog.Logger + Memory kvs.Client + MemoryConfig *MemoryConfig + ObservabilityHook ObservabilityHook + Providers []ProviderConfig + TokenEstimator TokenEstimator + ValidateTokens bool + type ConversationMemory struct + CreatedAt time.Time + Messages []Message + Metadata map[string]any + SessionID string + UpdatedAt time.Time + type ErrorCategory int + const ErrorCategoryNonRetryable + const ErrorCategoryRetryable + const ErrorCategoryUnknown + func ClassifyError(err error) ErrorCategory + func (c ErrorCategory) String() string + type FallbackAttempt struct + Duration time.Duration + Error error + Provider string + Skipped bool + type FallbackError struct + Attempts []FallbackAttempt + LastError error + func (e *FallbackError) Error() string + func (e *FallbackError) Unwrap() error + type FallbackProvider struct + func NewFallbackProvider(primary provider.Provider, fallbacks []provider.Provider, ...) *FallbackProvider + func (fp *FallbackProvider) CircuitBreaker(providerName string) *CircuitBreaker + func (fp *FallbackProvider) Close() error + func (fp *FallbackProvider) CreateChatCompletion(ctx context.Context, req *provider.ChatCompletionRequest) (*provider.ChatCompletionResponse, error) + func (fp *FallbackProvider) CreateChatCompletionStream(ctx context.Context, req *provider.ChatCompletionRequest) (provider.ChatCompletionStream, error) + func (fp *FallbackProvider) FallbackProviders() []provider.Provider + func (fp *FallbackProvider) Name() string + func (fp *FallbackProvider) PrimaryProvider() provider.Provider + type FallbackProviderConfig struct + CircuitBreakerConfig *CircuitBreakerConfig + Logger *slog.Logger + type LLMCallInfo struct + CallID string + ProviderName string + StartTime time.Time + type MemoryConfig struct + KeyPrefix string + MaxMessages int + TTL time.Duration + func DefaultMemoryConfig() MemoryConfig + type MemoryManager struct + func NewMemoryManager(kvsClient kvs.Client, config MemoryConfig) *MemoryManager + func (m *MemoryManager) AppendMessage(ctx context.Context, sessionID string, message Message) error + func (m *MemoryManager) AppendMessages(ctx context.Context, sessionID string, messages []Message) error + func (m *MemoryManager) CreateConversationWithSystemMessage(ctx context.Context, sessionID, systemMessage string) error + func (m *MemoryManager) DeleteConversation(ctx context.Context, sessionID string) error + func (m *MemoryManager) GetMessages(ctx context.Context, sessionID string) ([]Message, error) + func (m *MemoryManager) LoadConversation(ctx context.Context, sessionID string) (*ConversationMemory, error) + func (m *MemoryManager) SaveConversation(ctx context.Context, conversation *ConversationMemory) error + func (m *MemoryManager) SetMetadata(ctx context.Context, sessionID string, metadata map[string]any) error + type Message = provider.Message + type ModelInfo struct + ID string + MaxTokens int + Name string + Provider ProviderName + func GetModelInfo(modelID string) *ModelInfo + type ObservabilityHook interface + AfterResponse func(ctx context.Context, info LLMCallInfo, req *provider.ChatCompletionRequest, ...) + BeforeRequest func(ctx context.Context, info LLMCallInfo, req *provider.ChatCompletionRequest) context.Context + WrapStream func(ctx context.Context, info LLMCallInfo, req *provider.ChatCompletionRequest, ...) provider.ChatCompletionStream + type Provider = provider.Provider + type ProviderConfig struct + APIKey string + BaseURL string + CustomProvider provider.Provider + Extra map[string]any + HTTPClient *http.Client + Provider ProviderName + Region string + Timeout time.Duration + type ProviderName string + const ProviderNameAnthropic + const ProviderNameBedrock + const ProviderNameGemini + const ProviderNameOllama + const ProviderNameOpenAI + const ProviderNameXAI + type Role = provider.Role + type TokenEstimator interface + EstimateTokens func(model string, messages []provider.Message) (int, error) + GetContextWindow func(model string) int + func NewTokenEstimator(config TokenEstimatorConfig) TokenEstimator + type TokenEstimatorConfig struct + CharactersPerToken float64 + CustomContextWindows map[string]int + TokenOverheadPerMessage int + func DefaultTokenEstimatorConfig() TokenEstimatorConfig + type TokenLimitError struct + AvailableTokens int + ContextWindow int + EstimatedTokens int + Model string + func (e *TokenLimitError) Error() string + type TokenValidation struct + AvailableTokens int + ContextWindow int + EstimatedTokens int + ExceedsLimit bool + ExceedsWithCompletion bool + MaxCompletionTokens int + func ValidateTokens(estimator TokenEstimator, model string, messages []provider.Message, ...) (*TokenValidation, error) + type Tool = provider.Tool + type ToolCall = provider.ToolCall + type ToolFunction = provider.ToolFunction + type ToolSpec = provider.ToolSpec + type Usage = provider.Usage