npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

flexprice-ts-sdk

v2.2.0

Published

TypeScript & JavaScript SDK for Flexprice usage-based billing infrastructure

Readme

@flexprice/sdk

Unofficial TypeScript & JavaScript SDK for Flexprice
A lightweight, fully typed, resilient client for the Flexprice metering & billing platform.


Features

  • 100% Type-Safe: Full TypeScript auto-completion powered directly by Flexprice OpenAPI operations.
  • Multi-Region Native: Built-in support for US (us) and India (in) Flexprice Cloud clusters, with custom endpoint overrides for self-hosted instances.
  • AsyncIterable Streaming: Effortlessly paginate through large datasets using for await (... of client.<resource>.list()).
  • Built-in Resilience: Automatic retries with exponential backoff for rate-limits (429), server conflicts (409), and transient errors (5xx).
  • Zero Heavy Dependencies: Extremely lightweight with standard Web fetch API compatibility.

Installation

npm install @flexprice/sdk
# or
pnpm add @flexprice/sdk
# or
yarn add @flexprice/sdk

Quickstart

Initialize the unified Flexprice client to access all 7 core platform resources:

import { Flexprice } from "@flexprice/sdk";

const flexprice = new Flexprice({
	apiKey: process.env.FLEXPRICE_API_KEY,
	region: "in", // "in" (api.cloud.flexprice.io) or "us" (us.api.flexprice.io)
});

async function main() {
	// 1. Create a customer
	const customer = await flexprice.customers.create({
		name: "Acme Enterprises",
		email: "[email protected]",
		external_id: "acme_tenant_101",
	});
	console.log(`Created customer: ${customer.id}`);

	// 2. Create a subscription
	const subscription = await flexprice.subscriptions.create({
		customer_id: customer.id,
		plan_id: "plan_pro_tier",
		currency: "USD",
		billing_period: "MONTHLY",
	});
	console.log(`Subscription status: ${subscription.status}`);

	// 3. Ingest metered usage event
	await flexprice.events.ingest({
		event_name: "api_requests",
		customer_id: customer.id,
		properties: { tokens_used: 1500, model: "gpt-4o" },
		timestamp: new Date().toISOString(),
	});
}

main().catch(console.error);

Core Resources

The SDK exposes 7 specialized resource modules attached to the Flexprice instance (or available as individual standalone imports):

1. Customers (flexprice.customers)

Create, update, search customers, and inspect customer entitlement state:

const customer = await flexprice.customers.create({
	name: "Stark Industries",
	email: "[email protected]",
	external_id: "stark_001",
});

const search = await flexprice.customers.query({ limit: 10 });

2. Metering & Events (flexprice.events)

Ingest single or bulk metered usage events and query usage analytics:

// Single event ingestion
await flexprice.events.ingest({
	event_name: "vector_search",
	customer_id: "cust_123",
	properties: { query_count: 50 },
});

// Bulk event ingestion
await flexprice.events.ingestBulk([
	{ event_name: "storage_gb", customer_id: "cust_123", properties: { size: 10 } },
	{ event_name: "storage_gb", customer_id: "cust_456", properties: { size: 25 } },
]);

3. Features & Entitlements (flexprice.features)

Define metered, boolean, static, and config features:

const feature = await flexprice.features.create({
	name: "API Rate Limit",
	lookup_key: "api_rate_limit",
	type: "METERED",
});

4. Plans & Prices (flexprice.plans & flexprice.prices)

Manage billing tiers, cloning, flat fees, and tiered usage pricing:

// Create bulk prices
await flexprice.prices.createBulk({
	items: [
		{
			amount: "99",
			currency: "usd",
			type: "FIXED",
			billing_period: "MONTHLY",
			billing_period_count: 1,
			invoice_cadence: "ADVANCE",
			entity_type: "PLAN",
			entity_id: "plan_123",
		},
	],
});

5. Subscriptions (flexprice.subscriptions)

Manage customer subscription lifecycles, upgrades, add-ons, and plan change previews:

// Preview plan change proration impact
const preview = await flexprice.subscriptions.previewPlanChange("sub_123", {
	target_plan_id: "plan_enterprise",
	billing_cadence: "RECURRING",
	billing_cycle: "anniversary",
	billing_period: "MONTHLY",
	billing_period_count: 1,
	proration_behavior: "create_prorations",
});

console.log(`Credit amount: ${preview.proration_details?.credit_amount}`);

6. Invoices (flexprice.invoices)

Preview, query, finalize, void, and pay invoices:

const invoices = await flexprice.invoices.query({
	customer_id: "cust_123",
	limit: 5,
});

// Finalize a draft invoice
await flexprice.invoices.finalize("inv_123");

Streaming Auto-Pagination

Every listable resource provides an AsyncIterable method for smooth pagination:

// Automatically handles page offsets and limits in the background
for await (const subscription of flexprice.subscriptions.list({ limit: 25 })) {
	console.log(`Sub ID: ${subscription.id}, Status: ${subscription.status}`);
}

Client Configuration

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | apiKey | string | process.env.FLEXPRICE_API_KEY | Your Flexprice API key (sk_test_... or sk_live_...) | | region | "us" \| "in" | "us" | Deployment cluster region ("us" or "in") | | baseUrl | string | undefined | Custom base URL override for self-hosted instances | | timeout | number | 10000 | HTTP request timeout in milliseconds | | maxRetries | number | 3 | Maximum automatic retries for 429, 409, or 5xx errors | | fetch | typeof fetch | globalThis.fetch | Custom fetch implementation |


Error Handling

All SDK errors inherit from FlexpriceError with HTTP status codes and endpoint context:

import { Flexprice, FlexpriceError } from "@flexprice/sdk";

try {
	await flexprice.subscriptions.get("sub_non_existent");
} catch (error) {
	if (error instanceof FlexpriceError) {
		console.error(`Flexprice API Error (${error.status}):`, error.message);
		console.error(`Endpoint: ${error.endpoint}, Request ID: ${error.requestId}`);
	}
}

License

MIT © Flexprice Community