Versions in this module Expand all Collapse all v0 v0.4.0 Oct 8, 2026 v0.3.0 Oct 5, 2026 v0.2.1 Oct 4, 2026 v0.2.0 Oct 4, 2026 v0.1.0 Oct 2, 2026 Changes in this version + const ReasonChoiceNotArgmax + const ReasonChoiceNotOption + const ReasonCustom + const ReasonDecodeFailed + const ReasonLegendKeys + const ReasonMissingAnswer + const ReasonMissingField + const ReasonNotFinite + const ReasonOutOfRange + const ReasonProbabilityKeys + const ReasonProbabilitySum + const ReasonTypeMismatch + const ReasonUnexpectedAnswer + const Version + var ErrAuth = errors.New("decide: authentication failed") + var ErrDecode = errors.New("decide: cannot decode response") + var ErrInconsistentAnswer = errors.New("decide: inconsistent answer") + var ErrInvalidAnswer = errors.New("decide: invalid answer") + var ErrInvalidRequest = errors.New("decide: invalid request") + var ErrNoAPIKey = errors.New("decide: no API key: set TYPESAFE_API_KEY or use WithAPIKey") + var ErrOverloaded = errors.New("decide: overloaded") + var ErrRateLimited = errors.New("decide: rate limited") + var ErrServer = errors.New("decide: server error") + var ErrValidation = errors.New("decide: request validation failed") + func AnswerAs[A Answer](resp *Response, key string) (A, error) + func Attempt(ctx context.Context) int + func RegisterAnswerType(typ string, newAnswer func() Answer) error + type APIError struct + Body []byte + Details []ValidationDetail + Message string + RequestID string + RetryAfter time.Duration + StatusCode int + Type string + func (e *APIError) Error() string + func (e *APIError) Unwrap() []error + type Answer interface + AnswerType func() string + func DecodeAnswer(data []byte) (Answer, error) + type AnswerError struct + Detail string + Err error + Key string + Reason string + Type string + func (e *AnswerError) Error() string + func (e *AnswerError) Unwrap() []error + type AnswerMaker interface + MakeAnswer func() Answer + type AnswerValidator interface + ValidateAnswer func(a Answer) error + type CallOption func(*callConfig) + func WithCallAttemptTimeout(d time.Duration) CallOption + func WithCallMaxRetries(n int) CallOption + func WithCallValidation(on bool) CallOption + type Candidate struct + Description any + Item T + type ChoiceAnswer struct + Choice string + Confidence float64 + Extra map[string]json.RawMessage + Probabilities map[string]float64 + func (a *ChoiceAnswer) AnswerType() string + func (a *ChoiceAnswer) Margin() float64 + func (a *ChoiceAnswer) MarshalJSON() ([]byte, error) + func (a *ChoiceAnswer) Ranked() []Prob + func (a *ChoiceAnswer) UnmarshalJSON(data []byte) error + type ChoiceOption struct + Description any + Key string + func Option(key string, description ...any) ChoiceOption + func OptionsFromMap[V any](m map[string]V) []ChoiceOption + type ChoiceQuestion struct + Criteria []ChoiceOption + Extra map[string]any + Instructions any + func Choice(instructions any, options ...ChoiceOption) *ChoiceQuestion + func (q *ChoiceQuestion) MakeAnswer() Answer + func (q *ChoiceQuestion) MarshalJSON() ([]byte, error) + func (q *ChoiceQuestion) NewAnswer() *ChoiceAnswer + func (q *ChoiceQuestion) QuestionType() string + func (q *ChoiceQuestion) UnmarshalJSON(data []byte) error + func (q *ChoiceQuestion) ValidateAnswer(a Answer) error + type Client struct + Models *ModelsService + func NewClient(opts ...ClientOption) (*Client, error) + func (c *Client) DefaultModel() string + func (c *Client) GoString() string + func (c *Client) LogValue() slog.Value + func (c *Client) String() string + func (c *Client) SystemOne(ctx context.Context, req *Request, opts ...CallOption) (*Response, error) + type ClientOption func(*clientConfig) error + func WithAPIKey(key string) ClientOption + func WithAttemptTimeout(d time.Duration) ClientOption + func WithBaseURL(url string) ClientOption + func WithHTTPClient(hc *http.Client) ClientOption + func WithLogBodies(on bool) ClientOption + func WithLogger(l *slog.Logger) ClientOption + func WithMaxRetries(n int) ClientOption + func WithModel(name string) ClientOption + func WithRetryBackoff(initial, max time.Duration) ClientOption + func WithTransport(t Transport) ClientOption + func WithUserAgent(product string) ClientOption + func WithValidation(on bool) ClientOption + func WithoutEnvironment() ClientOption + type Decision struct + Answer *ChoiceAnswer + Index int + Item T + Picked bool + Response *Response + func Pick[T any](ctx context.Context, client *Client, state any, instructions any, ...) (Decision[T], error) + type Evaluation struct + Answer A + Response *Response + func Eval[A Answer](ctx context.Context, client *Client, state any, question QuestionFor[A], ...) (Evaluation[A], error) + type HTTPTransport struct + func NewHTTPTransport(cfg HTTPTransportConfig) (*HTTPTransport, error) + func (t *HTTPTransport) ListModels(ctx context.Context) (*ModelList, error) + func (t *HTTPTransport) SystemOne(ctx context.Context, req *Request) (*Response, error) + func (t HTTPTransport) GoString() string + func (t HTTPTransport) LogValue() slog.Value + func (t HTTPTransport) String() string + type HTTPTransportConfig struct + APIKey string + BaseURL string + HTTPClient *http.Client + UserAgent string + func (c HTTPTransportConfig) GoString() string + func (c HTTPTransportConfig) LogValue() slog.Value + func (c HTTPTransportConfig) String() string + type Handle struct + func Ask[A Answer](req *Request, key string, q QuestionFor[A]) Handle[A] + func (h Handle[A]) From(resp *Response) (A, error) + func (h Handle[A]) Key() string + type InvalidAnswersError struct + Answers []*AnswerError + func (e *InvalidAnswersError) Error() string + func (e *InvalidAnswersError) Unwrap() []error + type Model struct + Description string + Extra map[string]json.RawMessage + Name string + ReleaseDate string + func (m *Model) UnmarshalJSON(data []byte) error + func (m Model) MarshalJSON() ([]byte, error) + type ModelList struct + Extra map[string]json.RawMessage + Header http.Header + Models []Model + Raw []byte + RequestID string + func (l *ModelList) MarshalJSON() ([]byte, error) + func (l *ModelList) UnmarshalJSON(data []byte) error + type ModelsService struct + func (s *ModelsService) List(ctx context.Context) (*ModelList, error) + type NoulAnswer struct + Extra map[string]json.RawMessage + Noul float64 + func (a *NoulAnswer) AnswerType() string + func (a *NoulAnswer) MarshalJSON() ([]byte, error) + func (a *NoulAnswer) UnmarshalJSON(data []byte) error + type NoulCriteria struct + False any + True any + type NoulOption func(*NoulQuestion) + func NoulFalse(description any) NoulOption + func NoulTrue(description any) NoulOption + type NoulQuestion struct + Criteria *NoulCriteria + Extra map[string]any + Instructions any + func Noul(instructions any, opts ...NoulOption) *NoulQuestion + func (q *NoulQuestion) MakeAnswer() Answer + func (q *NoulQuestion) MarshalJSON() ([]byte, error) + func (q *NoulQuestion) NewAnswer() *NoulAnswer + func (q *NoulQuestion) QuestionType() string + func (q *NoulQuestion) UnmarshalJSON(data []byte) error + func (q *NoulQuestion) ValidateAnswer(a Answer) error + type Prob struct + Key string + P float64 + type Question interface + QuestionType func() string + func DecodeQuestion(data []byte) (Question, error) + type QuestionFor interface + NewAnswer func() A + type RawAnswer struct + Err error + JSON json.RawMessage + Type string + func (a *RawAnswer) AnswerType() string + func (a *RawAnswer) MarshalJSON() ([]byte, error) + func (a *RawAnswer) UnmarshalJSON(data []byte) error + type RawQuestion struct + JSON json.RawMessage + Type string + func (q *RawQuestion) MakeAnswer() Answer + func (q *RawQuestion) MarshalJSON() ([]byte, error) + func (q *RawQuestion) NewAnswer() *RawAnswer + func (q *RawQuestion) QuestionType() string + func (q *RawQuestion) UnmarshalJSON(data []byte) error + type Request struct + Extra map[string]any + Model string + Questions map[string]Question + State any + func NewRequest(state any, opts ...RequestOption) *Request + func (r *Request) MarshalJSON() ([]byte, error) + func (r *Request) UnmarshalJSON(data []byte) error + func (r *Request) Validate() error + type RequestOption func(*Request) + func WithRequestExtra(key string, value any) RequestOption + func WithRequestModel(name string) RequestOption + type Response struct + Answers map[string]Answer + Extra map[string]json.RawMessage + Header http.Header + Invalid map[string]*AnswerError + Model string + Raw []byte + RequestID string + Usage Usage + func DecodeResponse(data []byte, req *Request) (*Response, error) + func (r *Response) MarshalJSON() ([]byte, error) + func (r *Response) UnmarshalJSON(data []byte) error + type ScoreAnswer struct + Confidence float64 + Extra map[string]json.RawMessage + Legend map[string]any + Probabilities map[string]float64 + Score float64 + func (a *ScoreAnswer) AnswerType() string + func (a *ScoreAnswer) Level() int + func (a *ScoreAnswer) LevelLabel(i int) any + func (a *ScoreAnswer) Levels() int + func (a *ScoreAnswer) MarshalJSON() ([]byte, error) + func (a *ScoreAnswer) Normalized() float64 + func (a *ScoreAnswer) ProbabilityAt(i int) (float64, bool) + func (a *ScoreAnswer) UnmarshalJSON(data []byte) error + type ScoreQuestion struct + Criteria []any + Extra map[string]any + Instructions any + func Score(instructions any, levels ...any) *ScoreQuestion + func ScoreOf[T any](instructions any, levels []T) *ScoreQuestion + func (q *ScoreQuestion) MakeAnswer() Answer + func (q *ScoreQuestion) MarshalJSON() ([]byte, error) + func (q *ScoreQuestion) NewAnswer() *ScoreAnswer + func (q *ScoreQuestion) QuestionType() string + func (q *ScoreQuestion) UnmarshalJSON(data []byte) error + func (q *ScoreQuestion) ValidateAnswer(a Answer) error + type Transport interface + ListModels func(ctx context.Context) (*ModelList, error) + SystemOne func(ctx context.Context, req *Request) (*Response, error) + type Usage struct + Extra map[string]json.RawMessage + InputTokens int + OutputTokens int + func (u *Usage) UnmarshalJSON(data []byte) error + func (u Usage) MarshalJSON() ([]byte, error) + type ValidationDetail struct + Ctx map[string]any + Input json.RawMessage + Loc []any + Msg string + Type string