Documentation
¶
Index ¶
- Constants
- Variables
- type AuthenticationError
- type BaseError
- type ContentFilterError
- type ContextLengthError
- type InsufficientFundsError
- type InvalidRequestError
- type MissingAPIKeyError
- type ModelNotFoundError
- type ProviderError
- type RateLimitError
- type UnsupportedOperationError
- type UnsupportedParamError
- type UnsupportedProviderError
Constants ¶
const ( CODE_RATE_LIMIT = "rate_limit" CODE_AUTH_ERROR = "auth_error" CODE_INVALID_REQUEST = "invalid_request" CODE_CONTEXT_LENGTH = "context_length_exceeded" CODE_CONTENT_FILTER = "content_filter" CODE_MODEL_NOT_FOUND = "model_not_found" CODE_PROVIDER_ERROR = "provider_error" CODE_MISSING_API_KEY = "missing_api_key" CODE_UNSUPPORTED_PROVIDER = "unsupported_provider" CODE_UNSUPPORTED_PARAM = "unsupported_parameter" CODE_INSUFFICIENT_FUNDS = "insufficient_funds" CODE_UNSUPPORTED = "unsupported" )
Error codes used in BaseError.Code field.
Variables ¶
var ( ErrRateLimit = stderrors.New("rate limit exceeded") ErrAuthentication = stderrors.New("authentication failed") ErrInvalidRequest = stderrors.New("invalid request") ErrContextLength = stderrors.New("context length exceeded") ErrContentFilter = stderrors.New("content filtered") ErrModelNotFound = stderrors.New("model not found") ErrProvider = stderrors.New("provider error") ErrMissingAPIKey = stderrors.New("missing API key") ErrUnsupportedProvider = stderrors.New("unsupported provider") ErrUnsupportedParam = stderrors.New("unsupported parameter") ErrInsufficientFunds = stderrors.New("insufficient funds") ErrUnsupported = stderrors.New("operation not supported by provider") )
Sentinel errors for type checking with errors.Is().
Functions ¶
This section is empty.
Types ¶
type AuthenticationError ¶
type AuthenticationError struct {
BaseError
}
AuthenticationError is returned when authentication fails.
func NewAuthenticationError ¶
func NewAuthenticationError(provider string, err error) *AuthenticationError
NewAuthenticationError creates a new AuthenticationError.
type BaseError ¶
type BaseError struct {
// Code is a short error code (e.g., "rate_limit", "auth_error").
Code string
// Provider is the name of the provider that returned the error.
Provider string
// Err is the underlying error (original provider error).
Err error
// contains filtered or unexported fields
}
BaseError is the base error type for all llm errors. It wraps the original error and includes provider context.
func New ¶
New constructs a BaseError for embedding in a caller-defined error type. It exists so packages outside this one can populate the unexported sentinel field that drives errors.Is matching; without it, external packages could only set the exported fields via struct literals and errors.Is(err, ErrFoo) would never match.
Typical usage from a provider package:
type UpstreamProviderError struct{ errors.BaseError }
func NewUpstreamProviderError(provider string, err error) *UpstreamProviderError {
return &UpstreamProviderError{
BaseError: errors.New("upstream_provider", provider, err, ErrUpstreamProvider),
}
}
type ContentFilterError ¶
type ContentFilterError struct {
BaseError
}
ContentFilterError is returned when content is blocked by safety filters.
func NewContentFilterError ¶
func NewContentFilterError(provider string, err error) *ContentFilterError
NewContentFilterError creates a new ContentFilterError.
type ContextLengthError ¶
type ContextLengthError struct {
BaseError
}
ContextLengthError is returned when the context exceeds the model's limit.
func NewContextLengthError ¶
func NewContextLengthError(provider string, err error) *ContextLengthError
NewContextLengthError creates a new ContextLengthError.
type InsufficientFundsError ¶
type InsufficientFundsError struct {
BaseError
}
InsufficientFundsError is returned when the account has insufficient funds (HTTP 402).
func NewInsufficientFundsError ¶
func NewInsufficientFundsError(provider string, err error) *InsufficientFundsError
NewInsufficientFundsError creates a new InsufficientFundsError.
type InvalidRequestError ¶
type InvalidRequestError struct {
BaseError
}
InvalidRequestError is returned when the request is malformed.
func NewInvalidRequestError ¶
func NewInvalidRequestError(provider string, err error) *InvalidRequestError
NewInvalidRequestError creates a new InvalidRequestError.
type MissingAPIKeyError ¶
type MissingAPIKeyError struct {
BaseError
EnvVar string // The environment variable that should contain the key
}
MissingAPIKeyError is returned when no API key is provided.
func NewMissingAPIKeyError ¶
func NewMissingAPIKeyError(provider string, envVar string) *MissingAPIKeyError
NewMissingAPIKeyError creates a new MissingAPIKeyError.
type ModelNotFoundError ¶
type ModelNotFoundError struct {
BaseError
}
ModelNotFoundError is returned when the requested model doesn't exist.
func NewModelNotFoundError ¶
func NewModelNotFoundError(provider string, err error) *ModelNotFoundError
NewModelNotFoundError creates a new ModelNotFoundError.
type ProviderError ¶
ProviderError is returned for general provider-side errors.
func NewProviderError ¶
func NewProviderError(provider string, err error) *ProviderError
NewProviderError creates a new ProviderError.
type RateLimitError ¶
RateLimitError is returned when the API rate limit is exceeded.
func NewRateLimitError ¶
func NewRateLimitError(provider string, err error) *RateLimitError
NewRateLimitError creates a new RateLimitError.
type UnsupportedOperationError ¶
type UnsupportedOperationError struct {
BaseError
// Operation names the unsupported capability (e.g. "moderation",
// "multimodal_moderation").
Operation string
}
UnsupportedOperationError indicates a provider does not support a given operation (e.g. moderation). Use errors.As to detect:
var unsup *errors.UnsupportedOperationError
if errors.As(err, &unsup) {
// unsup.Operation, unsup.Provider ...
}
Also matches errors.Is(err, ErrUnsupported).
func NewUnsupportedOperationError ¶
func NewUnsupportedOperationError(provider, operation string, err error) *UnsupportedOperationError
NewUnsupportedOperationError creates a new UnsupportedOperationError for the given provider and operation (e.g. "moderation").
type UnsupportedParamError ¶
UnsupportedParamError is returned when a parameter is not supported.
func NewUnsupportedParamError ¶
func NewUnsupportedParamError(provider string, param string) *UnsupportedParamError
NewUnsupportedParamError creates a new UnsupportedParamError.
type UnsupportedProviderError ¶
type UnsupportedProviderError struct {
BaseError
}
UnsupportedProviderError is returned when the provider is not supported.
func NewUnsupportedProviderError ¶
func NewUnsupportedProviderError(provider string) *UnsupportedProviderError
NewUnsupportedProviderError creates a new UnsupportedProviderError.