Skip to main content
Client for the TypeSafe AI API.

Constructors

Constructor

Create a client for the TypeSafe AI API. Explicit options take precedence over environment variables, then SDK defaults. Empty or whitespace-only environment values are ignored.

Parameters

config?
TypeSafeClientConfig = {}

Returns

TypeSafeClient

Throws

The API key is missing, configuration is invalid, the runtime is unsupported, or the runtime lacks the requested compression.

Properties

baseURL

API root with trailing slashes removed.

compression

Request body compression, or false when bodies are sent uncompressed.

defaultHeaders

Additional headers sent with each request.

defaultModel

Model used when a request omits model.

fetch

HTTP fetch implementation.

logger

The configured logger, filtered to logLevel.

logLevel

Configured log verbosity.

models

The models available to the account.

retry

Retry settings with constructor overrides applied.

timeout

Timeout per attempt in milliseconds.

Methods

systemOne()

Answer named questions about text, structured state, or assets.

Type Parameters

Q
Q extends Questions

Parameters

request
SystemOneRequest<Q> State, questions, an optional model override, and optional assets. Assets in state, question content, or withAssets text are sent under their references.
options?
RequestOptions = {} Per-call timeout, retry, headers, and cancellation settings.

Returns

APIPromise<SystemOneResult<Q>> Answers typed by question name and criteria, with model and token usage. Every failure below rejects the returned promise; the call itself doesn’t throw.

Throws

State is null or omitted, questions are empty, score criteria are not a list of at least two entries, choice criteria are not a nonempty map, a noul question has neither instructions nor a described outcome, a string holds the reference of an asset not attached to the request, a name in assets doesn’t appear in the request, or a Blob asset can’t be read.

Throws

The server returns a non-2xx response after retries.

Throws

The request cannot connect or times out after retries.

Throws

The caller aborts the request.

Example