AlphaQuantum.WebsiteCategorizationAPI
1.0.0
See the version list below for details.
dotnet add package AlphaQuantum.WebsiteCategorizationAPI --version 1.0.0
NuGet\Install-Package AlphaQuantum.WebsiteCategorizationAPI -Version 1.0.0
<PackageReference Include="AlphaQuantum.WebsiteCategorizationAPI" Version="1.0.0" />
<PackageVersion Include="AlphaQuantum.WebsiteCategorizationAPI" Version="1.0.0" />
<PackageReference Include="AlphaQuantum.WebsiteCategorizationAPI" />
paket add AlphaQuantum.WebsiteCategorizationAPI --version 1.0.0
#r "nuget: AlphaQuantum.WebsiteCategorizationAPI, 1.0.0"
#:package AlphaQuantum.WebsiteCategorizationAPI@1.0.0
#addin nuget:?package=AlphaQuantum.WebsiteCategorizationAPI&version=1.0.0
#tool nuget:?package=AlphaQuantum.WebsiteCategorizationAPI&version=1.0.0
AlphaQuantum.WebsiteCategorizationAPI
Categorise web pages by topic from .NET. Send an article URL, get back IAB content categories with confidence scores, and use them for contextual advertising, brand safety or content analytics. This is the .NET 8 client for page topic classification for publishers.
dotnet add package AlphaQuantum.WebsiteCategorizationAPI
Classify a page
using AlphaQuantum.WebsiteCategorizationAPI;
var wca = new WebsiteCategorizationAPIClient(Environment.GetEnvironmentVariable("AQ_API_KEY")!);
var r = await wca.ClassifyAsync("https://example.com/travel/lisbon-weekend-guide");
foreach (var c in r["categories"].EnumerateArray())
Console.WriteLine($"T{c.GetProperty("tier")} {c.GetProperty("name").GetString()} {c.GetProperty("confidence").GetDouble():0.00}");
According to the published API reference, categories lists taxonomy nodes (id, name, tier, confidence), and meta carries a request ID and processing time. The client hands you the reply as Dictionary<string, JsonElement> without changing it.
Classify on publish, not on page view
An article's topic does not change between page views. The efficient pattern is one call when the article is published, and another only when its text changes. In an ASP.NET Core CMS, a Channel<T> plus a BackgroundService keeps the editor's save button fast:
public sealed class ClassificationQueue
{
private readonly Channel<(int ArticleId, string Url)> _ch = Channel.CreateUnbounded<(int, string)>();
public ValueTask EnqueueAsync(int id, string url) => _ch.Writer.WriteAsync((id, url));
public IAsyncEnumerable<(int ArticleId, string Url)> ReadAllAsync(CancellationToken ct) => _ch.Reader.ReadAllAsync(ct);
}
public sealed class ClassificationWorker(ClassificationQueue q, WebsiteCategorizationAPIClient wca, IArticleStore store)
: BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken ct)
{
await foreach (var (id, url) in q.ReadAllAsync(ct))
{
try { await store.SaveCategoriesAsync(id, await wca.ClassifyAsync(url, ct)); }
catch (ApiException ex) when (ex.StatusCode == 429) { await Task.Delay(30_000, ct); await q.EnqueueAsync(id, url); }
}
}
}
Your publish handler calls EnqueueAsync. Categories are usually stored before the first reader arrives.
Sending topics to the ad server
Ad servers accept key-values with each ad request. A short list of confident category IDs is enough:
static string[] TopicKeys(Dictionary<string, JsonElement> r, double floor = 0.5, int max = 2) =>
r["categories"].EnumerateArray()
.Where(c => c.GetProperty("confidence").GetDouble() >= floor)
.OrderByDescending(c => c.GetProperty("confidence").GetDouble())
.Take(max)
.Select(c => c.GetProperty("id").ToString())
.ToArray();
Store the keys with the article and render them into the page's ad tag. Targeting then follows content, not cookies.
Brand safety needs a lower bar
For targeting, a moderate threshold is fine. For brand safety, inspect every returned category, including low-confidence ones, and send borderline pages to a person. Keep the full reply on record so reviewers can see what the classifier saw.
Tiers in reporting
Tier 1 gives about two dozen broad topics, which is right for dashboards and executive reports. Tier 2 adds the detail sales teams sell against. Deeper tiers matter mostly for brand safety lists. Store everything once, then choose the depth in each report.
Thin pages
Galleries, video-only pages, paywalled articles and script-heavy apps give a classifier little text. If a page returns weak categories, classify the site's section page or the bare domain, and reuse that label for the thin pages beneath it.
Reference
- Constructor:
WebsiteCategorizationAPIClient(string apiKey, HttpClient? httpClient = null, string baseUrl = "https://www.websitecategorizationapi.com/api"). Without anHttpClient, a 30 second timeout applies. - Method:
Task<Dictionary<string, JsonElement>> ClassifyAsync(string value, CancellationToken ct = default). - Errors:
ArgumentExceptionfor empty key or input,ApiException(StatusCode,Body) for HTTP failures,TaskCanceledExceptionfor timeouts.
The key is sent in the form body over HTTPS, as the endpoint expects.
Testing
Build the client on an HttpClient whose handler returns a fixed JSON reply, then test your queue worker and key selection without network access. The package ships tests that do this, including a check that a 429 becomes an ApiException with status 429.
Neighbouring data
Topics describe content. Other questions need other sources:
- A topic taxonomy will not single out AI products. For a separate label for AI product sites, use the AI register.
- Security and compliance teams can build a an inventory of AI tools built from logs you keep.
- For large domain lists that only need site-level labels, site-level categories as a downloadable file cost less than per-call classification.
- Network teams enforcing rules should use policy categories for DNS filtering rather than content topics.
Other clients
websitecategorizationapi-go for Go services, the websitecategorization npm package for Node.js, and the Composer package for PHP sites.
License
MIT. IAB taxonomy names belong to IAB Technology Laboratory and are mentioned for compatibility only.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.