Documentation
¶
Index ¶
- func CalculateHTTPBackoff(config types.RetryConfig, attempt int) time.Duration
- func Is529Error(resp *http.Response, err error) bool
- func IsModelDeprecatedError(err error, resp *http.Response) bool
- func IsQuotaExhaustedError(err error, resp *http.Response) bool
- func IsRateLimitError(resp *http.Response) bool
- func IsRegionallyUnavailableError(err error, resp *http.Response) bool
- func IsRetryableStatus(statusCode int) bool
- func ParseContextOverflowError(err error) (inputTokens, maxTokens, contextLimit int, ok bool)
- func ParseRetryAfterHeader(resp *http.Response) time.Duration
- func RecoveryHint(classification RetryClassification, modelID string) string
- func RetryHTTP(ctx context.Context, config types.RetryConfig, send HTTPRequestFunc, ...) (*http.Response, error)
- func RetryWithStrategy(ctx context.Context, strategy *RetryStrategy, model types.ModelIdentifier, ...) (*types.APIResponse, error)
- func ShouldRetryHTTP(config types.RetryConfig, classification RetryClassification, attempt int) bool
- type CircuitOpenChecker
- type HTTPRequestFunc
- type HTTPResponseErrorFunc
- type RequestFunc
- type RetryClassification
- type RetryState
- type RetryStrategy
- type RetryableResponseInspector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateHTTPBackoff ¶
func CalculateHTTPBackoff(config types.RetryConfig, attempt int) time.Duration
func IsModelDeprecatedError ¶
IsModelDeprecatedError returns true when the provider signals that the requested model is no longer available (retired, renamed, or removed).
func IsRateLimitError ¶
func IsRegionallyUnavailableError ¶
IsRegionallyUnavailableError returns true when the service is reachable but not available in the current region or endpoint configuration.
func IsRetryableStatus ¶
func RecoveryHint ¶
func RecoveryHint(classification RetryClassification, modelID string) string
RecoveryHint returns a human-readable suggestion for the operator based on the classification. Returns empty string for classifications that have no actionable hint beyond retrying.
func RetryHTTP ¶
func RetryHTTP( ctx context.Context, config types.RetryConfig, send HTTPRequestFunc, buildResponseError HTTPResponseErrorFunc, isCircuitOpen CircuitOpenChecker, ) (*http.Response, error)
func RetryWithStrategy ¶
func RetryWithStrategy( ctx context.Context, strategy *RetryStrategy, model types.ModelIdentifier, maxTokens int, fn RequestFunc, ) (*types.APIResponse, error)
func ShouldRetryHTTP ¶
func ShouldRetryHTTP(config types.RetryConfig, classification RetryClassification, attempt int) bool
Types ¶
type CircuitOpenChecker ¶
CircuitOpenChecker reports whether an error comes from an open circuit breaker.
type HTTPRequestFunc ¶
HTTPRequestFunc is the HTTP-level request function executed under retry control.
type HTTPResponseErrorFunc ¶
HTTPResponseErrorFunc translates a non-2xx HTTP response into an error. Implementations may consume and restore the response body as needed.
type RequestFunc ¶
type RequestFunc func(ctx context.Context, attempt int, maxTokens int, model types.ModelIdentifier) (*types.APIResponse, error)
RequestFunc is the function executed under advanced retry control.
type RetryClassification ¶
type RetryClassification string
RetryClassification represents the type of error for retry logic.
const ( RetryClassificationNetwork RetryClassification = "network" RetryClassificationRateLimit RetryClassification = "rate_limit" RetryClassificationServerOverload RetryClassification = "server_overload" RetryClassificationTimeout RetryClassification = "timeout" RetryClassificationServerError RetryClassification = "server_error" RetryClassificationClientError RetryClassification = "client_error" RetryClassificationAuthError RetryClassification = "auth_error" RetryClassificationUnknown RetryClassification = "unknown" // RetryClassificationModelDeprecated is returned when the provider rejects // the request because the model identifier is no longer available. The // caller should switch to an active fallback model and not retry with the // same model name. RetryClassificationModelDeprecated RetryClassification = "model_deprecated" // reachable but not available in the configured region or endpoint. The // caller may retry with a different region or endpoint. RetryClassificationRegionallyUnavailable RetryClassification = "regionally_unavailable" // RetryClassificationQuotaExhausted is returned when the account has // exhausted its quota (distinct from a transient rate-limit). Retrying // immediately will not help; the caller should either wait until the // quota resets or switch to a different provider. RetryClassificationQuotaExhausted RetryClassification = "quota_exhausted" )
func ClassifyHTTPError ¶
func ClassifyHTTPError(err error, statusCode int) RetryClassification
type RetryState ¶
type RetryState struct {
// contains filtered or unexported fields
}
RetryState contains retry and circuit breaker state.
func (*RetryState) IncrementFailure ¶
func (s *RetryState) IncrementFailure()
func (*RetryState) IsCircuitOpen ¶
func (s *RetryState) IsCircuitOpen(maxFailures int) bool
func (*RetryState) ResetConsecutiveFailures ¶
func (s *RetryState) ResetConsecutiveFailures()
type RetryStrategy ¶
type RetryStrategy struct {
MaxRetries int
MaxConsecutiveFailures int
FallbackModel *types.ModelIdentifier
Max529Errors int
EnableContextOverflowRetry bool
BaseDelayMs int64
MaxBackoffMs int64
}
RetryStrategy defines advanced retry options.
func DefaultRetryStrategy ¶
func DefaultRetryStrategy() *RetryStrategy
DefaultRetryStrategy returns the default retry strategy.