Vercel.AI
0.2.0
dotnet add package Vercel.AI --version 0.2.0
NuGet\Install-Package Vercel.AI -Version 0.2.0
<PackageReference Include="Vercel.AI" Version="0.2.0" />
<PackageVersion Include="Vercel.AI" Version="0.2.0" />
<PackageReference Include="Vercel.AI" />
paket add Vercel.AI --version 0.2.0
#r "nuget: Vercel.AI, 0.2.0"
#:package Vercel.AI@0.2.0
#addin nuget:?package=Vercel.AI&version=0.2.0
#tool nuget:?package=Vercel.AI&version=0.2.0
Vercel AI SDK for .NET
Unofficial community port of the Vercel AI SDK for .NET. It is an independent reimplementation of the public AI SDK behavior and provider HTTP APIs. It is not a copy of Vercel’s TypeScript, not an official Vercel product, and not endorsed by Vercel.
The parity target is AI SDK 7 / Language Model specification V4. See COMPATIBILITY.md for the upstream commit and the packages that are intentionally not ported.
License: Apache License 2.0. Copyright 2023 Vercel, Inc.
Docs: https://hardkoded.github.io/vercel-ai-sdk-dotnet/
Install
dotnet add package Vercel.AI
String model ids such as openai/gpt-4.1-mini are resolved by the Gateway, which ships inside this package.
What you can call
Vercel.AI is a server library:
GenerateTextAsyncandStreamTextAsync(tools, structured JSON output, stop conditions, middleware)EmbedAsync,EmbedManyAsync,RerankAsync,CosineSimilarityGenerateImageAsync,GenerateSpeechAsync,TranscribeAsync,TranslateAsync,GenerateVideoAsyncAgent,ProviderRegistry, and provider middleware- Model providers, including the Vercel AI Gateway, in the same package
ToUIMessageStreamResult writes the AI SDK UI message stream (text/event-stream) that a JavaScript useChat client already consumes. That helper is available on net10.0. There is no React, Vue, Svelte, Angular, or RSC package in this repo.
String model ids such as openai/gpt-4.1-mini are resolved by the Gateway provider.
Run the samples
dotnet run --project samples/Vercel.AI.Sample
dotnet run --project samples/Vercel.AI.AspNetCore.Sample
The console sample uses a scripted model unless AI_GATEWAY_API_KEY is set. The ASP.NET sample listens on http://127.0.0.1:43123 and does the same for POST /chat.
curl -N -X POST http://127.0.0.1:43123/chat \
-H 'content-type: application/json' \
-d '{"prompt":"Hello"}'
Tests
dotnet test Vercel.AI.slnx -c Release
Unit tests mock HTTP and do not need keys. Integration tests call a live provider only when AI_GATEWAY_API_KEY or OPENAI_API_KEY is set.
Packages
The library targets net10.0 and netstandard2.0. The ASP.NET UI stream helper and the samples are net10.0 only. Versions come from MinVer. Pushing a vMAJOR.MINOR.PATCH tag packs Vercel.AI, publishes that package to nuget.org with Trusted Publishing, and the docs workflow publishes the DocFX site.
var model = OpenAIProvider.Create().LanguageModel("gpt-4.1-mini");
var result = await new AiClient(Vercel.AI.Gateway.GatewayProvider.Create(new() { ApiKey = "unused" }))
.GenerateTextAsync(new GenerateTextOptions
{
Model = model,
Prompt = "Write a one-sentence release note.",
});
Console.WriteLine(result.Text);
Dependency injection:
services.AddAiSdk(options => options.GatewayApiKey = configuration["AI_GATEWAY_API_KEY"]);
services.AddOpenAI();
Provider keys use the same environment variables as the JavaScript providers (OPENAI_API_KEY, ANTHROPIC_API_KEY, AI_GATEWAY_API_KEY, and the rest listed in COMPATIBILITY.md).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
- System.Text.Json (>= 8.0.5)
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.