Google_GenerativeAI 0.1.17
See the version list below for details.
dotnet add package Google_GenerativeAI --version 0.1.17
NuGet\Install-Package Google_GenerativeAI -Version 0.1.17
<PackageReference Include="Google_GenerativeAI" Version="0.1.17" />
<PackageVersion Include="Google_GenerativeAI" Version="0.1.17" />
<PackageReference Include="Google_GenerativeAI" />
paket add Google_GenerativeAI --version 0.1.17
#r "nuget: Google_GenerativeAI, 0.1.17"
#:package Google_GenerativeAI@0.1.17
#addin nuget:?package=Google_GenerativeAI&version=0.1.17
#tool nuget:?package=Google_GenerativeAI&version=0.1.17
Google GenerativeAI (Gemini)
Unofficial C# SDK based on Google GenerativeAI (Gemini Pro) REST APIs.
This package includes C# Source Generator which allows you to define functions natively through a C# interface,
and also provides extensions that make it easier to call this interface later.
In addition to easy function implementation and readability,
it generates Args classes, extension methods to easily pass a functions to API,
and extension methods to simply call a function via json and return json.
Currently only System.Text.Json is supported.
Usage
Quick Start
- Obtain an API key to use with the Google AI SDKs. 
- Install Google_GenerativeAI Nuget Package 
Install-Package Google_GenerativeAI
or
dotnet add package Google_GenerativeAI
Write some codes:
 var apiKey = 'Your API Key';
 var model = new GenerativeModel(apiKey);
 //or var model = new GeminiProModel(apiKey)
 var res = await model.GenerateContentAsync("How are you doing?");
Chat Mode
 var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
 var model = new GenerativeModel(apiKey);
 //or var model = new GeminiProModel(apiKey)
 var chat = model.StartChat(new StartChatParams());
 var result = await chat.SendMessageAsync("Write a poem");
 Console.WriteLine("Initial Poem\r\n");
 Console.WriteLine(result);
 var result2 = await chat.SendMessageAsync("Make it longer");
 Console.WriteLine("Long Poem\r\n");
 Console.WriteLine(result2);
 
Vision
var imageBytes = await File.ReadAllBytesAsync("image.png");
string prompt = "What is in the image?";
var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
var visionModel = new GeminiProVision(apiKey);
var result = await visionModel.GenerateContentAsync(prompt,new FileObject(imageBytes,"image.png"));
Console.WriteLine(result.Text());
or
var imageBytes = await File.ReadAllBytesAsync("image.png");
var imagePart = new Part()
{
    InlineData = new GenerativeContentBlob()
    {
        MimeType = "image/png",
        Data = Convert.ToBase64String(imageBytes)
    }
};
var textPart = new Part()
{
    Text = "What is in the image?"
};
var parts = new[] { textPart, imagePart };
var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
var visionModel = new GeminiProVision(apiKey);
var result = await visionModel.GenerateContentAsync(parts);
Console.WriteLine(result.Text());
Function Calling
using GenerativeAI;
public enum Unit
{
    Celsius,
    Fahrenheit,
    Imperial
}
public class Weather
{
    public string Location { get; set; } = string.Empty;
    public double Temperature { get; set; }
    public Unit Unit { get; set; }
    public string Description { get; set; } = string.Empty;
}
[GenerativeAIFunctions]
public interface IWeatherFunctions
{
    [Description("Get the current weather in a given location")]
    public Task<Weather> GetCurrentWeatherAsync(
        [Description("The city and state, e.g. San Francisco, CA")] string location,
        Unit unit = Unit.Celsius,
        CancellationToken cancellationToken = default);
}
public class WeatherService : IWeatherFunctions
{
    public Task<Weather> GetCurrentWeatherAsync(string location, Unit unit = Unit.Celsius, CancellationToken cancellationToken = default)
    {
        return Task.FromResult(new Weather
        {
            Location = location,
            Temperature = 22.0,
            Unit = unit,
            Description = "Sunny",
        });
    }
}
 WeatherService service = new WeatherService();
 
 var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
 var model = new GenerativeModel(apiKey);
 // Add Global Functions
 model.AddGlobalFunctions(service.AsGoogleFunctions(), service.AsGoogleCalls())
 var result = await model.GenerateContentAsync("How is the weather in San Francisco today?");
 
 Console.WriteLine(result);
Streaming
streaming doesn't support Function calling
Streaming with Generative Model
var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
var model = new GenerativeModel(apiKey);
//or var model = new GeminiProModel(apiKey);
var action = new Action<string>(s =>
{
    Console.Write(s);
});
await model.StreamContentAsync("How are you doing?",action);
Streaming With GeminiProVision
var imageBytes = await File.ReadAllBytesAsync("image.png");
string prompt = "What is in the image?";
var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
var visionModel = new GeminiProVision(apiKey);
var chat = visionModel.StartChat(new StartChatParams());
Action<string> handler = (a) =>
{
    Console.WriteLine(a);
};
var result = await chat.StreamContentVisionAsync(prompt, new FileObject(imageBytes, "image.png"), handler);
Streaming with ChatSession
var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
var model = new GenerativeModel(apiKey);
var handler = new Action<string>((a) =>
{
    Console.Write(a);
});
var chat = model.StartChat(new StartChatParams());
await chat.StreamContentAsync("Write a poem", handler);
ModelInfoService
This service can be used to get all the Google Generative AI Models.
Get List of Available Models
var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
var service = new ModelInfoService(apiKey);
var models = await service.GetModelsAsync();
Get Model info with Model Id
 var apiKey = Environment.GetEnvironmentVariable("Gemini_API_Key", EnvironmentVariableTarget.User);
 var service = new ModelInfoService(apiKey);
 var modelInfo = await service.GetModelInfoAsync("gemini-pro");
Credits
Thanks to HavenDV for OpenAI SDK
| Product | Versions Compatible and additional computed target framework versions. | 
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 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 was computed. 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 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- System.ComponentModel.Annotations (>= 5.0.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.3)
 
- 
                                                    .NETStandard 2.0- System.ComponentModel.Annotations (>= 5.0.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.3)
 
- 
                                                    net6.0- System.ComponentModel.Annotations (>= 5.0.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.3)
 
- 
                                                    net7.0- System.ComponentModel.Annotations (>= 5.0.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.3)
 
- 
                                                    net8.0- System.ComponentModel.Annotations (>= 5.0.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 8.0.3)
 
NuGet packages (11)
Showing the top 5 NuGet packages that depend on Google_GenerativeAI:
| Package | Downloads | 
|---|---|
| LangChain.Providers.Google Google Gemini Chat model provider. | |
| Google_GenerativeAI.Auth This library is part of the Google_GenerativeAI SDK and provides various API authentication implementations for seamless usage of the Google_GenerativeAI SDK. | |
| Google_GenerativeAI.Live Gemini MultiModal Live API module for Google Generative AI SDK | |
| Google_GenerativeAI.Microsoft This library provides Microsoft.Extensions.AI integration with Google_GenerativeAI SDK for .NET applications. | |
| Google_GenerativeAI.Tools Provides a set of tools and concrete implementations to facilitate function calling with the Google_GenerativeAI SDK, including support for code generation. | 
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Google_GenerativeAI:
| Repository | Stars | 
|---|---|
| SciSharp/BotSharp 
                                                            AI Multi-Agent Framework in .NET
                                                         | 
| Version | Downloads | Last Updated | 
|---|---|---|
| 3.4.0 | 1,108 | 10/21/2025 | 
| 3.3.0 | 4,019 | 10/3/2025 | 
| 3.2.0 | 7,545 | 9/10/2025 | 
| 3.1.1 | 737 | 9/7/2025 | 
| 3.0.0 | 24,530 | 7/21/2025 | 
| 2.7.0 | 25,315 | 6/2/2025 | 
| 2.6.0 | 1,772 | 5/25/2025 | 
| 2.5.10 | 5,977 | 5/9/2025 | 
| 2.5.9.1 | 337 | 5/25/2025 | 
| 2.5.9 | 5,164 | 4/25/2025 | 
| 2.5.8.1 | 337 | 5/25/2025 | 
| 2.5.8 | 5,163 | 4/18/2025 | 
| 2.5.6 | 1,678 | 4/9/2025 | 
| 2.5.5 | 3,073 | 4/4/2025 | 
| 2.5.3 | 422 | 4/3/2025 | 
| 2.5.2 | 330 | 4/2/2025 | 
| 2.4.7 | 600 | 4/2/2025 | 
| 2.4.6 | 4,655 | 3/23/2025 | 
| 2.4.5 | 1,021 | 3/22/2025 | 
| 2.4.4 | 335 | 3/22/2025 | 
| 2.4.3 | 7,535 | 3/13/2025 | 
| 2.4.2 | 989 | 3/12/2025 | 
| 2.4.1 | 435 | 3/11/2025 | 
| 2.4.0 | 566 | 3/10/2025 | 
| 2.3.0 | 1,719 | 3/1/2025 | 
| 2.2.0 | 2,053 | 2/23/2025 | 
| 2.1.5 | 445 | 2/22/2025 | 
| 2.1.4 | 734 | 2/22/2025 | 
| 2.0.14 | 1,177 | 2/19/2025 | 
| 2.0.11 | 565 | 2/18/2025 | 
| 2.0.8 | 290 | 2/18/2025 | 
| 2.0.7 | 494 | 2/17/2025 | 
| 2.0.6 | 491 | 2/17/2025 | 
| 2.0.4 | 550 | 2/16/2025 | 
| 2.0.3 | 224 | 2/16/2025 | 
| 2.0.2 | 347 | 2/16/2025 | 
| 2.0.1 | 195 | 2/16/2025 | 
| 2.0.0 | 3,142 | 2/16/2025 | 
| 1.0.2 | 97,577 | 7/14/2024 | 
| 1.0.1 | 41,983 | 6/6/2024 | 
| 1.0.0 | 1,381 | 5/22/2024 | 
| 0.1.20 | 2,394 | 4/29/2024 | 
| 0.1.19 | 10,413 | 4/4/2024 | 
| 0.1.18 | 352 | 4/3/2024 | 
| 0.1.17 | 183 | 4/3/2024 | 
| 0.1.16 | 176 | 4/3/2024 | 
| 0.1.15 | 656 | 2/25/2024 | 
| 0.1.14 | 3,273 | 2/24/2024 | 
| 0.1.13 | 176 | 2/24/2024 | 
| 0.1.12 | 8,392 | 12/19/2023 | 
| 0.1.11 | 219 | 12/19/2023 | 
| 0.1.10 | 201 | 12/19/2023 | 
| 0.1.9 | 214 | 12/18/2023 | 
| 0.1.7 | 175 | 12/18/2023 | 
| 0.1.6 | 192 | 12/18/2023 | 
| 0.1.5 | 207 | 12/18/2023 | 
| 0.1.4 | 197 | 12/18/2023 | 
| 0.1.3 | 200 | 12/18/2023 | 
| 0.1.2 | 206 | 12/18/2023 | 
| 0.1.1 | 217 | 12/18/2023 | 
| 0.1.0 | 329 | 12/17/2023 |