Recapi 0.1.2
See the version list below for details.
dotnet add package Recapi --version 0.1.2
NuGet\Install-Package Recapi -Version 0.1.2
<PackageReference Include="Recapi" Version="0.1.2" />
<PackageVersion Include="Recapi" Version="0.1.2" />
<PackageReference Include="Recapi" />
paket add Recapi --version 0.1.2
#r "nuget: Recapi, 0.1.2"
#:package Recapi@0.1.2
#addin nuget:?package=Recapi&version=0.1.2
#tool nuget:?package=Recapi&version=0.1.2
recapi for .NET
C# client for the recapi recommendation API. .NET 8 or newer, standard
library only (HttpClient, System.Text.Json), no NuGet dependency.
Like the Python and Go libraries,
it keeps each user's decayed history
(docs/history-spec.md) and sends it with every
recommendation request, sends events in the background (within 2 s, a
full batch of 1,000 at once) with retries, falls back to popular items when recapi is slow or failing,
and attributes events on recommended items to the recommendation that
showed them (the dashboard's clicks and conversions). It passes the shared
vectors in spec/.
Apps published trimmed (PublishTrimmed) or as Native AOT (PublishAot) are
supported, with no IL warning from the library: checked on .NET 8 and .NET 10.
Install
The library is the NuGet package Recapi (production releases publish it:
docs/deployment.md):
dotnet add package Recapi
Without access to NuGet, the API serves the library's project (Recapi/:
the .csproj and its .cs files, no tests) as a zip: unzip it next to your
project and reference it. The dashboard's quick start shows the URL with
your address.
curl -fLo recapi-csharp.zip https://api.<your-domain>/sdk/csharp/recapi-csharp-0.1.2.zip
unzip -o recapi-csharp.zip -d vendor
dotnet add reference vendor/Recapi/Recapi.csproj
In ASP.NET Core, register one client for the process; the container disposes it at shutdown, which sends the events still queued:
builder.Services.AddSingleton(_ => new RecapiClient("rk_sec_…", "https://api.example.com"));
Quick start
using Recapi;
// A secret key (rk_sec_…): it stays on your server. One client per process
// (a singleton in dependency injection); dispose it at exit.
await using var client = new RecapiClient("rk_sec_…", "https://api.example.com");
// Levels: Levels.View, Cart, Purchase, Reject, or any integer from -10 to 10.
// Queued: the background sender sends it within 2 s.
await client.TrackAsync(new RecapiEvent { ItemId = "sku-42", Level = Levels.View, UserId = "cust-881" });
var recs = await client.RecommendAsync(new RecommendRequest { UserId = "cust-881", Count = 4 });
foreach (var item in recs.Items)
{
// Metadata: the item's stored object, or null. Why: why it is listed
// ("for_you", "similar", "bought_together"...; docs/api.md "Reason codes"):
// map the codes you want to a label, show none for one you don't map.
Console.WriteLine($"{item.ItemId} {item.Metadata?["name"]} {item.Why}");
}
Calls
Each takes an optional CancellationToken. A refused argument (an invalid
id or level) throws ArgumentException; an API failure a RecapiException
(Code, Status, RetryAfter, Retryable, Outage).
| Call | What it does |
|---|---|
TrackAsync(RecapiEvent) |
Records an interaction: Level -10 to 10 (Levels.View 3, Cart 5, Purchase 10, Reject -10; Levels.Parse("view") reads a name). The history changes at once; the event is queued, and a background sender sends the queue every FlushInterval (2 s), a full batch at once. After a failed send it waits twice as long each time, up to a minute. |
FlushAsync() |
Sends the queued events now, 1,000 per request (the end of a job or a serverless handler). A network error, 429 or 5xx is retried 3 times (0.5 s, 1 s, 2 s with jitter, or the Retry-After, at most 8 s), then the events stay queued; a batch over the API's body limit (413) is sent in halves; any other error drops them (logged). |
DisposeAsync() |
Stops the sender and sends what is queued, one try per batch, so a deploy never waits on an outage. An event tracked afterwards is sent at once, one try. |
RecommendAsync(RecommendRequest) |
A list for UserId or AnonId, with Count, Placement, TagsAny, TagsAll, Exclude, ContextItemId, Discovery. At most 1.5 s; on a network error, timeout or 5xx it returns popular items (Fallback, no id), or no item when recapi is down. A 4xx or 429 throws. |
IdentifyAsync(anonId, userId) |
At login: the visitor's history and shown items become the user's. The user's first restore from recapi then leaves that visitor's browsing out, so it doesn't count twice. |
PopularAsync(PopularRequest) |
Popular items, for pages without a user. |
UpsertItemsAsync(CatalogItem[]) |
Creates or replaces items (ItemId, Title, Tags, Metadata…), 1,000 per request, retried like events. |
DeleteUserAsync(userId) |
Erases a user's events in recapi and their state in the store, retried like events. |
new RecapiOptions { Store, Timeout, FlushInterval, MaxBatch, Log } sets the options. The
default MemoryStore keeps the 10,000 most recent users in the process;
implement IRecapiStore (GetAsync, SetAsync, DeleteAsync) over Redis
or a database table when several processes serve the same users. It stores
the same JSON as the Python and Go libraries, so they can share one store.
Failures the client handles itself go to Log (default
System.Diagnostics.Trace).
Development
./test.sh [filter] builds the library and runs its tests (make test-sdk
does), against a fake API on a raw socket; make lint checks the format
with dotnet format, and the build treats warnings as errors. It also packs
the NuGet package (Recapi/bin/Release/Recapi.<version>.nupkg, metadata in
Recapi/Directory.Build.props), which PackageTests checks.
scripts/dotnet.sh uses a local .NET 8+ SDK, else fetches Microsoft's .NET
8 SDK once into ~/.cache/recapi. The tests use their own runner
(Recapi.Tests/Runner.cs): every public static Test* method runs, so no
NuGet download is needed.
RECAPI_KEY=rk_sec_… ../../scripts/dotnet.sh run --project Sample [item ids]
runs Sample/Program.cs against staging (RECAPI_URL
picks another API): it tracks views of a new visitor, then prints their
recommendations and the popular items. ./test.sh builds it.
| 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.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.17 | 0 | 12/4/2026 |
| 0.1.16 | 51 | 12/2/2026 |
| 0.1.15 | 103 | 11/24/2026 |
| 0.1.14 | 95 | 11/22/2026 |
| 0.1.13 | 96 | 11/22/2026 |
| 0.1.12 | 102 | 11/19/2026 |
| 0.1.11 | 99 | 11/19/2026 |
| 0.1.10 | 107 | 11/15/2026 |
| 0.1.9 | 100 | 11/14/2026 |
| 0.1.8 | 102 | 11/7/2026 |
| 0.1.7 | 97 | 11/7/2026 |
| 0.1.6 | 94 | 11/5/2026 |
| 0.1.5 | 94 | 11/4/2026 |
| 0.1.4 | 94 | 11/4/2026 |
| 0.1.3 | 99 | 11/4/2026 |
| 0.1.2 | 103 | 11/4/2026 |
| 0.1.1 | 103 | 11/2/2026 |
| 0.1.0 | 100 | 11/2/2026 |