Paid 0.1.0

dotnet add package Paid --version 0.1.0
                    
NuGet\Install-Package Paid -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Paid" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Paid" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Paid" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Paid --version 0.1.0
                    
#r "nuget: Paid, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Paid@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Paid&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Paid&version=0.1.0
                    
Install as a Cake Tool

nuget

The official .NET library for the Paid API. Use it to send usage events (signals) and to read customers, credits, orders and invoices from C#.

The package has builds for .NET 8, .NET 9, .NET Framework 4.6.2 and later, and .NET Standard 2.0. See Target frameworks before you configure the client in a .NET Standard library.

Install

dotnet add package Paid

Authenticate

Create an API key in the Paid dashboard and pass it to the client. Keep the key out of source code, for example in an environment variable.

using Paid;

var client = new PaidClient(Environment.GetEnvironmentVariable("PAID_API_KEY"));

The client sends the key as Authorization: Bearer <key> to https://api.agentpaid.io/api/v2. Create one client and reuse it.

Every method returns something you await directly. If you need a real Task, for example for Task.WhenAll, call .WithRawResponse() and read .Data: casting the call to Task<T> instead wraps any error in an AggregateException.

var calls = new[] { "acme-corp", "globex" }.Select(id =>
    client.Customers.GetCustomerCreditBalancesByExternalIdAsync(
        new GetCustomerCreditBalancesByExternalIdRequest { ExternalId = id }).WithRawResponse());
var answers = await Task.WhenAll(calls);
var acmeBalances = answers[0].Data;

Send signals in bulk

A signal is one usage event. Send up to 500 in one call. Give each signal an idempotency key. If a call fails and you are not sure it reached Paid, send it again with the same keys: Paid counts a repeated key as a duplicate instead of storing the signal twice.

var result = await client.Signals.CreateSignalsAsync(new BulkSignalsRequest
{
    Signals = new List<Signal>
    {
        new Signal
        {
            EventName = "email_sent",
            Customer = new CustomerByExternalId { ExternalCustomerId = "acme-corp" },
            Attribution = new ProductByExternalId { ExternalProductId = "email-agent" },
            Timestamp = DateTime.UtcNow,
            Data = new Dictionary<string, object?> { { "recipients", 3 } },
            IdempotencyKey = "email_sent_msg_8f3a2c",
        },
        new Signal
        {
            EventName = "email_sent",
            CustomerUnit = new CustomerUnitAttribution { ExternalCustomerUnitId = "acme-marketing" },
            IdempotencyKey = "email_sent_msg_9b41d7",
        },
    },
});

Console.WriteLine($"{result.Ingested} stored, {result.Duplicates} duplicates, {result.Failed} failed");

Each signal names its customer (CustomerByExternalId or CustomerById), its customer unit, or both. Leave Timestamp out to use the time Paid receives the signal.

Always pass timestamps in UTC (DateTime.UtcNow, or a DateTime with DateTimeKind.Utc): a DateTime of unspecified kind is sent without a time zone, which the API does not accept.

Read a customer's credit balances

Look the customer up by the id you gave them in your own system (their external id).

var balances = await client.Customers.GetCustomerCreditBalancesByExternalIdAsync(
    new GetCustomerCreditBalancesByExternalIdRequest { ExternalId = "acme-corp" });

foreach (var balance in balances.Data)
{
    Console.WriteLine($"{balance.CurrencyName}: {balance.AvailableDecimal} available of {balance.TotalDecimal}");
}

Available, Used and Total are doubles, cut to 6 decimal places. Use the ...Decimal string fields when you need the exact value.

To get everything about a customer in one call (orders, seats, checkout links and credit balances), use GetCustomerStateByExternalIdAsync:

var state = await client.Customers.GetCustomerStateByExternalIdAsync(
    new GetCustomerStateByExternalIdRequest { ExternalId = "acme-corp" });

Handle errors

Any answer outside 2xx throws a PaidClientApiException. StatusCode holds the HTTP status and Body the JSON error the API sent, with error, code and details.

Some status codes also have their own subclass, such as NotFoundError (404), but only on endpoints whose API description lists that code. Others, for example 401, 409 and 422, arrive as the base PaidClientApiException. The safe pattern is to catch PaidClientApiException and look at StatusCode:

try
{
    await client.Customers.GetCustomerStateByExternalIdAsync(
        new GetCustomerStateByExternalIdRequest { ExternalId = "unknown-customer" });
}
catch (PaidClientApiException e)
{
    switch (e.StatusCode)
    {
        case 404:
            Console.WriteLine($"No such customer: {e.Body}");
            break;
        case 401:
        case 403:
            Console.WriteLine("Check the API key.");
            break;
        default:
            Console.WriteLine($"Paid answered {e.StatusCode}: {e.Body}");
            break;
    }
}

Retries and timeouts

The client retries only answers with status 408, 429 or 5xx, twice by default, with exponential backoff that honours Retry-After. Other errors are not retried. A dropped connection is not retried either: it throws HttpRequestException. Each attempt times out after 30 seconds; a timeout throws TaskCanceledException.

Change the defaults for the whole client, or for one call:

var client = new PaidClient(apiKey, new ClientOptions
{
    MaxRetries = 4,
    Timeout = TimeSpan.FromSeconds(10),
});

await client.Signals.CreateSignalsAsync(request, new RequestOptions { MaxRetries = 0 });

To retry a signal batch yourself, send the same signals with the same idempotency keys.

Target frameworks

On .NET 8 and 9 the settings on ClientOptions and RequestOptions can only be set when the object is created, while the .NET Standard 2.0 and .NET Framework builds allow setting them later, so the two builds are not interchangeable. Build the code that configures the client for the same target framework as the app that runs it; for example, a .NET Standard 2.0 library that sets BaseUrl or Timeout fails with MissingMethodException when a .NET 8 app loads it.

More

Development

Most of this repository is generated by Fern from Paid's OpenAPI spec, so changes to generated files are overwritten on the next release. Files listed in .fernignore are kept. Build with the .NET 9 SDK:

dotnet build src/Paid/Paid.csproj -c Release
dotnet test src/Paid.Test/Paid.Test.csproj
dotnet test src/Paid.Test.Wire/Paid.Test.Wire.csproj

Releases are published to nuget.org from .github/workflows/publish.yml when a bare version tag such as 0.1.0 is pushed, using NuGet Trusted Publishing (GitHub OIDC, no stored API key); the repository variable NUGET_USER names the nuget.org account.

License

MIT. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0 69 11/23/2026