{"id":26328465,"url":"https://github.com/dprakash2101/geminisharp","last_synced_at":"2025-09-26T15:56:51.978Z","repository":{"id":277818086,"uuid":"929389808","full_name":"dprakash2101/GeminiSharp","owner":"dprakash2101","description":"C# client SDK for Google Gemini API","archived":false,"fork":false,"pushed_at":"2025-03-15T07:23:28.000Z","size":75,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T08:23:07.269Z","etag":null,"topics":["gemini","gemini-api","google","nuget-package","sdk"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/GeminiSharp/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dprakash2101.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-08T12:44:13.000Z","updated_at":"2025-02-18T11:55:49.000Z","dependencies_parsed_at":"2025-02-16T11:20:32.746Z","dependency_job_id":"e6560904-9f7a-40f7-bf95-571dc0a36c51","html_url":"https://github.com/dprakash2101/GeminiSharp","commit_stats":null,"previous_names":["dprakash2101/geminisharp"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dprakash2101%2FGeminiSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dprakash2101%2FGeminiSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dprakash2101%2FGeminiSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dprakash2101%2FGeminiSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dprakash2101","download_url":"https://codeload.github.com/dprakash2101/GeminiSharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243790995,"owners_count":20348385,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gemini","gemini-api","google","nuget-package","sdk"],"created_at":"2025-03-15T21:17:01.585Z","updated_at":"2025-09-26T15:56:51.966Z","avatar_url":"https://github.com/dprakash2101.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GeminiSharp - the C# library for the Google Gemini API\n\nComprehensive API for interacting with Google's Gemini models supporting text, chat, image generation, file uploads, grounding, code execution, model tuning, and more.\n\n## Frameworks supported\n\n## Dependencies\n\n- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.2 or later\n- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later\n- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.0.0 or later\n\nThe DLLs included in the package may not be the latest version. We recommend using [NuGet](https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages:\n```\nInstall-Package Newtonsoft.Json\nInstall-Package JsonSubTypes\nInstall-Package System.ComponentModel.Annotations\n```\n\n## Installation\n```sh\ndotnet add package GeminiSharp\n```\n\n## Usage\n\n### Connections\nEach ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method.\n\nTo better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see [here](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net) for details). To use your own HttpClient instance just pass it to the ApiClass constructor.\n\n```csharp\nHttpClientHandler yourHandler = new HttpClientHandler();\nHttpClient yourHttpClient = new HttpClient(yourHandler);\nvar api = new YourApiClass(yourHttpClient, yourHandler);\n```\n\nIf you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory.\n\n```csharp\nHttpClient yourHttpClient = new HttpClient();\nvar api = new YourApiClass(yourHttpClient);\n```\nYou'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available.\n\nHere an example of DI setup in a sample web project:\n\n```csharp\nservices.AddHttpClient\u003cYourApiClass\u003e(httpClient =\u003e\n   new PetApi(httpClient));\n```\n\n\n## Getting Started\n\n```csharp\nusing System.Collections.Generic;\nusing System.Diagnostics;\nusing System.Net.Http;\nusing GeminiSharp.Api;\nusing GeminiSharp.Client;\nusing GeminiSharp.Model;\nusing Serilog;\nusing Serilog.Sinks.Console;\n\nnamespace Example\n{\n    public class Example\n    {\n        public static void Main()\n        {\n            // Configure Serilog\n            Log.Logger = new LoggerConfiguration()\n                .MinimumLevel.Debug() // Set minimum logging level\n                .WriteTo.Console()    // Output logs to console\n                .CreateLogger();\n\n            Configuration config = new Configuration();\n            config.BasePath = \"https://generativelanguage.googleapis.com\";\n            // Assign the logger to the configuration\n            config.Logger = Log.Logger;\n            // Configure API key authorization: ApiKeyHeader\n            config.ApiKey.Add(\"x-goog-api-key\", \"YOUR_API_KEY\");\n            // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed\n            // config.ApiKeyPrefix.Add(\"x-goog-api-key\", \"Bearer\");\n            // Configure API key authorization: ApiKeyQuery\n            config.ApiKey.Add(\"key\", \"YOUR_API_KEY\");\n            // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed\n            // config.ApiKeyPrefix.Add(\"key\", \"Bearer\");\n\n            // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes\n            HttpClient httpClient = new HttpClient();\n            HttpClientHandler httpClientHandler = new HttpClientHandler();\n            var apiInstance = new GeminiApi(httpClient, config, httpClientHandler);\n            var model = \"model_example\";  // string | \n            var batchEmbedContentsRequest = new BatchEmbedContentsRequest(); // BatchEmbedContentsRequest | \n\n            try\n            {\n                // Batch Embed Contents\n                BatchEmbedContents200Response result = apiInstance.BatchEmbedContents(model, batchEmbedContentsRequest);\n                Debug.WriteLine(result);\n            }\n            catch (ApiException e)\n            {\n                Debug.Print(\"Exception when calling GeminiApi.BatchEmbedContents: \" + e.Message );\n                Debug.Print(\"Status Code: \"+ e.ErrorCode);\n                Debug.Print(e.StackTrace);\n            }\n            finally\n            {\n                Log.CloseAndFlush();\n            }\n        }\n    }\n}\n```\n\n## Advanced Features\n\nThis client includes several helpers to facilitate common tasks.\n\n### Retry Logic\n\nThe API client supports custom retry logic using the [Polly](https://github.com/App-vNext/Polly) library. You can define your own retry policies for handling transient network errors or other temporary issues.\n\nFor detailed instructions and examples, see the [Retry Logic Documentation](./docs/RetryLogic.md).\n\n### Logging\n\nThe client is instrumented with `Serilog` to provide detailed logging of API requests and responses. This is useful for debugging and monitoring. Logging is opt-in and can be configured by providing a logger instance.\n\nFor more details, see the [Logging Documentation](./docs/Logging.md).\n\n### JSON Schema Generation\n\nA utility is provided to generate JSON schemas from your C# model classes. This is especially useful for defining tools and functions for the Gemini API.\n\nFor more information, see the [JSON Schema Generation Documentation](./docs/JsonSchemaGenerator.md).\n\n### File to Base64 Conversion\n\nThe client includes a helper to easily convert files and streams to base64-encoded strings, which is useful for embedding file data in API requests.\n\nFor usage examples, see the [File to Base64 Conversion Documentation](./docs/FileConverter.md).\n\n\n## Documentation for API Endpoints\n\nAll URIs are relative to *https://generativelanguage.googleapis.com*\n\nClass | Method | HTTP request | Description\n------------ | ------------- | ------------- | -------------\n*GeminiApi* | [**BatchEmbedContents**](docs/GeminiApi.md#batchembedcontents) | **POST** /v1/models/{model}:batchEmbedContents | Batch Embed Contents\n*GeminiApi* | [**CancelOperation**](docs/GeminiApi.md#canceloperation) | **DELETE** /v1/operations/{name} | Cancel Operation\n*GeminiApi* | [**CountTokens**](docs/GeminiApi.md#counttokens) | **POST** /v1/models/{model}:countTokens | Count Tokens\n*GeminiApi* | [**CreateCachedContent**](docs/GeminiApi.md#createcachedcontent) | **POST** /v1/cachedContents | Create Cached Content\n*GeminiApi* | [**CreateChunk**](docs/GeminiApi.md#createchunk) | **POST** /v1/corpora/{corpus}/documents/{document}/chunks | Create Chunk\n*GeminiApi* | [**CreateCorpus**](docs/GeminiApi.md#createcorpus) | **POST** /v1/corpora | Create Corpus\n*GeminiApi* | [**CreateDocument**](docs/GeminiApi.md#createdocument) | **POST** /v1/corpora/{corpus}/documents | Create Document\n*GeminiApi* | [**CreateTunedModel**](docs/GeminiApi.md#createtunedmodel) | **POST** /v1/tunedModels | Create Tuned Model\n*GeminiApi* | [**DeleteCachedContent**](docs/GeminiApi.md#deletecachedcontent) | **DELETE** /v1/cachedContents/{name} | Delete Cached Content\n*GeminiApi* | [**DeleteChunk**](docs/GeminiApi.md#deletechunk) | **DELETE** /v1/corpora/{corpus}/documents/{document}/chunks/{chunk} | Delete Chunk\n*GeminiApi* | [**DeleteCorpus**](docs/GeminiApi.md#deletecorpus) | **DELETE** /v1/corpora/{name} | Delete Corpus\n*GeminiApi* | [**DeleteDocument**](docs/GeminiApi.md#deletedocument) | **DELETE** /v1/corpora/{corpus}/documents/{document} | Delete Document\n*GeminiApi* | [**DeleteFile**](docs/GeminiApi.md#deletefile) | **DELETE** /v1/files/{name} | Delete File\n*GeminiApi* | [**DeleteTunedModel**](docs/GeminiApi.md#deletetunedmodel) | **DELETE** /v1/tunedModels/{name} | Delete Tuned Model\n*GeminiApi* | [**EmbedContent**](docs/GeminiApi.md#embedcontent) | **POST** /v1/models/{model}:embedContent | Embed Content\n*GeminiApi* | [**GenerateContent**](docs/GeminiApi.md#generatecontent) | **POST** /v1/models/{model}:generateContent | Generate Content\n*GeminiApi* | [**GenerateImage**](docs/GeminiApi.md#generateimage) | **POST** /v1/models/{model}:generateImage | Generate Image\n*GeminiApi* | [**GetCachedContent**](docs/GeminiApi.md#getcachedcontent) | **GET** /v1/cachedContents/{name} | Get Cached Content\n*GeminiApi* | [**GetChunk**](docs/GeminiApi.md#getchunk) | **GET** /v1/corpora/{corpus}/documents/{document}/chunks/{chunk} | Get Chunk\n*GeminiApi* | [**GetCorpus**](docs/GeminiApi.md#getcorpus) | **GET** /v1/corpora/{name} | Get Corpus\n*GeminiApi* | [**GetDocument**](docs/GeminiApi.md#getdocument) | **GET** /v1/corpora/{corpus}/documents/{document} | Get Document\n*GeminiApi* | [**GetFile**](docs/GeminiApi.md#getfile) | **GET** /v1/files/{name} | Get File\n*GeminiApi* | [**GetModel**](docs/GeminiApi.md#getmodel) | **GET** /v1/models/{model} | Get Model\n*GeminiApi* | [**GetOperation**](docs/GeminiApi.md#getoperation) | **GET** /v1/operations/{name} | Get Operation\n*GeminiApi* | [**GetTunedModel**](docs/GeminiApi.md#gettunedmodel) | **GET** /v1/tunedModels/{name} | Get Tuned Model\n*GeminiApi* | [**ListCachedContents**](docs/GeminiApi.md#listcachedcontents) | **GET** /v1/cachedContents | List Cached Contents\n*GeminiApi* | [**ListChunks**](docs/GeminiApi.md#listchunks) | **GET** /v1/corpora/{corpus}/documents/{document}/chunks | List Chunks\n*GeminiApi* | [**ListCorpora**](docs/GeminiApi.md#listcorpora) | **GET** /v1/corpora | List Corpora\n*GeminiApi* | [**ListDocuments**](docs/GeminiApi.md#listdocuments) | **GET** /v1/corpora/{corpus}/documents | List Documents\n*GeminiApi* | [**ListFiles**](docs/GeminiApi.md#listfiles) | **GET** /v1/files | List Files\n*GeminiApi* | [**ListModels**](docs/GeminiApi.md#listmodels) | **GET** /v1/models | List Models\n*GeminiApi* | [**ListOperations**](docs/GeminiApi.md#listoperations) | **GET** /v1/operations | List Operations\n*GeminiApi* | [**ListTunedModels**](docs/GeminiApi.md#listtunedmodels) | **GET** /v1/tunedModels | List Tuned Models\n*GeminiApi* | [**QueryCorpus**](docs/GeminiApi.md#querycorpus) | **POST** /v1/corpora/{corpus}:query | Query Corpus\n*GeminiApi* | [**StreamGenerateContent**](docs/GeminiApi.md#streamgeneratecontent) | **POST** /v1/models/{model}:streamGenerateContent | Stream Generate Content\n*GeminiApi* | [**UpdateCachedContent**](docs/GeminiApi.md#updatecachedcontent) | **PATCH** /v1/cachedContents/{name} | Update Cached Content\n*GeminiApi* | [**UpdateChunk**](docs/GeminiApi.md#updatechunk) | **PATCH** /v1/corpora/{corpus}/documents/{document}/chunks/{chunk} | Update Chunk\n*GeminiApi* | [**UpdateCorpus**](docs/GeminiApi.md#updatecorpus) | **PATCH** /v1/corpora/{name} | Update Corpus\n*GeminiApi* | [**UpdateDocument**](docs/GeminiApi.md#updatedocument) | **PATCH** /v1/corpora/{corpus}/documents/{document} | Update Document\n*GeminiApi* | [**UpdateTunedModel**](docs/GeminiApi.md#updatetunedmodel) | **PATCH** /v1/tunedModels/{name} | Update Tuned Model\n*GeminiApi* | [**UploadFile**](docs/GeminiApi.md#uploadfile) | **POST** /v1/files | Upload File\n*GeminiApi* | [**UploadMedia**](docs/GeminiApi.md#uploadmedia) | **POST** /v1/media | Upload Media\n\n\n\n## Documentation for Models\n\n - [Model.ApiErrorResponse](docs/ApiErrorResponse.md)\n - [Model.ApiErrorResponseError](docs/ApiErrorResponseError.md)\n - [Model.AttributionSourceId](docs/AttributionSourceId.md)\n - [Model.BatchEmbedContents200Response](docs/BatchEmbedContents200Response.md)\n - [Model.BatchEmbedContentsRequest](docs/BatchEmbedContentsRequest.md)\n - [Model.BatchEmbedContentsRequestRequestsInner](docs/BatchEmbedContentsRequestRequestsInner.md)\n - [Model.CachedContent](docs/CachedContent.md)\n - [Model.CachedContentUsageMetadata](docs/CachedContentUsageMetadata.md)\n - [Model.Candidate](docs/Candidate.md)\n - [Model.CandidateLogprobs](docs/CandidateLogprobs.md)\n - [Model.Chunk](docs/Chunk.md)\n - [Model.ChunkData](docs/ChunkData.md)\n - [Model.CitationMetadata](docs/CitationMetadata.md)\n - [Model.CitationSource](docs/CitationSource.md)\n - [Model.CodeExecutionResult](docs/CodeExecutionResult.md)\n - [Model.Condition](docs/Condition.md)\n - [Model.ContentEmbedding](docs/ContentEmbedding.md)\n - [Model.Corpus](docs/Corpus.md)\n - [Model.CountTokens200Response](docs/CountTokens200Response.md)\n - [Model.CreateTunedModelRequest](docs/CreateTunedModelRequest.md)\n - [Model.CustomMetadata](docs/CustomMetadata.md)\n - [Model.Dataset](docs/Dataset.md)\n - [Model.Document](docs/Document.md)\n - [Model.DynamicRetrievalConfig](docs/DynamicRetrievalConfig.md)\n - [Model.EmbedContentRequest](docs/EmbedContentRequest.md)\n - [Model.ExecutableCode](docs/ExecutableCode.md)\n - [Model.File](docs/File.md)\n - [Model.FileData](docs/FileData.md)\n - [Model.FunctionCall](docs/FunctionCall.md)\n - [Model.FunctionCallingConfig](docs/FunctionCallingConfig.md)\n - [Model.FunctionDeclaration](docs/FunctionDeclaration.md)\n - [Model.FunctionResponse](docs/FunctionResponse.md)\n - [Model.GeminiModel](docs/GeminiModel.md)\n - [Model.GenerateContentRequest](docs/GenerateContentRequest.md)\n - [Model.GenerateContentResponse](docs/GenerateContentResponse.md)\n - [Model.GenerateImageRequest](docs/GenerateImageRequest.md)\n - [Model.GenerateImageResponse](docs/GenerateImageResponse.md)\n - [Model.GeneratedImage](docs/GeneratedImage.md)\n - [Model.GenerationConfig](docs/GenerationConfig.md)\n - [Model.GoogleSearchRetrieval](docs/GoogleSearchRetrieval.md)\n - [Model.GroundingAttribution](docs/GroundingAttribution.md)\n - [Model.GroundingChunk](docs/GroundingChunk.md)\n - [Model.GroundingChunkWeb](docs/GroundingChunkWeb.md)\n - [Model.GroundingMetadata](docs/GroundingMetadata.md)\n - [Model.GroundingPassageId](docs/GroundingPassageId.md)\n - [Model.GroundingSupport](docs/GroundingSupport.md)\n - [Model.Hyperparameters](docs/Hyperparameters.md)\n - [Model.InlineData](docs/InlineData.md)\n - [Model.ListCachedContents200Response](docs/ListCachedContents200Response.md)\n - [Model.ListChunks200Response](docs/ListChunks200Response.md)\n - [Model.ListCorpora200Response](docs/ListCorpora200Response.md)\n - [Model.ListDocuments200Response](docs/ListDocuments200Response.md)\n - [Model.ListFiles200Response](docs/ListFiles200Response.md)\n - [Model.ListModels200Response](docs/ListModels200Response.md)\n - [Model.ListOperations200Response](docs/ListOperations200Response.md)\n - [Model.ListTunedModels200Response](docs/ListTunedModels200Response.md)\n - [Model.LogprobsResult](docs/LogprobsResult.md)\n - [Model.MetadataFilter](docs/MetadataFilter.md)\n - [Model.Operation](docs/Operation.md)\n - [Model.PromptFeedback](docs/PromptFeedback.md)\n - [Model.QueryCorpusRequest](docs/QueryCorpusRequest.md)\n - [Model.QueryCorpusResponse](docs/QueryCorpusResponse.md)\n - [Model.RelevantChunk](docs/RelevantChunk.md)\n - [Model.RequestContent](docs/RequestContent.md)\n - [Model.RequestContentPart](docs/RequestContentPart.md)\n - [Model.ResponseContent](docs/ResponseContent.md)\n - [Model.ResponseContentPart](docs/ResponseContentPart.md)\n - [Model.RetrievalMetadata](docs/RetrievalMetadata.md)\n - [Model.SafetyRating](docs/SafetyRating.md)\n - [Model.SafetySetting](docs/SafetySetting.md)\n - [Model.SearchEntryPoint](docs/SearchEntryPoint.md)\n - [Model.Segment](docs/Segment.md)\n - [Model.SemanticRetrieverChunk](docs/SemanticRetrieverChunk.md)\n - [Model.Status](docs/Status.md)\n - [Model.StringList](docs/StringList.md)\n - [Model.Tool](docs/Tool.md)\n - [Model.ToolConfig](docs/ToolConfig.md)\n - [Model.TopCandidates](docs/TopCandidates.md)\n - [Model.TunedModel](docs/TunedModel.md)\n - [Model.TunedModelSource](docs/TunedModelSource.md)\n - [Model.TuningExample](docs/TuningExample.md)\n - [Model.TuningExamples](docs/TuningExamples.md)\n - [Model.TuningSnapshot](docs/TuningSnapshot.md)\n - [Model.TuningTask](docs/TuningTask.md)\n - [Model.UploadFileRequestMetadata](docs/UploadFileRequestMetadata.md)\n - [Model.UsageMetadata](docs/UsageMetadata.md)\n - [Model.VideoMetadata](docs/VideoMetadata.md)\n\n\n\n## Documentation for Authorization\n\nThe API key can be provided in two ways: as a header or as a query parameter. You only need to use one of these methods.\n\n### 1. As a Header (`ApiKeyHeader`)\n\n- **Type**: API key\n- **Header Name**: `x-goog-api-key`\n- **Location**: HTTP header\n\nExample configuration:\n```csharp\nvar config = new Configuration();\nconfig.ApiKey.Add(\"x-goog-api-key\", \"YOUR_API_KEY\");\n```\n\n### 2. As a Query Parameter (`ApiKeyQuery`)\n\n- **Type**: API key\n- **Parameter Name**: `key`\n- **Location**: URL query string\n\nExample configuration:\n```csharp\nvar config = new Configuration();\nconfig.ApiKey.Add(\"key\", \"YOUR_API_KEY\");\n```\n\n\n\n## Contributing\n\nWe welcome contributions! To get started:\n\n1. **Fork** the repository.\n2. **Create** a new branch (`feature-branch-name`).\n3. **Make** your changes and **commit** them.\n4. **Push** your branch to your fork.\n5. **Open** a Pull Request (PR) with a clear description of your changes.\n\nVisit the [issues section](https://github.com/dprakash2101/GeminiSharp/issues) to discuss ideas or report issues.\n\n\n## License\n\nThis project is licensed under the [MIT License](https://github.com/dprakash2101/GeminiSharp/blob/master/LICENSE).\n\n\n\n## Author\n\n**[Devi Prakash](https://github.com/dprakash2101)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdprakash2101%2Fgeminisharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdprakash2101%2Fgeminisharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdprakash2101%2Fgeminisharp/lists"}