For the complete documentation index, see llms.txt. This page is also available as Markdown.

.NET SDK

Runnable versions of every example on this page live in nexos-ai/dotnet-examples.

Setup

Install the packages:

dotnet add package Microsoft.Extensions.AI
dotnet add package Microsoft.Extensions.AI.OpenAI
dotnet add package DotNetEnv

All examples read the API key from a .env file:

API_KEY=YOUR_NEXOS_API_KEY

OpenAI-compatible clients use the base URL https://api.nexos.ai/v1; the Anthropic Messages API takes the bare https://api.nexos.ai because the SDK appends /v1/messages itself.

Model IDs on nexos.ai are the model names shown in the console (e.g. GPT 5.5, Claude Sonnet 5, Whisper). List them with GET /v1/models.

The examples below use Microsoft.Extensions.AI — the provider-neutral abstraction layer — over an OpenAIClient pointed at the gateway. Where a capability has no Microsoft.Extensions.AI surface, the raw OpenAI SDK client is used directly.

Chat Completion

Send a conversation and get the model's next reply — the standard OpenAI-compatible endpoint, supported by most chat models on the platform.

using DotNetEnv;
using Microsoft.Extensions.AI;
using OpenAI;
using System.ClientModel;

Env.TraversePath().Load();
var apiKey = Environment.GetEnvironmentVariable("API_KEY")!;

var options = new OpenAIClientOptions { Endpoint = new Uri("https://api.nexos.ai/v1") };

IChatClient chatClient = new OpenAIClient(new ApiKeyCredential(apiKey), options)
    .GetChatClient("GPT 5.5")
    .AsIChatClient();

var response = await chatClient.GetResponseAsync(
    "how many letters 'r' in the word 'strawberry'");

Console.WriteLine(response.Text);

Chat Completion with history

Keep the full message list between turns so the model can resolve references to earlier context.

Streaming

Receive the reply incrementally as server-sent events instead of waiting for the whole message — useful for chat UIs and long outputs.

Reasoning

Let the model reason internally before answering — the response carries reasoning content alongside the final text. Reasoning effort is an experimental surface in the OpenAI SDK, so the OPENAI001 diagnostic is suppressed.

Function calling

Let the model call functions you define. With FunctionInvokingChatClient in the pipeline, the round trip is automatic: the model requests the tool, the client runs your delegate, sends the result back, and returns the final answer.

Caching

Wrap the client in DistributedCachingChatClient to serve identical requests from a local cache instead of calling the gateway again — the second call below returns without a network round trip.

Structured output

Ask for the answer as a typed .NET object. The client derives a JSON schema from the record, sends it as the response format, and deserializes the reply.

Embedding

Convert text into a numeric vector for semantic search, clustering, and RAG. One vector is returned per input.

Image Generation

Generate an image from a text prompt. IImageGenerator is experimental in Microsoft.Extensions.AI.Abstractions, so the MEAI001 diagnostic is suppressed.

Audio Generation

Convert text to spoken audio (text-to-speech).

Audio Transcription

Transcribe an audio file to text in its original language. The example reads sound.mp3 — you can create one with the Audio Generation example above.

Audio Translation

Transcribe an audio file and translate the text into English. The example reads sound.mp3 — you can create one with the Audio Generation example above.

Dependency injection

In ASP.NET Core, register IChatClient once and inject it wherever it's needed. The key comes from configuration — user secrets, an environment variable, or appsettings.Development.json.

Set the key and call the endpoint:

Anthropic Messages API

The /v1/messages endpoint implements the Anthropic Messages API — including cache_control prompt caching, thinking blocks, and tool_use — and is available for models that list the messages endpoint in GET /v1/models (e.g. Claude models).

There is no Microsoft-owned provider for it. Use the community Anthropic.SDK package against the bare base URL https://api.nexos.ai, or call the endpoint with a plain HttpClient.