Skip to content

Public API

Sanam edited this page Oct 6, 2026 · 1 revision

Public API

Root namespace TypeSafeSharp. Nullable annotations are part of the contract. Configurable types use { get; set; }; response types are get-only, so C# 7.3 callers on .NET Framework can use every member.

Client

Type What it does
TypeSafeClient One thread-safe client per app. SystemOneAsync runs one request, EvaluateManyAsync a batch.
ModelsClient ListAsync returns the models and aliases available to the key.
ModelCard A model or alias: Name, Description, ReleaseDate.

Requests and questions

Type What it does
SystemOneRequest The state and questions for one call, plus an optional Model.
Question Abstract base. Build with Question.Noul, Question.Choice or Question.Score. Question.FromJson passes through kinds this package does not model yet.
NoulQuestion, ChoiceQuestion, ScoreQuestion The three question kinds.

Responses and answers

Type What it does
SystemOneResponse Model, Answers, Usage, RequestId, and typed GetNoul, GetChoice, GetScore.
Answer Abstract base with a Type.
NoulAnswer, ChoiceAnswer, ScoreAnswer The typed answers.
UnknownAnswer An answer kind this package does not model, kept with its raw JSON.
Usage Input and output token counts.
TypeSafeModelFactory Builds responses, answers and exceptions for callers' unit tests.

Options and retries

Type What it does
TypeSafeClientOptions Key, base URL, default model, timeouts, retries and logging.
TypeSafeRequestOptions Per-call overrides for timeouts and retries.
RetryPolicy Default (two retries, retry timeouts) or None.
BatchOptions MaxConcurrency and per-call options for EvaluateManyAsync.

Errors

Each status has its own type under TypeSafeApiException, which carries StatusCode, RequestId, Endpoint, Body and Headers. TypeSafeTimeoutException and TypeSafeConnectionException cover the transport. TypeSafeResponseValidationException covers a 2xx body that is not the documented shape, and TypeSafeConfigurationException a bad key, base URL or browser use. All derive from TypeSafeException.

Batch

Type What it does
BatchItem<TItem> One item's Index, Item, Response or Exception, Elapsed and Succeeded.

Dependency injection

AddTypeSafe(IConfiguration) and AddTypeSafe(Action<TypeSafeClientOptions>) on IServiceCollection register a singleton TypeSafeClient over a named HttpClient, bind options AOT-safely and check the key at host start. They live in TypeSafeSharp.Extensions.DependencyInjection.

Clone this wiki locally