Versions in this module Expand all Collapse all v1 v1.0.0 Sep 19, 2026 Changes in this version + const DefaultBackoffInitial + const DefaultBackoffJitter + const DefaultBackoffMax + const DefaultBaseURL + const DefaultBatchConcurrency + const DefaultCircuitOpenFor + const DefaultCircuitThreshold + const DefaultInputCostPerMillionTokens + const DefaultMaxRetries + const DefaultMaxRetryAfter + const DefaultModel + const DefaultRequestsPerMinute + const DefaultRetryTimeout + const DefaultTimeout + const DefaultTokensPerSecond + const EnvAPIKey + const EnvBaseURL + const EnvDefaultModel + const EnvLogLevel + const MaxContextTokens + const MaxScoreLevels + const MaxSingleQuestionTokens + const MinAdaptiveConcurrency + const MinScoreLevels + const ModelsPath + const RequestIDHeader + const StatusOverloaded + const SystemOnePath + const TypeChoice + const TypeNoul + const TypeScore + var ErrAuthentication = errors.New("typesafe: authentication failed") + var ErrBadRequest = errors.New("typesafe: bad request") + var ErrBatchPartialFailure = errors.New("typesafe: some batch items failed") + var ErrBudgetExceeded = errors.New("typesafe: budget exceeded") + var ErrCircuitOpen = errors.New("typesafe: circuit breaker is open") + var ErrConnection = errors.New("typesafe: connection failed") + var ErrInternalServer = errors.New("typesafe: server error") + var ErrInvalidConfig = errors.New("typesafe: invalid client configuration") + var ErrInvalidRequest = errors.New("typesafe: request failed validation") + var ErrInvalidResponse = errors.New("typesafe: malformed response") + var ErrNoAPIKey = errors.New("typesafe: no API key") + var ErrNoSuchAnswer = errors.New("typesafe: no answer with that id") + var ErrNotFound = errors.New("typesafe: not found") + var ErrOverloaded = errors.New("typesafe: service overloaded") + var ErrPermissionDenied = errors.New("typesafe: permission denied") + var ErrRateLimit = errors.New("typesafe: rate limited") + var ErrRetriesExhausted = errors.New("typesafe: retries exhausted") + var ErrTimeout = errors.New("typesafe: request timed out") + var ErrUndeclaredOption = fmt.Errorf("typesafe: answer contains an option the question did not declare") + var ErrWrongAnswerType = errors.New("typesafe: wrong answer type") + var Version = "0.0.0-dev" + func ContextWithRequestID(ctx context.Context, id string) context.Context + func Exhaustive[T OptionKey](a ChoiceAnswerOf[T], allowed ...T) error + func RequestIDFrom(ctx context.Context) string + func VersionString() string + type API interface + Models func(ctx context.Context) ([]ModelCard, error) + SystemOne func(ctx context.Context, req *SystemOneRequest) (*SystemOneResponse, error) + type APIError struct + Body []byte + Detail []ValidationDetail + Endpoint string + Header http.Header + Reason *ErrorDetail + RequestID string + Status int + func (e *APIError) Error() string + type Answer interface + Type func() string + type AttemptInfo struct + Attempt int + Delay time.Duration + Elapsed time.Duration + Err error + RetryAfterHonored bool + Status int + type AuthenticationError struct + func (e *AuthenticationError) Is(target error) bool + func (e *AuthenticationError) Unwrap() error + type BadRequestError struct + func (e *BadRequestError) Is(target error) bool + func (e *BadRequestError) Unwrap() error + type BatchError struct + Failed int + Summary string + Total int + func (e *BatchError) Error() string + func (e *BatchError) Is(target error) bool + type BatchOption func(*batchConfig) + func WithAdaptiveConcurrency(enabled bool) BatchOption + func WithBatchModel(model string) BatchOption + func WithConcurrency(n int) BatchOption + func WithItemCallback(fn func(ItemResult)) BatchOption + type BatchResult struct + Duration time.Duration + Failed int + Items []ItemResult + MinConcurrency int + PeakConcurrency int + Succeeded int + Usage Usage + func (r BatchResult) Err() error + func (r BatchResult) Errors() []error + func (r BatchResult) Responses() []*SystemOneResponse + type Budget struct + func DefaultBudget() *Budget + func NewBudget(opts ...BudgetOption) *Budget + func (b *Budget) Reset() + func (b *Budget) Usage() BudgetUsage + type BudgetOption func(*Budget) + func MaxRequestsPerMinute(n int) BudgetOption + func MaxTokensPerSecond(n int) BudgetOption + func MaxTotalRequests(n int) BudgetOption + func MaxTotalTokens(n int) BudgetOption + type BudgetUsage struct + RequestsLastMinute int + TokensLastSecond int + TotalRequests int + TotalTokens int + type CallInfo struct + Duration time.Duration + Err error + InputTokens int + Model string + OutputTokens int + Questions int + RequestID string + type Choice struct + Criteria Options + Instructions EntryType + func (c Choice) MarshalJSON() ([]byte, error) + type ChoiceAnswer struct + Choice string + Confidence float64 + Probabilities map[string]float64 + func (ChoiceAnswer) Type() string + func (a ChoiceAnswer) Margin() float64 + func (a ChoiceAnswer) ProbabilityOf(option string) (float64, bool) + func (a ChoiceAnswer) Ranked() []RankedOption + type ChoiceAnswerOf struct + Choice T + Confidence float64 + Probabilities map[T]float64 + func TypedChoiceAnswer[T OptionKey](r *SystemOneResponse, id string) (ChoiceAnswerOf[T], error) + func (a ChoiceAnswerOf[T]) Margin() float64 + func (a ChoiceAnswerOf[T]) ProbabilityOf(option T) (float64, bool) + func (a ChoiceAnswerOf[T]) Ranked() []RankedOptionOf[T] + func (a ChoiceAnswerOf[T]) Untyped() ChoiceAnswer + type ChoiceBuilder struct + func NewChoice(instructions EntryType) ChoiceBuilder + func (b ChoiceBuilder) Build() Choice + func (b ChoiceBuilder) MarshalJSON() ([]byte, error) + func (b ChoiceBuilder) Option(name string, description EntryType) ChoiceBuilder + func (b ChoiceBuilder) Options(names ...string) ChoiceBuilder + type CircuitBreaker struct + HalfOpenProbes int + OnStateChange func(from, to CircuitState) + OpenFor time.Duration + Threshold int + func NewCircuitBreaker() *CircuitBreaker + func (b *CircuitBreaker) Reset() + func (b *CircuitBreaker) State() CircuitState + type CircuitState int + const CircuitClosed + const CircuitHalfOpen + const CircuitOpen + func (s CircuitState) String() string + type Client struct + func NewClient(opts ...Option) (*Client, error) + func (c *Client) BaseURL() string + func (c *Client) DefaultModel() string + func (c *Client) Models(ctx context.Context) ([]ModelCard, error) + func (c *Client) SystemOne(ctx context.Context, req *SystemOneRequest) (*SystemOneResponse, error) + func (c *Client) SystemOneAll(ctx context.Context, requests ...*SystemOneRequest) []Result + func (c *Client) SystemOneAsync(ctx context.Context, req *SystemOneRequest) <-chan Result + func (c *Client) SystemOneBatch(ctx context.Context, states []any, qs Questions, opts ...BatchOption) BatchResult + func (c *Client) SystemOneBatchSeq(ctx context.Context, states []any, qs Questions, opts ...BatchOption) iter.Seq2[int, ItemResult] + type ConnectionError struct + Endpoint string + Err error + func (e *ConnectionError) Error() string + func (e *ConnectionError) Is(target error) bool + func (e *ConnectionError) Unwrap() error + type CostEstimate struct + InputCostUSD float64 + Questions int + RatePerMillionUSD float64 + Tokens TokenEstimate + func (c CostEstimate) String() string + type EntryType = any + type ErrorDetail struct + ErrorType string + Message string + func (d ErrorDetail) String() string + type Handler func(ctx context.Context, req *SystemOneRequest) (*SystemOneResponse, error) + type Hooks struct + OnError func(ctx context.Context, info CallInfo) + OnRequest func(ctx context.Context, req *SystemOneRequest) + OnResponse func(ctx context.Context, info CallInfo) + type Interceptor func(next Handler) Handler + func WithLogging(l *slog.Logger) Interceptor + type InternalServerError struct + func (e *InternalServerError) Is(target error) bool + func (e *InternalServerError) Unwrap() error + type ItemResult struct + Duration time.Duration + Err error + Index int + Response *SystemOneResponse + State any + type LevelKey interface + type Levels []EntryType + type ModelCard struct + Description string + Name string + ReleaseDate string + type NotFoundError struct + func (e *NotFoundError) Is(target error) bool + func (e *NotFoundError) Unwrap() error + type Noul struct + Criteria *NoulCriteria + Instructions EntryType + func (n Noul) MarshalJSON() ([]byte, error) + type NoulAnswer struct + Noul float64 + func (NoulAnswer) Type() string + func (a NoulAnswer) Bool(threshold float64) bool + func (a NoulAnswer) Uncertain(delta float64) bool + type NoulBuilder struct + func NewNoul(instructions EntryType) NoulBuilder + func (b NoulBuilder) Build() Noul + func (b NoulBuilder) MarshalJSON() ([]byte, error) + func (b NoulBuilder) Means(yes, no EntryType) NoulBuilder + type NoulCriteria struct + False EntryType + True EntryType + type Option func(*config) error + func WithAPIKey(key string) Option + func WithBaseURL(raw string) Option + func WithBudget(b *Budget) Option + func WithCircuitBreaker(b *CircuitBreaker) Option + func WithContextLimitCheck(enabled bool) Option + func WithDefaultModel(model string) Option + func WithHTTPClient(hc *http.Client) Option + func WithHeader(key, value string) Option + func WithHooks(h Hooks) Option + func WithInterceptor(interceptors ...Interceptor) Option + func WithLogger(l *slog.Logger) Option + func WithMaxRetries(n int) Option + func WithRequestID(fn func() string, header ...string) Option + func WithRetryObserver(fn func(context.Context, AttemptInfo)) Option + func WithRetryPolicy(p RetryPolicy) Option + func WithTimeout(d time.Duration) Option + func WithUserAgentSuffix(suffix string) Option + type OptionKey interface + type Options map[string]EntryType + type OverloadedError struct + RetryAfter time.Duration + func (e *OverloadedError) Is(target error) bool + func (e *OverloadedError) Unwrap() error + type PanicError struct + Stack []byte + Value any + func (e *PanicError) Error() string + func (e *PanicError) Unwrap() error + type PermissionDeniedError struct + func (e *PermissionDeniedError) Is(target error) bool + func (e *PermissionDeniedError) Unwrap() error + type Question interface + type Questions = map[string]Question + type RankedOption struct + Option string + Probability float64 + type RankedOptionOf struct + Option T + Probability float64 + type RateLimitError struct + RetryAfter time.Duration + func (e *RateLimitError) Is(target error) bool + func (e *RateLimitError) Unwrap() error + type RawQuestion map[string]any + type RefWarning struct + Path string + QuestionID string + Reason string + func (w RefWarning) String() string + type ResponseValidationError struct + Body []byte + Endpoint string + Err error + RequestID string + func (e *ResponseValidationError) Error() string + func (e *ResponseValidationError) Is(target error) bool + func (e *ResponseValidationError) Unwrap() error + type Result struct + Err error + Response *SystemOneResponse + type RetryPolicy struct + BackoffInitial time.Duration + BackoffJitter float64 + BackoffMax time.Duration + HTTPStatuses map[int]bool + MaxRetries int + MaxRetryAfter time.Duration + Predicate func(error) bool + RespectRetryAfter bool + RetryOnConnection bool + RetryOnTimeout bool + Timeout time.Duration + func DefaultRetryPolicy() RetryPolicy + func NoRetry() RetryPolicy + type Score struct + Criteria Levels + Instructions EntryType + func (s Score) MarshalJSON() ([]byte, error) + type ScoreAnswer struct + Confidence float64 + Legend map[string]EntryType + Probabilities map[string]float64 + Score float64 + func (ScoreAnswer) Type() string + func (a ScoreAnswer) AtOrAbove(level int) float64 + func (a ScoreAnswer) AtOrBelow(level int) float64 + func (a ScoreAnswer) LevelProbabilities() []float64 + func (a ScoreAnswer) Levels() []EntryType + func (a ScoreAnswer) MostLikely() (int, float64) + func (a ScoreAnswer) Nearest() (int, EntryType) + func (a ScoreAnswer) NumLevels() int + type ScoreAnswerOf struct + Confidence float64 + Legend map[L]EntryType + Level L + Probabilities map[L]float64 + Score float64 + func TypedScoreAnswer[L LevelKey](r *SystemOneResponse, id string) (ScoreAnswerOf[L], error) + func (a ScoreAnswerOf[L]) AtOrAbove(level L) float64 + func (a ScoreAnswerOf[L]) AtOrBelow(level L) float64 + func (a ScoreAnswerOf[L]) MostLikely() (L, float64) + func (a ScoreAnswerOf[L]) Untyped() ScoreAnswer + type ScoreBuilder struct + func NewScore(instructions EntryType) ScoreBuilder + func (b ScoreBuilder) Build() Score + func (b ScoreBuilder) Level(description EntryType) ScoreBuilder + func (b ScoreBuilder) Levels(descriptions ...string) ScoreBuilder + func (b ScoreBuilder) MarshalJSON() ([]byte, error) + type SystemOneRequest struct + Model string + Questions map[string]Question + State any + func (r *SystemOneRequest) CheckReferences() []RefWarning + func (r *SystemOneRequest) EstimateCost(ratePerMillionUSD float64) CostEstimate + func (r *SystemOneRequest) EstimateTokens() TokenEstimate + func (r *SystemOneRequest) Validate() ([]Warning, error) + type SystemOneResponse struct + Answers map[string]json.RawMessage + Model string + Usage Usage + func (r *SystemOneResponse) All() map[string]Answer + func (r *SystemOneResponse) Answer(id string) (Answer, error) + func (r *SystemOneResponse) Choice(id string) (ChoiceAnswer, error) + func (r *SystemOneResponse) Choices() map[string]ChoiceAnswer + func (r *SystemOneResponse) Confidence(id string) (float64, bool) + func (r *SystemOneResponse) Noul(id string) (NoulAnswer, error) + func (r *SystemOneResponse) Nouls() map[string]NoulAnswer + func (r *SystemOneResponse) Score(id string) (ScoreAnswer, error) + func (r *SystemOneResponse) Scores() map[string]ScoreAnswer + type TimeoutError struct + Endpoint string + Err error + func (e *TimeoutError) Error() string + func (e *TimeoutError) Is(target error) bool + func (e *TimeoutError) Unwrap() error + type TokenEstimate struct + Approximate bool + ExceedsSingle bool + ExceedsTotal bool + LongestQuestionID string + LongestSingle int + Overhead int + PerQuestion map[string]int + State int + Total int + func (e TokenEstimate) Err() error + func (e TokenEstimate) String() string + func (e TokenEstimate) WouldExceedLimits() bool + type TypedChoiceQuestion struct + func TypedChoice[T OptionKey](instructions EntryType, opts ...TypedOption[T]) TypedChoiceQuestion[T] + func (q TypedChoiceQuestion[T]) Answer(r *SystemOneResponse, id string) (ChoiceAnswerOf[T], error) + func (q TypedChoiceQuestion[T]) Options() []T + type TypedLevel struct + Description EntryType + Level L + func LevelOf[L LevelKey](level L, description EntryType) TypedLevel[L] + type TypedOption struct + Description EntryType + Name T + func OptionOf[T OptionKey](name T, description EntryType) TypedOption[T] + type TypedScoreQuestion struct + func TypedScore[L LevelKey](instructions EntryType, levels ...TypedLevel[L]) TypedScoreQuestion[L] + func (q TypedScoreQuestion[L]) Answer(r *SystemOneResponse, id string) (ScoreAnswerOf[L], error) + func (q TypedScoreQuestion[L]) Levels() []L + type UnprocessableEntityError struct + func (e *UnprocessableEntityError) Is(target error) bool + func (e *UnprocessableEntityError) Unwrap() error + type Usage struct + InputTokens int + OutputTokens int + type ValidationDetail struct + Ctx map[string]any + Input any + Loc []any + Msg string + Type string + func (d ValidationDetail) Path() string + func (d ValidationDetail) String() string + type Warning struct + Message string + QuestionID string + func (w Warning) String() string