Gravicode.TypeSafeSdk
1.1.0
dotnet add package Gravicode.TypeSafeSdk --version 1.1.0
NuGet\Install-Package Gravicode.TypeSafeSdk -Version 1.1.0
<PackageReference Include="Gravicode.TypeSafeSdk" Version="1.1.0" />
<PackageVersion Include="Gravicode.TypeSafeSdk" Version="1.1.0" />
<PackageReference Include="Gravicode.TypeSafeSdk" />
paket add Gravicode.TypeSafeSdk --version 1.1.0
#r "nuget: Gravicode.TypeSafeSdk, 1.1.0"
#:package Gravicode.TypeSafeSdk@1.1.0
#addin nuget:?package=Gravicode.TypeSafeSdk&version=1.1.0
#tool nuget:?package=Gravicode.TypeSafeSdk&version=1.1.0
TypeSafe .NET SDK
Unofficial, strongly typed .NET 10 client for the TypeSafe System One API, ported from the official Python SDK.
dotnet add package Gravicode.TypeSafeSdk
Ask a question about some text
using TypeSafeSdk;
await using var client = new TypeSafeClient(TypeSafeOptions.FromEnvironment());
var response = await client.SystemOneAsync(
new { document = "I was charged twice. Please fix this ASAP." },
Choice.Create("billing", "technical", "other"));
Console.WriteLine(response.Choices["category"].Choice); // billing
Console.WriteLine(response.Choices["category"].Confidence); // 1
Three kinds of question, one request
var response = await client.SystemOneAsync(
new { document = ticket.Body },
new Dictionary<string, object>
{
["category"] = Choice.Create("billing", "technical", "other"),
["urgent"] = new NoulSchema("Does this need a response within one hour?"),
["tone"] = new ScoreSchema("How frustrated is the customer?", "calm", "annoyed", "angry")
});
var queue = response.Choices["category"].Choice; // a label
var urgent = response.Nouls["urgent"].IsTrue; // a 0..1 value, thresholded
var tone = response.Scores["tone"].NearestLabel; // an expected value on a scale
Every answer carries its full probability distribution, so an ambiguous case is visible instead of hidden behind a single label.
Typed failures
TypeSafeApiException is the base for every HTTP failure, and each one carries StatusCode, Body, Headers, Endpoint, and RequestId.
catch (TypeSafeRateLimitException ex) { await Task.Delay(ex.RetryAfter ?? TimeSpan.FromSeconds(1)); }
catch (TypeSafeAuthenticationException) { /* 401 — retrying will not help */ }
catch (TypeSafeApiTimeoutException ex) { logger.LogWarning("Timed out after {Timeout}", ex.Timeout); }
Also available: TypeSafeBadRequestException, TypeSafePermissionDeniedException, TypeSafeNotFoundException, TypeSafeUnprocessableEntityException, TypeSafeInternalServerException, TypeSafeApiConnectionException, and TypeSafeApiResponseValidationException.
Retry, timeout, headers
Defaults match the Python SDK: two retries, 0.5 s backoff doubling to a 5 s ceiling with 25% jitter, retrying 408/429/5xx, honouring Retry-After, inside a 30 s budget.
var options = new TypeSafeOptions
{
Timeout = TimeSpan.FromSeconds(20),
Retry = new RetryPolicy(MaxRetries: 4),
Headers = { ["X-Tenant"] = "acme" }
};
Any of it can be overridden per call, alongside extraHeaders and extraBody.
Tests without a key
await using var client = new TypeSafeClient(new TypeSafeOptions { Simulator = true });
The simulator answers choice, noul, and score questions locally and deterministically — no key, no network. It is lexical rather than semantic: it weights rare criteria words above common ones, honours negation, and abstains with a flat distribution when it finds no signal instead of guessing.
Configuration
TypeSafeOptions.FromEnvironment() reads TYPESAFE_API_KEY, TYPESAFE_BASE_URL, TYPESAFE_DEFAULT_MODEL, TYPESAFE_LOG_LEVEL, and TYPESAFE_SIMULATOR. The names are also constants on TypeSafeConstants.
Links
Created by Gravicode Studios, led by Kang Fadhil. AI assistant: Jack — The Code Bender.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 78 | 9/24/2026 |
Parity pass against the official Python SDK: full typed exception hierarchy, request ids, Retry-After, client-level retry and timeout, custom headers and extra body, TypeSafeConstants, ListModelsResponse, and a simulator that answers choice, noul, and score questions.