Google_GenerativeAI.Microsoft
4.0.1
dotnet add package Google_GenerativeAI.Microsoft --version 4.0.1
NuGet\Install-Package Google_GenerativeAI.Microsoft -Version 4.0.1
<PackageReference Include="Google_GenerativeAI.Microsoft" Version="4.0.1" />
<PackageVersion Include="Google_GenerativeAI.Microsoft" Version="4.0.1" />
<PackageReference Include="Google_GenerativeAI.Microsoft" />
paket add Google_GenerativeAI.Microsoft --version 4.0.1
#r "nuget: Google_GenerativeAI.Microsoft, 4.0.1"
#:package Google_GenerativeAI.Microsoft@4.0.1
#addin nuget:?package=Google_GenerativeAI.Microsoft&version=4.0.1
#tool nuget:?package=Google_GenerativeAI.Microsoft&version=4.0.1
Google_GenerativeAI.Microsoft
Google_GenerativeAI.Microsoft implements the Microsoft.Extensions.AI
abstractions for Google Gemini, using the Google_GenerativeAI SDK.
| Abstraction | Implementation | Default model |
|---|---|---|
IChatClient |
GenerativeAIChatClient |
GoogleAIModels.DefaultGeminiModel |
IEmbeddingGenerator<string, Embedding<float>> |
GenerativeAIEmbeddingGenerator |
GoogleAIModels.GeminiEmbedding |
IImageGenerator |
GenerativeAIImageGenerator (Gemini native image models) |
GoogleAIModels.GeminiNanoBanana21 |
Each type accepts either an API key (Gemini API) or an IPlatformAdapter, for example a VertextPlatformAdapter for
Vertex AI.
Installation
dotnet add package Google_GenerativeAI.Microsoft
Microsoft.Extensions.AI.Abstractions 10.x is used on .NET 8 and .NET 9, and 11.x on .NET 10+, .NET Standard 2.0 and
.NET Framework 4.6.2.
Chat
using GenerativeAI;
using GenerativeAI.Microsoft;
using Microsoft.Extensions.AI;
IChatClient chatClient = new GenerativeAIChatClient(
System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY")!, GoogleAIModels.Gemini38Flash);
// Single response
ChatResponse response = await chatClient.GetResponseAsync("What is the capital of France?");
Console.WriteLine(response.Text);
// Multi-turn conversation
var history = new List<ChatMessage>
{
new(ChatRole.System, "You are a concise assistant."),
new(ChatRole.User, "Suggest a name for a coffee shop.")
};
response = await chatClient.GetResponseAsync(history);
history.AddMessages(response);
// Streaming
await foreach (var update in chatClient.GetStreamingResponseAsync("Tell me a short story."))
Console.Write(update.Text);
Function calling
Functions passed in ChatOptions.Tools are called automatically and their results are sent back to the model. Pass
autoCallFunction: false to the constructor if you prefer ChatClientBuilder.UseFunctionInvocation().
[Description("Gets the current weather for a city")]
static string GetWeather(string city) => $"It is 22°C and sunny in {city}.";
var options = new ChatOptions { Tools = [AIFunctionFactory.Create(GetWeather)] };
var answer = await chatClient.GetResponseAsync("What's the weather in Paris?", options);
Dependency injection
builder.Services.AddSingleton<IChatClient>(_ =>
new GenerativeAIChatClient(builder.Configuration["Gemini:ApiKey"]!, GoogleAIModels.Gemini38Flash));
Embeddings
IEmbeddingGenerator<string, Embedding<float>> embeddings =
new GenerativeAIEmbeddingGenerator(System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY")!);
var vectors = await embeddings.GenerateAsync(["first document", "second document"]);
Images
#pragma warning disable MEAI001
IImageGenerator images = new GenerativeAIImageGenerator(System.Environment.GetEnvironmentVariable("GOOGLE_API_KEY")!);
var generated = await images.GenerateAsync(new ImageGenerationRequest { Prompt = "A watercolor lighthouse at sunrise" });
var image = generated.Contents.OfType<DataContent>().First();
await File.WriteAllBytesAsync("lighthouse.png", image.Data.ToArray());
// Gemini image models can also edit and combine existing images.
var edited = await images.GenerateAsync(new ImageGenerationRequest
{
Prompt = "Turn this into a night scene.",
OriginalImages = [image]
});
Documentation
License
MIT License. See LICENSE.
| 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 is compatible. 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 is compatible. 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. net11.0 is compatible. |
| .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 is compatible. 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. |
-
.NETFramework 4.6.2
- Google_GenerativeAI (>= 4.0.1)
- Microsoft.Extensions.AI.Abstractions (>= 11.0.0)
-
.NETStandard 2.0
- Google_GenerativeAI (>= 4.0.1)
- Microsoft.Extensions.AI.Abstractions (>= 11.0.0)
-
net10.0
- Google_GenerativeAI (>= 4.0.1)
- Microsoft.Extensions.AI.Abstractions (>= 11.0.0)
-
net11.0
- Google_GenerativeAI (>= 4.0.1)
- Microsoft.Extensions.AI.Abstractions (>= 11.0.0)
-
net8.0
- Google_GenerativeAI (>= 4.0.1)
- Microsoft.Extensions.AI.Abstractions (>= 10.11.0)
-
net9.0
- Google_GenerativeAI (>= 4.0.1)
- Microsoft.Extensions.AI.Abstractions (>= 10.11.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Google_GenerativeAI.Microsoft:
| Package | Downloads |
|---|---|
|
HPD-Agent.Providers.GoogleAI
Google AI (Gemini) provider for HPD-Agent |
|
|
GoogleAdk
Agent Development Kit (ADK) for .NET — libraries, API host, tools, and Roslyn source generators in one package. |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Google_GenerativeAI.Microsoft:
| Repository | Stars |
|---|---|
|
rwjdk/agent-framework-samples
Samples demonstrating the Microsoft Agent Framework in C#
|
|
|
signumsoftware/framework
Open Source framework for writing data-centric applications using the latest versions of .Net Core, C# (not-nullable), ASP.NET Web API, Typescript (strict), React, D3 and Sql Server or PostgreeSQL
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1 | 0 | 11/15/2026 |
| 4.0.0 | 0 | 11/15/2026 |
| 3.6.8 | 2,748 | 10/14/2026 |
| 3.6.7 | 13,907 | 7/22/2026 |
| 3.6.6 | 35,083 | 4/20/2026 |
| 3.6.5 | 288 | 4/18/2026 |
| 3.6.4 | 4,687 | 3/26/2026 |
| 3.6.3 | 70,755 | 1/23/2026 |
| 3.6.2 | 2,842 | 1/15/2026 |
| 3.6.1 | 4,643 | 12/28/2025 |
| 3.5.0 | 270 | 12/26/2025 |
| 3.4.1 | 5,575 | 11/8/2025 |
| 3.4.0 | 2,783 | 10/21/2025 |
| 3.3.0 | 3,062 | 10/3/2025 |
| 3.2.0 | 5,293 | 9/10/2025 |
| 3.1.1 | 302 | 9/7/2025 |
| 3.0.0 | 2,270 | 7/21/2025 |
| 2.7.0 | 4,289 | 6/2/2025 |
| 2.6.0 | 532 | 5/25/2025 |
| 2.5.9.1 | 317 | 5/25/2025 |