{"id":18238182,"url":"https://github.com/patchoulish/kagi-dotnet","last_synced_at":"2025-04-11T12:12:05.266Z","repository":{"id":260715303,"uuid":"882066078","full_name":"patchoulish/kagi-dotnet","owner":"patchoulish","description":"A .NET library for interacting with the Kagi API","archived":false,"fork":false,"pushed_at":"2024-12-07T02:02:59.000Z","size":104,"stargazers_count":3,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T08:38:14.227Z","etag":null,"topics":["ai","api","dotnet","fastgpt","kagi","search","summarization","web-index"],"latest_commit_sha":null,"homepage":"","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/patchoulish.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-01T20:05:40.000Z","updated_at":"2024-12-29T04:14:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"b29fdb90-b193-4178-ad0d-4a2108189f21","html_url":"https://github.com/patchoulish/kagi-dotnet","commit_stats":null,"previous_names":["patchoulish/kagi-dotnet"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchoulish%2Fkagi-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchoulish%2Fkagi-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchoulish%2Fkagi-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patchoulish%2Fkagi-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patchoulish","download_url":"https://codeload.github.com/patchoulish/kagi-dotnet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247886901,"owners_count":21012918,"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":["ai","api","dotnet","fastgpt","kagi","search","summarization","web-index"],"created_at":"2024-11-05T03:04:17.067Z","updated_at":"2025-04-11T12:12:05.240Z","avatar_url":"https://github.com/patchoulish.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kagi-dotnet [![CI](https://github.com/patchoulish/kagi-dotnet/actions/workflows/ci.yml/badge.svg)](https://github.com/patchoulish/kagi-dotnet/actions/workflows/ci.yml)\nA .NET library for interacting with the [Kagi](https://kagi.com/) API.\n\n\n## Features\n- **API Coverage** – Full support for **`v0`** of the **Universal Summarizer**, **FastGPT**, **Search**, and **Enrichment** APIs.\n- **.NET Standards Compliant** – Adheres to .NET best practices and conventions.\n\n\n## Installation\nInstall the library via [NuGet](https://www.nuget.org/packages/kagi-dotnet):\n```bash\ndotnet add package kagi-dotnet\n```\n\n### Extensions\nInstall optional library extensions for more functionality, depending on your use case.\n#### Dependency Injection\nIntegrate gravatar-dotnet and your DI container of choice. Install the extension library via [NuGet](https://www.nuget.org/packages/kagi-dotnet-dependencyinjection):\n```bash\ndotnet add package kagi-dotnet-dependencyinjection\n```\n\n\n## Usage\n1. Obtain your API key from the [Kagi API portal](https://kagi.com/settings?p=api) (requires a Kagi account).\n2. Pass the API key into a new instance of the `KagiService` class or use a configured `HttpClient` if advanced configuration (e.g., proxies) is required.\n3. Use the methods available on `KagiService` to interact with the Kagi API.\n\n### Initialization\nThe library can be initialized in three ways:\n#### Basic Initialization\nPass in your API key directly:\n```csharp\nvar kagi = new KagiService(\"YOUR_KAGI_API_KEY\");\n```\n#### Advanced Initialization\nUse an existing `HttpClient`, ensuring that `BaseAddress` and an `Authorization` header have been set:\n```csharp\nvar httpClient = new HttpClient(\n\tnew KagiDelegatingHandler()\n\t{\n\t\tInnerHandler = new HttpClientHandler()\n\t},\n\tdisposeHandler: true)\n{\n\tBaseAddress = new Uri(\"https://kagi.com/api/v0/\"),\n\tTimeout = TimeSpan.FromSeconds(5)\n};\n\nhttpClient.DefaultRequestHeaders.Add(\n\t$\"Authorization\",\n\t$\"Bot YOUR_KAGI_API_KEY\");\n\nvar kagi = new KagiService(httpClient);\n```\n#### Dependency Injection\nIf you've installed the appropriate extension library.\n1. Register `KagiService` with your dependency container:\n```csharp\nservices.AddKagiHttpClient(options =\u003e\n{\n\toptions.BaseUrl = new Uri(\"https://kagi.com/api/v0/\");\n\toptions.ApiKey = \"YOUR_KAGI_API_KEY\";\n});\n```\n2. Inject `IKagiService` where needed:\n```csharp\npublic class MyClass\n{\n    private readonly IKagiService kagi;\n\n    public MyClass(IKagiService kagi)\n    {\n        this.kagi = kagi;\n    }\n}\n```\n\n### Summarization\nThe **Universal Summarizer API** uses large language models to generate summaries for various types of content.\n```csharp\nvar summarizeOptions = new KagiSummarizeOptions\n{\n    // Provide either a URL to summarize...\n    Url = new Uri(\"https://en.wikipedia.org/wiki/Kagi_(search_engine)\")\n\n    // ...or raw text content.\n    Text = \"Kagi is a paid ad-free search engine developed by Kagi Inc...\"\n};\n\nvar summarizeResult = await kagi.SummarizeAsync(summarizeOptions);\n\t\nConsole.WriteLine(summarizeResult.Data.Output);\n```\n\n### Search-augmented Q\u0026A\nThe **FastGPT API** combines Kagi’s search engine with language models to answer queries.\n```csharp\nvar answerOptions = new KagiAnswerOptions\n{\n    Query = \"What is the airspeed of a fully-laden swallow?\"\n};\n\nvar answerResult = await kagi.AnswerAsync(answerOptions);\n\nConsole.WriteLine(\n\t$\"{answerResult.Data.Output}\\n\\n\" +\n\t$\"References Used: {answerResult.Data.References.Length}\");\n```\n\n### Search\nThe **Search API** allows you to access Kagi’s search engine programmatically.\n\u003e [!NOTE]\n\u003e This API is currently in closed beta for business users.\n```csharp\nvar searchResults = await kagi.SearchAsync(\"weather today\", limit: 20);\n\nforeach (var item in searchResults.Data)\n{\n    if (item is KagiRecordSearchData record)\n    {\n        // Item contains a search result (i.e. with a URL, title, optional snippet, etc.)\n    }\n    else if (item is KagiRelatedQuerySearchData relatedQuery)\n    {\n        // Item contains a list of related queries\n    }\n}\n```\n\n### Enrichment APIs for Supplemental Content\nThe **Enrichment API** allows you to access unique web content from Kagi’s specialized indexes, Teclis (for web content) and TinyGem (for news). This API is designed to provide specialized, non-mainstream results and is ideal for enhancing broader search results.\n\n#### Web Enrichment\nRetrieve supplemental results focused on high-quality \"small web\" content.\n```csharp\nvar webEnrichmentResults = await kagi.GetWebEnrichmentsAsync(\"coffee blog\");\n\nforeach (var item in webEnrichmentResults.Data)\n{\n    // Processing similar to the Search API output\n}\n```\n\n#### News Enrichment\nRetrieve non-mainstream, high-quality news content relevant to your query.\n```csharp\nvar newsEnrichmentResults = await kagi.GetNewsEnrichmentsAsync(\"local news\");\n\nforeach (var item in newsEnrichmentResults.Data)\n{\n    // Processing similar to the Search API output\n}\n```\n\n\n## Documentation\nRefer to the [Usage](#usage) section above for a quick start, or consult the inline documentation while working in your IDE. For detailed information about the underlying API endpoints, parameters, and expected responses, refer to the [official Kagi API documentation](https://help.kagi.com/kagi/api/overview.html).\n\n\n## Contributing\nContributions are welcome! To contribute, fork the repository, create a new branch, and submit a pull request with your changes. Please make sure all tests pass before submitting.\n\n\n## License\nThis project is licensed under the MIT license. See `license.txt` for full details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatchoulish%2Fkagi-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatchoulish%2Fkagi-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatchoulish%2Fkagi-dotnet/lists"}