Versions in this module Expand all Collapse all v0 v0.1.0 Jul 25, 2026 Changes in this version + type Attempt struct + Duration time.Duration + ErrorCode ErrorCode + ErrorKind ErrorKind + Number int + Provider string + StartedAt time.Time + Success bool + type BackoffPolicy interface + Delay func(retryNumber int) time.Duration + type CandidateScorer interface + Score func(candidate ProviderState) float64 + func ByCost() CandidateScorer + func ByObservedLatency() CandidateScorer + type Codec interface + Decode func(ctx context.Context, response HTTPResponse) (ResponsePayload, error) + Encode func(ctx context.Context, request Request[RequestPayload]) (HTTPRequest, error) + Supports func(operation Operation) bool + type ErrorCode string + const CodeAdapterError + const CodeInvalidBaseURL + const CodeNetworkTimeout + const CodeNilCodec + const CodeNilGateway + const CodeOperationRequired + const CodeOperationUnsupported + const CodeProviderHintUnknown + const CodeProviderHintUnsupported + const CodeRequestCanceled + const CodeRequestTimeout + const CodeResponseReadFailed + const CodeResponseTooLarge + const CodeRetryLoopExhausted + const CodeRoutingFailed + const CodeRoutingUnknownProvider + const CodeTransportError + type ErrorKind string + const ErrorAuthentication + const ErrorAuthorization + const ErrorCanceled + const ErrorInternal + const ErrorRateLimited + const ErrorRejected + const ErrorTimeout + const ErrorUnavailable + const ErrorUnknown + const ErrorValidation + type ExponentialBackoff struct + Initial time.Duration + Jitter float64 + Maximum time.Duration + func (b ExponentialBackoff) Delay(retryNumber int) time.Duration + type FallbackPolicy interface + Allows func(err *GatewayError) bool + func FallbackOn(kinds ...ErrorKind) FallbackPolicy + type Gateway struct + func New[RequestPayload any, ResponsePayload any](options ...Option) (*Gateway[RequestPayload, ResponsePayload], error) + func (g *Gateway[RequestPayload, ResponsePayload]) HandleRequest(ctx context.Context, request Request[RequestPayload]) (Result[ResponsePayload], error) + type GatewayError struct + Attempt int + Cause error + Code ErrorCode + Fallbackable bool + Kind ErrorKind + Message string + Operation Operation + Provider string + Retryable bool + StatusCode int + func AsError(err error) (*GatewayError, bool) + func HTTPProviderError(statusCode int, code ErrorCode, message string) *GatewayError + func (e *GatewayError) Error() string + func (e *GatewayError) Unwrap() error + type HTTPProviderConfig struct + BaseURL string + Client *http.Client + Headers http.Header + MaxResponseBytes int64 + Timeout time.Duration + type HTTPRequest struct + Body []byte + Headers http.Header + Method string + Path string + Query url.Values + type HTTPResponse struct + Body []byte + Headers http.Header + StatusCode int + type Operation string + type Option interface + func WithFallback(policy FallbackPolicy) Option + func WithLogger(logger *slog.Logger) Option + func WithProviders[RequestPayload any, ResponsePayload any](providers ...ProviderRegistration[RequestPayload, ResponsePayload]) Option + func WithRequestTimeout(timeout time.Duration) Option + func WithRetry(retry Retry) Option + func WithRouting(strategy RoutingStrategy) Option + type Provider interface + Execute func(ctx context.Context, request Request[RequestPayload]) (ResponsePayload, error) + Name func() string + Supports func(operation Operation) bool + func NewHTTPProvider[RequestPayload any, ResponsePayload any](name string, config HTTPProviderConfig, ...) Provider[RequestPayload, ResponsePayload] + type ProviderOption interface + func WithProviderCost(cost float64) ProviderOption + func WithProviderMetadata(metadata map[string]string) ProviderOption + func WithProviderPriority(priority int) ProviderOption + func WithProviderWeight(weight int) ProviderOption + type ProviderRegistration struct + func UseProvider[RequestPayload any, ResponsePayload any](provider Provider[RequestPayload, ResponsePayload], options ...ProviderOption) ProviderRegistration[RequestPayload, ResponsePayload] + type ProviderState struct + Cost float64 + Healthy bool + Metadata map[string]string + Name string + ObservedLatency time.Duration + Priority int + Weight int + type Request struct + ID string + IdempotencyKey string + Metadata map[string]string + Operation Operation + Payload T + ProviderHint string + type Result struct + Attempts []Attempt + Payload T + Provider string + RequestID string + Usage Usage + type Retry struct + Backoff BackoffPolicy + MaxAttempts int + type RoutingStrategy interface + Name func() string + Select func(ctx context.Context, candidates []ProviderState) (ProviderState, error) + func LowestCost() RoutingStrategy + func PowerOfTwo(scorer CandidateScorer) RoutingStrategy + func Priority(providerNames ...string) RoutingStrategy + func RoundRobin() RoutingStrategy + func Weighted(weights map[string]int) RoutingStrategy + type Usage struct + Cost float64 + Currency string + InputUnits int64 + OutputUnits int64