Skip to main content

Install

The SDK is standard-library only (no third-party dependencies) and requires Go 1.22+. Import it as recurso:

Create a client

NewClient takes your API key (sent as an Authorization: Bearer <key> bearer token) and optional functional options:
By default the client targets production (https://api.recurso.dev/v1 — the base URL already includes the /v1 prefix). Override it for a self-hosted, staging, or local make demo stack with WithBaseURL, and supply your own *http.Client with WithHTTPClient:
Amounts are integers in the currency’s smallest unit2900 is $29.00. This avoids floating-point rounding; convert for display only.

The service idiom

Every endpoint hangs off a typed service field on the Client. Each method takes a context.Context first, takes a *…Params struct for the body/filters, and returns (result, error):
The client exposes these services:

Worked example

Create a plan, a customer, and a subscription; then read the subscription back and list all subscriptions.
1

Set up the client

2

Create a plan

Money is in minor units — 2900 is $29.00/month.
3

Create a customer

4

Create a subscription

Creating a subscription generates its first invoice. Inspect a typed *recurso.APIError for structured failures (see below).
5

Read it back and list

Get takes a bare ID; list methods take a *…ListParams.

Error handling

Any non-2xx response is returned as a *recurso.APIError. It carries a stable machine-readable Code (e.g. "NOT_FOUND", "VALIDATION_ERROR"), a human-readable Message, and the HTTP StatusCode. Unwrap it with errors.As:
Non-API failures (network errors, a canceled context) come back as ordinary errors, so always check err != nil before using the result.

Pagination

Most list params take Limit plus a 1-based Page; pass an explicit Limit when you need the full set:
The raw usage-event stream instead pages with Limit and Offset (limit is capped at 200, server default 50):

Next

Bill a customer

Customer → plan → subscription → first invoice, end to end.

Usage-based billing

Metric → plan charges → record usage → query and rate it.