SVSANNVIT
SDKs

C# SDK

Install and use the ledger's C# SDK — manual capture API.

The C# SDK (sdk/csharp/Ledger.Sdk) covers the manual Record API. OTel-instrumented .NET apps should point their existing exporter at the ledger's OTLP receiver (/v1/otlp/v1/traces) instead of reaching for a span processor here.

Install

Not yet published to NuGet. Reference the project directly for now:

dotnet add reference <path-to-repo>/sdk/csharp/Ledger.Sdk/Ledger.Sdk.csproj

Quick start

using Ledger.Sdk;

var ledger = new LedgerClient(
    apiUrl: "http://127.0.0.1:4010",
    ingestKey: ingestKey,
    agentId: "urn:agent:research-assistant"
);
ledger.SetTrigger("human", "person@example.com");

var started = DateTimeOffset.UtcNow.AddSeconds(-1);
var ended = DateTimeOffset.UtcNow;

var spanId = ledger.Record(new RecordInput
{
    ActionType = "llm_call",
    Provider = "anthropic",
    Model = "claude-fable-5",
    StartedAt = started,
    EndedAt = ended,
    Status = "success",
    Usage = new Usage(TokensIn: 420, TokensOut: 180),
    Payloads = new[] { new Payload("response", Content: "The policy provides that…") },
});

ledger.Flush();

Record never throws into the host application — failures go to ledger.OnError instead. Trigger, Payload, Retrieval, ContextRef, and Usage are all C# records, so they're immutable and support with-expressions.

Decision lineage

Set RecordInput.ParentRef (and HasParentRef = true) to cite the span that caused this event — omit both to fall back to the ambient/default attribution.

Flushing

Flush() delivers buffered events and is safe to call on a timer or before shutdown. Delivery is at-least-once — the server dedups by span id.