@commet/node
v9.3.0
Published
Commet SDK for Node.js - Billing and usage tracking
Maintainers
Readme
Commet is an all-in-one billing and payments platform for SaaS and AI products. @commet/node is the core SDK — use it to manage customers, track usage, handle subscriptions, and more from your server.
Installation
npm install @commet/nodeGetting Started
1. Create a Commet account
Sign up at commet.co and create an organization. Go to Settings → API Keys to get your key.
# .env
COMMET_API_KEY=ck_...2. Initialize the SDK
import { Commet } from '@commet/node';
const commet = new Commet({
apiKey: process.env.COMMET_API_KEY,
});3. Start using it
// Create a customer
const customer = await commet.customers.create({
fullName: 'Acme Corp',
email: '[email protected]'
});
// Subscribe them to a plan
await commet.subscriptions.create({
customerId: 'cus_123',
planCode: 'pro', // autocomplete works after `commet pull`
billingInterval: 'yearly',
});
// Track usage events
await commet.usage.track({
featureCode: 'api_call',
value: 1,
customerId: 'cus_123'
});
// Manage seats
await commet.seats.add({
customerId: 'cus_123',
featureCode: 'admin',
count: 5
});
// Track durable quota (e.g. projects, tasks)
await commet.quota.add({
customerId: 'cus_123',
featureCode: 'projects',
count: 5
});
// Read the current quota allowance (held vs included)
const projects = await commet.quota.get({
customerId: 'cus_123',
featureCode: 'projects'
});
// Check feature access
const access = await commet.usage.check({
customerId: 'cus_123',
featureCode: 'api_calls'
});
// Generate customer portal link
const portal = await commet.portal.getUrl({
customerId: 'cus_123'
});Offers and selectable pricing
Create reusable country Markets and attach market prices to a base price or an inherited selectable variant:
const argentina = await commet.markets.create({
name: 'Argentina',
countryCodes: ['AR'],
});
const variant = await commet.plans.addPrice({
id: 'pln_pro',
billingInterval: 'monthly',
inheritsFromPriceId: 'pp_monthly',
marketPrices: [{
marketGroupId: argentina.id,
currency: 'ars',
price: 1_500_000,
}],
});
await commet.subscriptions.create({
customerId: 'cus_123',
planId: 'pln_pro',
priceId: variant.id,
});Offers own discount phases. Promo Codes reference compatible Offers instead of duplicating discount fields:
const offer = await commet.offers.create({
name: 'First three months at 25% off',
phases: [{ type: 'percentage', percentage: 2500, durationCycles: 3 }],
});
await commet.promoCodes.create({
code: 'LAUNCH25',
offerId: offer.id,
});Omitting priceId preserves default price resolution and still applies Currency Pricing and Markets. A subscription keeps the selected price identity and renews from that catalog price's current value.
Type Safety
Use the Commet CLI to generate TypeScript types from your organization:
npm install -g commet
commet login
commet link
commet pullThis generates type-safe autocomplete for your plan codes, feature codes, and seat types.
Update notifications
During local development, the SDK checks npm once per process and warns when a newer @commet/node version is available. The check never runs in production or CI and does not block SDK initialization. Set COMMET_NO_UPDATE_CHECK=1 to disable it.
Documentation
The version-matched reference is installed at node_modules/@commet/node/docs/README.md. It includes the generated API and webhook contracts used by this release.
Visit commet.co/docs for:
- Complete API reference
- Advanced usage examples
- Error handling
- Best practices
Resources
License
MIT
