![]() |
VOOZH | about |
dotnet add package Mscc.GenerativeAI.Web --version 3.1.0
NuGet\Install-Package Mscc.GenerativeAI.Web -Version 3.1.0
<PackageReference Include="Mscc.GenerativeAI.Web" Version="3.1.0" />
<PackageVersion Include="Mscc.GenerativeAI.Web" Version="3.1.0" />Directory.Packages.props
<PackageReference Include="Mscc.GenerativeAI.Web" />Project file
paket add Mscc.GenerativeAI.Web --version 3.1.0
#r "nuget: Mscc.GenerativeAI.Web, 3.1.0"
#:package Mscc.GenerativeAI.Web@3.1.0
#addin nuget:?package=Mscc.GenerativeAI.Web&version=3.1.0Install as a Cake Addin
#tool nuget:?package=Mscc.GenerativeAI.Web&version=3.1.0Install as a Cake Tool
Integrate Gemini API into your web projects. It works both Google AI (Studio) and Google Cloud Vertex AI.
Client for ASP.NET Core:
👁 NuGet Version
👁 NuGet Downloads
Either create a new ASP.NET Core project or use an existing one.
> dotnet new web -o Web.Minimal.Api
Navigate to the project's root folder and install the package Mscc.GenerativeAI.Web from NuGet. You can install the package from the command line using either the command line or the NuGet Package Manager Console. Or you add it directly to your .NET project.
Add the package using the dotnet command line tool in your .NET project folder.
> dotnet add package Mscc.GenerativeAI.Web
Working with Visual Studio use the NuGet Package Manager to install the package Mscc.GenerativeAI.Web.
PM> Install-Package Mscc.GenerativeAI.Web
Alternatively, add the following line to your .csproj file.
<ItemGroup>
<PackageReference Include="Mscc.GenerativeAI.Web" Version="3.1.0" />
</ItemGroup>
You can then add this code to your sources whenever you need to access any Gemini API provided by Google. This package works currently for Google AI (Google AI Studio) only. Use with Google Cloud Vertex AI is provided by the underlying Mscc.GenerativeAI package but not exposed yet.
Working with Google AI in your application requires an API key. Get an API key from Google AI Studio.
Add the following configuration to the appsettings.json file.
{
// section name and location to your liking.
"Gemini": {
"Credentials": {
"ApiKey": "YOUR_API_KEY" // replace value with key from AI Studio
},
"ProjectId": "",
"Region": "us-central1",
"Model": "gemini-1.5-pro" // default value
},
// any other settings...
"Logging": {
},
}
The section name Gemini is arbitrary as well as the location of the section. Although, it needs to be referenced correctly in the Configuration builder.
AddGenerativeAI serviceNext, add the service AddGenerativeAI() to the ASP.NET Core web app and map the routes as needed. Following is the most minimal implementation.
using Mscc.GenerativeAI.Web;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGenerativeAI(builder.Configuration.GetSection("Gemini"));
var app = builder.Build();
app.MapGet("/", async (IGenerativeModelService service) =>
{
var model = service.CreateInstance();
var result = await model.GenerateContent("Write about the history of Mauritius.");
return result.Text;
});
app.Run();
There are overloads of the extension method AddGenerativeAI() according to Options pattern guidance for .NET library authors.
Following approaches are available:
Hoping this provides enough flexibility for individual preferences.
HttpClientAlternatively to the above described service extension methods Mscc.GenerativeAI.Web also provides a typed HttpClient that can be added to your ASP.NET web application.
sing Mscc.GenerativeAI.Web;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpClient<GenerativeAIClient>()
{
BaseAddress = "";
};
var app = builder.Build();
app.MapGet("/", async (IGenerativeModelService service) =>
{
var model = service.CreateInstance();
var result = await model.GenerateContent("Write about the history of Mauritius.");
return result.Text;
});
app.Run();
Keeping the code base minimal, one should consider creating a GlobalUsings.cs file and define the using statements there.
global using Mscc.GenerativeAI.Web;
This approach renders repetitive use of using Mscc.GenerativeAI.Web; in each .cs file obsolete.
Find each approach documented. Surrounding source code skipped for brevity.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGenerativeAI();
var app = builder.Build();
// ...
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGenerativeAI(builder.Configuration.GetSection("Gemini"));
var app = builder.Build();
// ...
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGenerativeAI("Gemini");
var app = builder.Build();
// ...
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGenerativeAI(options =>
{
// User defined option values
options.ProjectId = string.Empty;
options.Model = GenerativeAI.Types.Model.GeminiProVision;
options.Credentials.ApiKey = "YOUR_API_KEY";
});
var app = builder.Build();
// ...
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGenerativeAI(new GenerativeAIOptions
{
// Specify option values
ProjectId = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID"),
Region = Environment.GetEnvironmentVariable("GOOGLE_REGION"),
Model = Environment.GetEnvironmentVariable("GOOGLE_MODEL"),
Credentials = new() { ApiKey = Environment.GetEnvironmentVariable("GOOGLE_API_KEY") }
});
var app = builder.Build();
// ...
The choice of configuring the service is yours.
The folders and contain more examples.
tba
You can create issues at the https://github.com/mscraftsman/generative-ai repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.1.0 | 654 | 3/2/2026 |
| 3.0.2 | 6,077 | 12/31/2025 |
| 3.0.1 | 122 | 12/29/2025 |
| 3.0.0 | 346 | 12/16/2025 |
| 2.9.8 | 837 | 12/10/2025 |
| 2.9.7 | 463 | 12/8/2025 |
| 2.9.6 | 434 | 12/8/2025 |
| 2.9.5 | 438 | 12/8/2025 |
| 2.9.4 | 794 | 12/3/2025 |
| 2.9.3 | 533 | 11/18/2025 |
| 2.9.2 | 416 | 11/17/2025 |
| 2.9.1 | 329 | 11/11/2025 |
| 2.9.0 | 475 | 11/11/2025 |
| 2.8.25 | 5,589 | 11/5/2025 |
| 2.8.24 | 409 | 11/2/2025 |
| 2.8.23 | 541 | 10/31/2025 |
| 2.8.22 | 222 | 10/30/2025 |
| 2.8.21 | 208 | 10/29/2025 |
| 2.8.20 | 374 | 10/28/2025 |
| 2.8.19 | 774 | 10/20/2025 |
# Changelog (Release Notes)
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
### Changed
### Fixed
## 3.1.0
### Changed
- bump version
## 3.0.2
### Changed
- bump version
## 3.0.1
### Changed
- bump version
## 3.0.0
see main Changelog
## 2.9.8
### Added
- add constructor parameter `accessToken` #157 (81ad7f9)
### Changed
- bump version
## 2.9.7
### Changed
- bump version
## 2.9.6
### Changed
- bump version
## 2.9.5
### Changed
- bump version
## 2.9.4
### Changed
- bump version
## 2.9.3
### Changed
- bump version
## 2.9.2
### Changed
- bump version
## 2.9.1
### Added
- add .NET 10.0 targeting
### Changed
- bump version
## 2.9.0
### Changed
- bump version
## 2.8.25
### Changed
- bump version
## 2.8.24
### Changed
- bump version
## 2.8.23
### Changed
- bump version
## 2.8.22
### Changed
- bump version
## 2.8.21
### Changed
- bump version
## 2.8.20
### Changed
- bump version
## 2.8.19
### Changed
- bump version
## 2.8.18
### Changed
- bump version
## 2.8.17
### Changed
- bump version
## 2.8.16
### Changed
- bump version
## 2.8.15
### Changed
- bump version
## 2.8.14
### Changed
- bump version
## 2.8.13
### Changed
- bump version
## 2.8.12
### Changed
- bump version
## 2.8.11
### Changed
- bump version
## 2.8.10
### Changed
- bump version
## 2.8.9
### Changed
- bump version
## 2.8.8
### Changed
- bump version
## 2.8.7
### Changed
- bump version
## 2.8.6
### Changed
- bump version
## 2.8.5
### Changed
- bump version
## 2.8.4
### Changed
- bump version
## 2.8.3
### Changed
- bump version
## 2.8.2
### Changed
- bump version
## 2.8.1
### Changed
- bump version
## 2.8.0
### Changed
- bump version
## 2.7.1
### Changed
- bump version
## 2.7.0
### Added
- add `location` key to service options
### Changed
- bump version
## 2.6.13
### Changed
- bump version
## 2.6.12
### Changed
- no code changes
## 2.6.11
### Changed
- bump version
## 2.6.10
### Changed
- bump version
## 2.6.9
### Changed
- bump version
## 2.6.8
### Changed
## 2.6.7
### Changed
- bump version
## 2.6.6
### Changed
- bump version
## 2.6.5
### Changed
- bump version
## 2.6.4
### Changed
- bump version
## 2.6.3
### Changed
- bump version
## 2.6.2
### Changed
- bump version
## 2.6.1
### Changed
- bump version
## 2.6.0
### Changed
- bump version
## 2.5.6
### Changed
- bump version
## 2.5.5
### Changed
- bump version
## 2.5.4
### Changed
- bump version
## 2.5.3
### Changed
- bump version
## 2.5.2
### Changed
- bump version
## 2.5.1
### Changed
- bump version
## 2.5.0
### Changed
- bump version
## 2.4.1
### Changed
- bump version
## 2.4.0
### Changed
- bump version
## 2.3.6
### Changed
- bump version
## 2.3.5
### Changed
- bump version
## 2.3.4
### Changed
- bump version
## 2.3.3
### Changed
- use named parameters due to overloaded constructor
- bump version
## 2.3.2
### Changed
- bump version
## 2.3.1
### Changed
- bump version
## 2.3.0
### Changed
- update NuGet packages
- bump version
## 2.2.11
### Changed
- bump version
## 2.2.10
### Changed
- bump version
## 2.2.9
### Changed
- bump version
## 2.2.8
### Changed
- bump version
## 2.2.7
### Changed
- bump version
## 2.2.6
### Changed
- bump version
## 2.2.5
### Changed
- update NuGet packages
- bump version
## 2.2.4
### Changed
- update NuGet packages
- bump version
## 2.2.3
### Changed
- bump version
## 2.2.2
### Changed
- update NuGet packages
## 2.2.1
### Changed
- bump version
## 2.2.0
### Changed
- bump version
## 2.1.8
### Changed
- bump version
## 2.1.7
### Changed
- bump version
## 2.1.6
### Changed
- bump version
## 2.1.5
### Changed
- bump version
## 2.1.4
### Changed
- bump version
## 2.1.3
### Changed
- bump version
## 2.1.2
### Changed
- bump version
## 2.1.1
### Changed
- bump version
## 2.1.0
### Changed
- update NuGet packages
- drop .NET 6.0 targeting
## 2.0.2
### Changed
- bump version
## 2.0.1
### Changed
- bump version
## 2.0.0
### Changed
## 1.9.7
### Changed
- bump version
## 1.9.6
### Changed
- update NuGet packages
- bump version
## 1.9.5
### Changed
- bump version
## 1.9.4
### Changed
- bump version
## 1.9.3
### Changed
- bump version
## 1.9.2
### Changed
- bump version
## 1.9.1
### Changed
- update NuGet package(s)
## 1.9.0
### Changed
- bump version
## 1.8.3
### Changed
- bump version
## 1.8.2
### Changed
- bump version
## 1.8.1
### Changed
- bump version
## 1.8.0
### Changed
- bump version
## 1.7.0
### Changed
- bump version
## 1.6.5
### Changed
- bump version
## 1.6.4
### Changed
- bump version
## 1.6.3
### Changed
- bump version
## 1.6.2
### Changed
- bump version
## 1.6.1
### Changed
- bump version
## 1.6.0
### Changed
- bump version
## 1.5.1
### Changed
- Update System.Text.Json to 8.0.4
## 1.5.0
### Changed
- bump version
## 1.4.0
### Changed
- bump version
## 1.3.0
### Changed
- bump version
## 1.2.0
### Changed
- bump version
## 1.1.4
### Changed
- bump version
## 1.1.3
### Changed
- bump version
## 1.1.2
### Changed
- bump version
## 1.1.1
### Changed
- bump version
## 1.1.0
### Added
- implement generic access to GenerativeModel
### Changed
- bump version
## 1.0.1
### Changed
- bump version
## 1.0.0
### Changed
- bump version
## 0.9.4
### Changed
- bump version
## 0.9.3
### Changed
- bump version
## 0.9.2
### Changed
- bump version
## 0.9.1
### Changed
- use GoogleAI type to create model reference
- increase package reference
- bump version
## 0.9.0
### Changed
- bump version
## 0.8.4
### Changed
- bump version
## 0.8.3
### Changed
- bump version
## 0.8.2
### Changed
- bump version
## 0.8.1
### Changed
- bump version
## 0.8.0
### Changed
- bump version
## 0.7.1
### Changed
- bump version
## 0.5.1
### Changed
- Update package reference
## 0.5.0
### Added
- Initial implementation