SDKs
Pre-releaseCall the tenant API and verify webhooks from TypeScript, Go, Python or PHP without writing HTTP by hand.
Client libraries for the tenant API (/v1/*, authenticated with an API key prk_test_… or prk_live_…) and for verifying webhook signatures, so your application can meter usage, manage customers and subscriptions and react to events. The operator API (/admin/v1) and the console's session routes (/app/v1, /auth) are not part of them.
TypeScript / JavaScript
@payrudder/sdk in sdk/typescript. Node 20+, browsers and edge runtimes (global fetch and WebCrypto); ESM + CJS + .d.ts.
Go
github.com/nafrucom/payrudder-sdks/go in sdk/go. Its own module, standard library only; iter.Seq2 pagination.
Python
payrudder in sdk/python. 3.10+, typed (py.typed), sync Payrudder and async AsyncPayrudder on httpx.
PHP
payrudder/payrudder-php in sdk/php. 8.1+, PSR-18 or the built-in curl transport; typed models and backed enums.
The SDKs are pre-release, at version 0.1.0. Python, Go and PHP are used from a checkout of the repository until they are published. In the commands below, /path/to/payrudder is the folder you cloned the repository into.
Install and make a first call
npm install @payrudder/sdkimport { Payrudder } from "@payrudder/sdk";
const payrudder = new Payrudder({
apiKey: process.env.PAYRUDDER_API_KEY, // prk_test_... (sandbox) or prk_live_...
});
await payrudder.customers.createCustomer({ external_id: "cus_42", name: "Ada", email: "ada@example.com" });
const results = await payrudder.events.ingest([
{ customer_external_id: "cus_42", meter_code: "ai_tokens", quantity: "1500", event_time: new Date() },
]);The console's Connect your app page shows these lines with the code to send a first event and to verify a webhook, built from your own meter. A test (web/admin/src/features/connect/__tests__/snippets.sdk.test.ts) compiles that code against the SDKs of the repository.
Each SDK has an examples/ directory with the same four programs: send a usage event, create a customer, list invoices, verify a webhook. They are not run (they need a gateway), but each SDK's own CI job type-checks, vets or analyses them (go build and golangci-lint, tsc and eslint, mypy --strict and ruff, PHPStan level max and php-cs-fixer), so a renamed method fails the build. For whole web apps, see Examples.
One design, four languages
Every operationId of api/openapi/v1.yaml under /v1/* is a method, named after the operationId in the language's usual case, on a resource namespace taken from the first path segment (customers, invoices, creditNotes, …). Arguments: path parameters, the body, the query, then per-call options (idempotency key, timeout, retries, headers).
Models and methods are generated from the OpenAPI file (npm run generate, go generate ./..., python tools/generate.py, composer generate). Each SDK has a test that fails when an operation has no method (or a method no operation), and CI checks that the generated files are current.
*_minor amounts are int64 strings on the wire and a safe integer type in the SDK (TypeScript string or bigint, Go payrudder.Int64, Python int, PHP int that refuses to overflow). Decimal quantities and prices are strings or Decimal.
events.ingest splits a list into batches of at most 500 events and 1 MiB, fills an idempotency key per event when the caller gives none (the key is stable across retries), and returns one result per event in request order. A rejected event is a result, not an exception. See Idempotency.
Network errors, 429 (honours Retry-After), 502, 503 and 504 are retried with exponential backoff and jitter; a 500 only for idempotent calls or a POST that carries an idempotency key. No other 4xx is retried.
One typed error carrying the HTTP status, code, the translatable error key (for example billing.credit_note.nothing_to_refund), message, details, request id and Retry-After, with subtypes for authentication, permission, not found, validation, conflict, rate limit, server and connection or timeout. The mapping per language is on Errors.
Every list operation that has a page_token also has an iterator (generator, async iterator or iter.Seq2) that walks all pages.
verifyWebhook / constructEvent implement the scheme of Webhooks: HMAC-SHA256 over t.payload, constant-time comparison, several v1 signatures for secret rotation, a 300 s tolerance. The event type names are constants.
Command line
The Go module also builds payrudder, a command line on the Go SDK (sdk/go/cmd/payrudder, standard library only): login, events send, events tail, webhooks listen, webhooks trigger ping, webhooks redeliver, customers list, customers create, plans create, plans publish -f, meters create, subscriptions create, webhooks create, invoices list. It is described on the Command line page and has the same pre-release status as the SDKs.
Versions and releases
All four SDKs and the command line share one version number (default, not agreed), and each keeps a CHANGELOG.md in the Keep a Changelog format. See Versioning.
node scripts/sdk-release.mjs checkverifies that the version is the same in every place it is written, that each SDK has its LICENSE and CHANGELOG and the metadata a registry shows, and that a0.0.0package cannot be published.bump X.Y.Zwrites a new version everywhere..github/workflows/sdk-publish.ymlis the publish path for the four registries (npm, PyPI, and the tagsvX.Y.Zfor Packagist andgo/vX.Y.Zfor Go in the public repository). It can only be started by hand, is a dry run unless that is switched off, refuses0.0.0, and its publishing jobs wait for an approver.
The SDKs are public, under the Apache License 2.0, in nafrucom/payrudder-sdks. A workflow copies the tracked files of sdk/ there as one commit on every push to main that touches them; only snapshots leave the main repository, never its history. That repository is read-only: changes are made in the main repository. Its root is sdk/, so sdk/README.md and sdk/LICENSE are its front page and licence, and sdk/composer.json is what Packagist reads.
Tests
Unit tests run against a local fake HTTP server: retries, backoff, Retry-After, key stability, error mapping, pagination, ingest splitting, and webhook verification with tampered payloads, stale timestamps and rotated secrets. An optional smoke test per SDK runs against a real stack when PAYRUDDER_API_KEY is set. CI has one workflow per SDK (.github/workflows/sdk-<language>.yml), triggered by changes to its directory or to the spec.
Not done
- The generators emit the types reachable from
paths. The per-event webhookdataschemas of the spec (WebhookEventis a discriminatedoneOf) are not generated into the SDKs yet, so webhook payloads are typed by hand. - Lists the backend does not page (meters, plans, coupons, webhook endpoints, credit packs, entitlements) have no iterator.
- Only the TypeScript SDK has
EntitlementCache(entitlement checks from the process's memory: fresh forttlMs, then stale-while-revalidate, one request per pair in flight). Go, Python and PHP callgetEntitlementeach time; PHP would need a shared store (APCu, Redis) because a request does not outlive its process. - Other languages (Java, C#, Ruby) are not built; the OpenAPI file is the contract for them.