Vercel.AI
0.4.0
dotnet add package Vercel.AI --version 0.4.0
NuGet\Install-Package Vercel.AI -Version 0.4.0
<PackageReference Include="Vercel.AI" Version="0.4.0" />
<PackageVersion Include="Vercel.AI" Version="0.4.0" />
<PackageReference Include="Vercel.AI" />
paket add Vercel.AI --version 0.4.0
#r "nuget: Vercel.AI, 0.4.0"
#:package Vercel.AI@0.4.0
#addin nuget:?package=Vercel.AI&version=0.4.0
#tool nuget:?package=Vercel.AI&version=0.4.0
Vercel AI SDK for .NET
The Vercel AI SDK for .NET is a provider-agnostic C# toolkit to build AI-powered applications and agents on .NET.
It is an unofficial community port of the AI SDK. 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.
To learn more, read the documentation.
Preview the docs site locally:
cd docs-site && npm ci && npm run api && npm run dev
Open http://localhost:4321/vercel-ai-sdk-dotnet/ . The path includes /vercel-ai-sdk-dotnet/ because that is the base path on hardkoded.com (https://www.hardkoded.com/vercel-ai-sdk-dotnet/). That URL is the marketing page. Documentation starts at http://localhost:4321/vercel-ai-sdk-dotnet/docs/ . Article sources stay in docs/articles/. See docs-site/README.md.
Installation
You need a project that targets net10.0 or netstandard2.0. Run dotnet add package Vercel.AI.
Every provider ships in this one package.
Skill for Coding Agents
If you use coding agents such as Claude Code or Cursor, we highly recommend adding the Vercel AI SDK for .NET skill to your repository:
npx skills add hardkoded/vercel-ai-sdk-dotnet
Unified Provider Architecture
The SDK gives you one API to call model providers like OpenAI, Anthropic, Google, and more.
By default, string model ids go to the Vercel AI Gateway, which gives you access to all major providers. Pass a model string for any supported model:
<a id='snippet-gateway-model'></a>
var client = new AiClient(GatewayProvider.Create());
var result = await client.GenerateTextAsync(
new GenerateTextOptions
{
ModelId = "anthropic/claude-opus-5.5", // or "openai/gpt-6-astra", "google/gemini-3.8-flash", etc.
Prompt = "Hello!",
}
);
<sup><a href='/examples/Providers/Program.cs#L19-L29' title='Snippet source file'>snippet source</a> | <a href='#snippet-gateway-model' title='Start of snippet'>anchor</a></sup>
You can also connect to a provider directly. Each provider has a Create() method that reads its API key from the same environment variable as the JavaScript provider:
<a id='snippet-provider-model'></a>
var client = new AiClient(GatewayProvider.Create());
var anthropic = AnthropicProvider.Create(); // or OpenAIProvider.Create(), GoogleProvider.Create(), etc.
var result = await client.GenerateTextAsync(
new GenerateTextOptions
{
Model = anthropic.LanguageModel("claude-opus-5-5"),
Prompt = "Hello!",
}
);
<sup><a href='/examples/Providers/Program.cs#L36-L47' title='Snippet source file'>snippet source</a> | <a href='#snippet-provider-model' title='Start of snippet'>anchor</a></sup>
Usage
Generating Text
<a id='snippet-generate-text'></a>
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);
<sup><a href='/examples/GenerateText/Program.cs#L14-L26' title='Snippet source file'>snippet source</a> | <a href='#snippet-generate-text' title='Start of snippet'>anchor</a></sup>
Generating Structured Data
<a id='snippet-generate-structured-data'></a>
var client = new AiClient(GatewayProvider.Create());
var result = await client.GenerateTextAsync(
new GenerateTextOptions
{
ModelId = "openai/gpt-6-astra",
Output = OutputSpec.Object(
"""
{
"type": "object",
"properties": {
"recipe": {
"type": "object",
"properties": {
"name": { "type": "string" },
"ingredients": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"amount": { "type": "string" }
},
"required": ["name", "amount"],
"additionalProperties": false
}
},
"steps": { "type": "array", "items": { "type": "string" } }
},
"required": ["name", "ingredients", "steps"],
"additionalProperties": false
}
},
"required": ["recipe"],
"additionalProperties": false
}
"""
),
Prompt = "Generate a lasagna recipe.",
}
);
Console.WriteLine(result.Output);
<sup><a href='/examples/GenerateStructuredData/Program.cs#L14-L58' title='Snippet source file'>snippet source</a> | <a href='#snippet-generate-structured-data' title='Start of snippet'>anchor</a></sup>
Agents
<a id='snippet-agent'></a>
var weatherAgent = new Agent(
new AgentOptions
{
ModelId = "openai/gpt-6-astra",
Instructions = "You are an agent that answers questions about the weather.",
Tools = new[]
{
Tool.Function(
"weather",
"Returns the weather in a city.",
"""{ "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] }""",
(arguments, cancellationToken) =>
{
var city = arguments.GetProperty("city").GetString();
return Task.FromResult(
JsonSerializer.Serialize(
new
{
city,
forecast = "sunny",
temperature = 22,
}
)
);
}
),
},
}
);
var result = await weatherAgent.GenerateAsync("What is the weather in Lisbon?");
Console.WriteLine(result.Text);
<sup><a href='/examples/Agent/Program.cs#L14-L47' title='Snippet source file'>snippet source</a> | <a href='#snippet-agent' title='Start of snippet'>anchor</a></sup>
Examples
Every code block in this README comes from a project in examples. Each project is one example, and CI builds all of them.
| Example | Shows |
|---|---|
| GenerateText | Generate text with a Gateway model string. |
| GenerateStructuredData | Generate a JSON object that matches a schema. |
| GenerateVertexAnthropicOutputObjectNative | Generate a structured object from Claude on Vertex with native structured output. |
| StreamVertexAnthropicOutputObjectNative | Stream a structured object from Claude on Vertex with native structured output. |
| Agent | Run an agent that calls a tool. |
| Providers | Call a model through the Gateway and through a provider directly. |
| StreamText | Stream text as the model writes it. |
| StreamTranscribeDeepgramBasic | Transcribe paced live audio with Deepgram streaming transcription. |
| GenerateSpeechAssemblyAIBasic | Generates speech with AssemblyAI assemblyai-tts-1 and saves it to a file. |
| TranscribeAssemblyAIBasic | Transcribes a local audio file with AssemblyAI assemblyai-stt-3-7. |
| TranscribeAssemblyAIString | Transcribes a base64 audio string with AssemblyAI assemblyai-stt-3-7. |
| TranscribeAssemblyAIUrl | Transcribes audio from a URL with AssemblyAI assemblyai-stt-3-7. |
| TranscribeGladiaV2Options | Transcribe audio with Gladia solaria-3, a language config and PII redaction. |
| Tools | Let the model call a tool and read its result. |
| McpImageContent | Convert an MCP image tool result into a model file part. |
| UIMessageStream | Stream a UI message response from ASP.NET Core to a JavaScript useChat client. |
Run an example with dotnet run --project examples/GenerateText. The examples call the AI Gateway when AI_GATEWAY_API_KEY is set. Without the key, they print a message and exit. Providers also calls Anthropic directly when ANTHROPIC_API_KEY is set. McpImageContent starts its bundled Node.js MCP server and needs no model key. UIMessageStream listens on http://127.0.0.1:43123 and uses a scripted model when no key is set.
This port has no UI packages. ToUIMessageStreamResult writes the AI SDK UI message stream (text/event-stream) that a JavaScript useChat client already reads.
Tests
Run 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 examples are net10.0 only. Versions come from MinVer. Pushing a vMAJOR.MINOR.PATCH tag packs Vercel.AI and publishes that package to nuget.org with Trusted Publishing. Vercel publishes the documentation site on push to main. .github/workflows/docs.yml only builds and checks it.
Community
Ask questions, report bugs, and share ideas in GitHub issues.
Contributing
Contributions are welcome. Read CONTRIBUTING.md before you start.
Authors
This port is maintained by Darío Kondratiuk. The AI SDK it ports is created by Vercel and Next.js team members, with contributions from the Open Source Community.
License
Apache License 2.0. Copyright 2023 Vercel, Inc. See LICENSE and NOTICE.
| 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
- AngleSharp (>= 1.8.5)
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
- System.Text.Encoding.CodePages (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
-
net10.0
- AngleSharp (>= 1.8.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Vercel.AI:
| Package | Downloads |
|---|---|
|
Vercel.AI.Mistral.LiveKit
LiveKit adapter for the Mistral realtime transport of the community .NET port of the Vercel AI SDK. Wraps the Livekit.Rtc.Dotnet client. Not an official Vercel product. |
GitHub repositories
This package is not used by any popular GitHub repositories.