Skip to Content
Payrudder

SDKs

Pre-release

Call 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/sdk
import { 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

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 check verifies 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 a 0.0.0 package cannot be published. bump X.Y.Z writes a new version everywhere.
  • .github/workflows/sdk-publish.yml is the publish path for the four registries (npm, PyPI, and the tags vX.Y.Z for Packagist and go/vX.Y.Z for Go in the public repository). It can only be started by hand, is a dry run unless that is switched off, refuses 0.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 webhook data schemas of the spec (WebhookEvent is a discriminated oneOf) 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 for ttlMs, then stale-while-revalidate, one request per pair in flight). Go, Python and PHP call getEntitlement each 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.