A fully typed client
Therecurso package is the official
Node.js / TypeScript client for the Recurso billing API. It wraps the REST
surface — 28 resources, 137 methods — behind a recurso.<resource>.<method>(...)
idiom, and every request and response is typed from the API’s OpenAPI schema so
your editor autocompletes fields and tsc catches shape mistakes.
Requires Node.js 18 or newer.
Install
Client construction
Import theRecurso class and construct it with your API key. The key is sent
as a bearer token (Authorization: Bearer <key>) on every request.
new Recurso(apiKey, options?). options is a
RecursoOptions object whose only field is baseUrl. For backward
compatibility a bare string is also accepted as the base URL:
baseUrl is the only supported option. There is no constructor timeout or
retry setting — the client uses axios defaults. If you need those, they’re
best handled at your own call sites.Base URL
If you omit
options entirely, the base URL defaults to
http://localhost:8080 (exported as DEFAULT_BASE_URL), which matches a local
make demo stack.
The resource-method idiom
Every call isrecurso.<resource>.<method>(...). Resources group sensibly by
domain:
Each resource exposes the CRUD and lifecycle methods that make sense for it —
for example
recurso.subscriptions has create, list, update, cancel,
pause, resume, reactivate, advance, charges, usage, and
setCommitment.
Typed responses
Responses are typed fromschema.d.ts, generated from the same OpenAPI spec the
API is built from, so results carry concrete field types rather than an opaque
object. Resource types are exported for annotating your own code:
2900 is $29.00, 499900 is
₹4,999.00 — which sidesteps floating-point rounding.
Worked example
Create a plan, a customer, and a subscription, read the customer back, then list subscriptions with an explicit page size.1
Create a plan
amount is in minor units. interval_count defaults to 1 when omitted.2
Create a customer
country defaults to US when omitted.3
Create a subscription
Reference the plan and customer by id.
4
Read it back
The subscription resource has no
get — read entities back through a
resource that does (customers.get, plans.get), or find the subscription
via subscriptions.list.5
List with a limit
List endpoints return a
{ data: [...] } envelope. Pass limit (and
page) to control the page.Pagination
Standard list methods accept aListParams object: page, limit, q (search
text), and status. Pagination is page-based, not offset-based, for these
endpoints:
webhooks.deliveries and auditLogs.list use limit/offset. The list
response is always a { data: [...] } envelope, so destructure data (it may
be undefined, hence the optional chaining above).
Error handling
The SDK does not define a custom error type — it uses axios under the hood and lets axios errors propagate. Wrap calls intry/catch and inspect the response
on failure:
err.response?.status gives the HTTP status (e.g. 409 when archiving a
customer with active subscriptions) and err.response?.data carries the API’s
JSON error body.
Next
Bill a customer
Customer → plan → subscription → first invoice, end to end.
Usage-based billing
Metric → plan charges → record usage → query and rate it.