Skip to main content
Full generated reference: pkg.go.dev. The upstream contract is in openapi.json, fetched from https://api.typesafe.ai/openapi.json.

Client

Option
Sets the API key, overriding TYPESAFE_API_KEY.
Option
Sets the base URL, overriding TYPESAFE_BASE_URL.
Option
Sets the default model, overriding TYPESAFE_DEFAULT_MODEL.
Option
Sets the underlying *http.Client.
Option
Sets the retry count for network errors, 429s, and 5xxs. Default 3.
Option
Turns on an in-memory cache for SystemOne responses. Off by default.

Caching, from first principles

A decision has a shelf life. The same question, asked about the same state, has one right answer until the state changes. A cache stores that answer, keyed on the full request, not on the words used to ask for it. The cache is off by default. A stale decision looks exactly like a fresh one, and the cost of acting on a wrong decision is usually higher than the cost of one repeated API call. Turn the cache on only when you know a state repeats, and a few seconds of staleness is acceptable. The cache check runs before the network call, not after. A cache hit skips the retry loop too, since there is no network call to retry. SystemOne is the only cached call. ListModels rarely changes and is rarely called, so it is not worth a cache entry. An error response is never cached: an error is not a decision.

SystemOne

POST /v1/systemone
typesafe.WithRequestModel(model string) overrides the model for a single call.

Question types

All three implement the Question interface.
struct
Instructions string, Criteria map[string]string. Picks one named option.
struct
Instructions string, Criteria []string. Rates on an ordered scale.
struct
Instructions string, Criteria map[string]string. Answers true or false with a probability.

Response

string
Usage
InputTokens, OutputTokens
map[string]ChoiceAnswer
Choice, Confidence, Probabilities
map[string]ScoreAnswer
Score, Confidence, Legend, Probabilities
map[string]NoulAnswer
Noul

ListModels

GET /v1/models
Returns []Model, each with Name, Description, ReleaseDate.

Errors

Non-2xx responses return *typesafe.Error:
int
json.RawMessage
Validation detail, when the API returns one.
[]byte
The raw response body.