@meterry/sdk
v1.0.0
Published
TypeScript SDK for Meterry Billing
Readme
Meterry TypeScript SDK
import { BillingClient } from "@meterry/sdk";
import Decimal from "decimal.js";
const billing = new BillingClient({
baseUrl: "http://127.0.0.1:8080",
apiKey: process.env.BILLING_API_KEY,
timeoutMs: 10_000,
});
await billing.ingest.ingest("proj_001", "ers_001", {
source: "gateway",
idempotencyKey: "req_001",
subjectType: "organization",
subjectId: "org_001",
rawJson: { usage: { input_tokens: 100, output_tokens: 40 } },
xBilling: {
items: [{ metric: "tool_call.web_search", quantity: new Decimal("1"), unit: "call" }],
pricing_hints: {
"tool_call.web_search": { unit_price: new Decimal("0.02"), pricing_unit: new Decimal("1"), currency: "USD" },
},
},
pricingRuleSetId: "prs_fallback",
});The SDK exposes manager, query, ingest, and webhook signature helpers for
trusted server-side Meterry Billing integrations.
Use Decimal or decimal strings for xBilling quantity, unit price, pricing
unit, and discount values. The SDK validates these fields with decimal.js and
serializes values only when they can be represented by the current Billing API
JSON number contract; values that would silently lose precision are rejected.
Development
npm install
npm test