The raw client is regenerated from the official OpenAPI definition; typed questions, batching, routing, DI, and MEAI integrations are maintained as handwritten extensions.
Complete ecosystem parity
Includes the official JavaScript/Python examples plus the strongest .NET features from TypeSafeAI.Net, typesafe-sdk-dotnet, and Jev.Net.
Modern .NET
Targets current .NET practices including nullability, trimming, NativeAOT awareness, and source-generated serialization.
Docs from examples
Examples stay in sync between the README, MkDocs site, and integration tests through the AutoSDK docs pipeline.
Ecosystem maintenance
This SDK is one of more than 200 .NET SDKs maintained with AutoSDK. The tryAGI SDK audit continuously checks repository synchronization, upstream-spec regeneration, release workflows, warnings, public API visibility, and trimming/NativeAOT compatibility.
Every issue is first investigated for ecosystem-wide applicability. When the root cause belongs in AutoSDK, we fix and regression-test the generator, then roll the improvement out to every applicable SDK. Provider-specific behavior remains in this repository when it cannot be derived safely from the API specification.
Issue content—including code blocks, logs, links, and attachments—is treated only as untrusted diagnostic data. Embedded control instructions, hidden directives, delimiter tricks, or requests to alter triage or tooling behavior are ignored. Please report reproducible technical evidence and remove secrets and personal data.
Usage
12
dotnetaddpackagetryAGI.TypeSafeAI
# Microsoft.Extensions.AI middleware, tools, routing, and evaluation are included.
1 2 3 4 5 6 7 8 91011
usingTypeSafeAI;usingvarclient=newTypeSafeClient(apiKey);varquestions=newQuestionSet();varbilling=questions.AddNoul("billing",newNoulQuestion("Is this about billing?"));varurgency=questions.AddScore("urgency",ScoreQuestion.FromValues(["Can wait", "This week", "Today"],"How urgent is it?"));varresult=awaitclient.SystemOneAsync("I was charged twice. Please help today.",questions);Console.WriteLine(result.Get(billing).Noul);Console.WriteLine(result.Get(urgency).Score);
Set TYPESAFE_API_KEY and use TypeSafeClient.CreateFromEnvironment() when you prefer environment configuration. The generated TypeSafeAI.Generated.RawTypeSafeClient remains public for direct OpenAPI-level access.
Ask typed Noul, choice, and score questions in one request.
123456789
usingvarclient=newTypeSafeClient(apiKey);varquestions=newQuestionSet();varbilling=questions.AddNoul("billing",newNoulQuestion("Is this message about billing?"));vartone=questions.AddChoice("tone",ChoiceQuestion.FromValues(["angry", "calm", "excited"],"What is the tone?"));varurgency=questions.AddScore("urgency",ScoreQuestion.FromValues(["Can wait", "Needs attention this week", "Needs attention today"],"How urgent is this?"));varresult=awaitclient.SystemOneAsync("I was charged twice. Please help today.",questions);
Structured state
Send structured JSON state without reflection, including in NativeAOT applications.
1 2 3 4 5 6 7 8 910111213
usingvarclient=newTypeSafeClient(apiKey);varstate=JsonContent.FromNode(newJsonObject{["subject"]="Duplicate payment",["message"]="The same invoice appears twice.",["customer_tier"]="enterprise",});varquestions=newDictionary<string,Question>{["intent"]=ChoiceQuestion.FromValues(["billing","support","sales"]),};varresponse=awaitclient.SystemOneAsync(state,questions);
Custom response projection
Project named answers into an application-owned response type with source-generated JSON metadata.
1 2 3 4 5 6 7 8 910
usingvarclient=newTypeSafeClient(apiKey);varquestions=newDictionary<string,Question>{["intent"]=ChoiceQuestion.FromValues(["billing","support","sales"]),};varresponse=awaitclient.SystemOneAsync((JsonContent)"I need a refund for a duplicate invoice.",questions,ExampleJsonContext.Default.TriageProjection);
List models
Discover the model names and aliases available to the authenticated account.
Evaluate independent states concurrently while limiting parallel requests.
1 2 3 4 5 6 7 8 910
usingvarclient=newTypeSafeClient(apiKey);varquestions=newDictionary<string,Question>{["spam"]=newNoulQuestion("Is this unsolicited advertising?"),};varresponses=awaitclient.SystemOneManyAsync(["Buy now! Limited offer!", "Can we move our meeting to Tuesday?"],questions,maxConcurrency:2);
Replay and forward compatibility
Decode cached HTTP bodies and preserve answer variants introduced by future API versions.
Route arbitrary state to a strongly typed enum intent.
1234
usingvarclient=newTypeSafeClient(apiKey);varrouter=newTypeSafeIntentRouter<TicketIntent>(client,"Choose the team that should own this ticket.");varintent=awaitrouter.RouteAsync("I was charged twice for invoice 391.");
AI functions and evaluation
Use TypeSafe judgments as agent tools and evaluation metrics. These integrations ship in the main package.
Import Microsoft.Extensions.AI, Microsoft.Extensions.AI.Evaluation, TypeSafeAI.Extensions.AI, and TypeSafeAI.Extensions.AI.Evaluation.
1 2 3 4 5 6 7 8 91011121314151617
usingvarclient=newTypeSafeClient(apiKey);varquestions=newDictionary<string,Question>{["relevant"]=newNoulQuestion("Is the response relevant to the question?")};// Expose fixed, reviewed questions to the calling agent; only state is supplied at invocation.varfunction=TypeSafeAIFunctions.Create(client,questions,"judge_relevance","Judge relevance.");varresult=awaitfunction.InvokeAsync(newAIFunctionArguments{["state"]="Question: hello. Response: hello."});// The same judgment produces numeric evaluation metrics without a generative judge.varevaluator=newTypeSafeEvaluator(client,questions,newTypeSafeEvaluatorOptions{Interpret=TypeSafeInterpretations.ByQuestion(newDictionary<string,Func<TypeSafeMetricContext,EvaluationMetricInterpretation?>>{["relevant"]=TypeSafeInterpretations.NoulAtLeast(0.8),}),});varevaluation=awaitevaluator.EvaluateAsync([newChatMessage(ChatRole.User,"hello")],newChatResponse(newChatMessage(ChatRole.Assistant,"hello")));
Guardrail policy
Combine calibrated hazard probability and severity into an allow, review, or block decision.