A .NET library for interacting with the Kagi API.
- API Coverage – Full support for
v0
of the Universal Summarizer, FastGPT, Search, and Enrichment APIs. - .NET Standards Compliant – Adheres to .NET best practices and conventions.
Install the library via NuGet:
dotnet add package kagi-dotnet
Install optional library extensions for more functionality, depending on your use case.
Integrate gravatar-dotnet and your DI container of choice. Install the extension library via NuGet:
dotnet add package kagi-dotnet-dependencyinjection
- Obtain your API key from the Kagi API portal (requires a Kagi account).
- Pass the API key into a new instance of the
KagiService
class or use a configuredHttpClient
if advanced configuration (e.g., proxies) is required. - Use the methods available on
KagiService
to interact with the Kagi API.
The library can be initialized in three ways:
Pass in your API key directly:
var kagi = new KagiService("YOUR_KAGI_API_KEY");
Use an existing HttpClient
, ensuring that BaseAddress
and an Authorization
header have been set:
var httpClient = new HttpClient(
new KagiDelegatingHandler()
{
InnerHandler = new HttpClientHandler()
},
disposeHandler: true)
{
BaseAddress = new Uri("https://kagi.com/api/v0/"),
Timeout = TimeSpan.FromSeconds(5)
};
httpClient.DefaultRequestHeaders.Add(
$"Authorization",
$"Bot YOUR_KAGI_API_KEY");
var kagi = new KagiService(httpClient);
If you've installed the appropriate extension library.
- Register
KagiService
with your dependency container:
services.AddKagiHttpClient(options =>
{
options.BaseUrl = new Uri("https://kagi.com/api/v0/");
options.ApiKey = "YOUR_KAGI_API_KEY";
});
- Inject
IKagiService
where needed:
public class MyClass
{
private readonly IKagiService kagi;
public MyClass(IKagiService kagi)
{
this.kagi = kagi;
}
}
The Universal Summarizer API uses large language models to generate summaries for various types of content.
var summarizeOptions = new KagiSummarizeOptions
{
// Provide either a URL to summarize...
Url = new Uri("https://en.wikipedia.org/wiki/Kagi_(search_engine)")
// ...or raw text content.
Text = "Kagi is a paid ad-free search engine developed by Kagi Inc..."
};
var summarizeResult = await kagi.SummarizeAsync(summarizeOptions);
Console.WriteLine(summarizeResult.Data.Output);
The FastGPT API combines Kagi’s search engine with language models to answer queries.
var answerOptions = new KagiAnswerOptions
{
Query = "What is the airspeed of a fully-laden swallow?"
};
var answerResult = await kagi.AnswerAsync(answerOptions);
Console.WriteLine(
$"{answerResult.Data.Output}\n\n" +
$"References Used: {answerResult.Data.References.Length}");
The Search API allows you to access Kagi’s search engine programmatically.
Note
This API is currently in closed beta for business users.
var searchResults = await kagi.SearchAsync("weather today", limit: 20);
foreach (var item in searchResults.Data)
{
if (item is KagiRecordSearchData record)
{
// Item contains a search result (i.e. with a URL, title, optional snippet, etc.)
}
else if (item is KagiRelatedQuerySearchData relatedQuery)
{
// Item contains a list of related queries
}
}
The 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.
Retrieve supplemental results focused on high-quality "small web" content.
var webEnrichmentResults = await kagi.GetWebEnrichmentsAsync("coffee blog");
foreach (var item in webEnrichmentResults.Data)
{
// Processing similar to the Search API output
}
Retrieve non-mainstream, high-quality news content relevant to your query.
var newsEnrichmentResults = await kagi.GetNewsEnrichmentsAsync("local news");
foreach (var item in newsEnrichmentResults.Data)
{
// Processing similar to the Search API output
}
Refer to the 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.
Contributions 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.
This project is licensed under the MIT license. See license.txt
for full details.