Vercel AI SDK for .NET

Call any model
from C#.

A provider-agnostic toolkit for text, structured data, tools, and agents. A model id such as openai/gpt-6-astra goes to the Vercel AI Gateway. Or call OpenAI, Anthropic, and Google directly.

Unofficial community port of the Vercel AI SDK. Not an official Vercel product.

dotnet add package Vercel.AI

One package. It targets net10.0 and netstandard2.0.Vercel.AI on NuGet.

C#GenerateTextExample source
using Vercel.AI;
using Vercel.AI.Gateway;

var client = new AiClient(GatewayProvider.Create());

var result = await client.GenerateTextAsync(
    new GenerateTextOptions
{
    ModelId = "openai/gpt-6-astra",
    // use Vercel AI Gateway
    Prompt = "What is an agent?",
});

Console.WriteLine(result.Text);
GatewayProvider.Create() reads AI_GATEWAY_API_KEY

Package

Vercel.AI

Every provider, one package

Targets

net10.0

and netstandard2.0

Parity

AI SDK 7

Language Model spec V4

License

Apache-2.0

Free for commercial use

Why this SDK

The same ideas as the AI SDK, in the C# you already write.

  • Gateway or a provider

    Pass ModelId and the Gateway resolves it. Pass Model when you already have an ILanguageModel from OpenAI, Anthropic, Google, and the other providers in this package.

    Providers
  • Tools and agents

    Tool.Function gives the model a JSON schema and an Execute delegate. Agent runs that loop with instructions and tools.

    Tools
  • Stream the reply

    StreamTextAsync returns immediately. Read TextStream for deltas. ToUIMessageStreamResult writes the events a JavaScript useChat client already reads.

    Streaming
  • JSON that matches a schema

    OutputSpec.Object takes a JSON schema. GenerateTextAsync parses the reply into result.Output.

    OutputSpec

Get started

From an empty project to a first reply, in three steps.

Install the package, call a model, then stream the reply or hand the model a tool. Each step links to the page that has the rest.

Read the quickstart
  1. Install the package

    Add Vercel.AI to a project that targets net10.0 or netstandard2.0. Every provider ships in this package.

    dotnet add package Vercel.AI
    Quickstart
  2. Call a model

    GatewayProvider.Create() reads AI_GATEWAY_API_KEY. A string model id goes to the Gateway. Pass Model to call a provider directly.

    var client = new AiClient(GatewayProvider.Create());
    Generate text
  3. Stream it, or add a tool

    StreamTextAsync yields text as the model writes it. To let the model call your code, add a tool.

    await foreach (var delta in stream.TextStream())
    {
        Console.Write(delta);
    }
    Streaming