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

@openaudr/audr-sink-chargebee

v0.1.1

Published

Chargebee sink for AUDR: deliver usage records to Chargebee Usage-Based Billing.

Readme

@openaudr/audr-sink-chargebee

npm Node versions

The Chargebee sink for AUDR delivers record batches from an @openaudr/audr Client to a Chargebee site's usage-ingest batch endpoint, for Chargebee Usage-Based Billing. Each record becomes one usage event, routed on attribution.subscription_id and de-duplicated on record_id. ESM with full type declarations; no runtime dependencies beyond @openaudr/audr.

Status: alpha. The record model tracks AUDR v1.0.0; until 1.0.0, a minor release may change the public API.

Setup

npm install @openaudr/audr @openaudr/audr-sink-chargebee

Requires Node.js 22.12 or later.

Usage

import { Client, createRecord } from '@openaudr/audr';
import { ChargebeeSink } from '@openaudr/audr-sink-chargebee';

const record = createRecord({
  resource: {
    provider: 'anthropic',
    type: 'model',
    name: 'claude-sonnet-5',
    operation: 'generation',
    modality: 'text',
  },
  usage: { llm: { input_tokens: 1200, output_tokens: 340, requests: 1 } },
  run: { run_id: '01J8ZQ8Y2K3M4N5P6Q7R8S9T0V', span_id: 'turn-3', run_type: 'agent_run' },
  attribution: { environment: 'production', account_id: 'acct_42', subscription_id: 'sub_42' },
});

const sink = new ChargebeeSink(); // reads CHARGEBEE_SITE and CHARGEBEE_API_KEY
const client = new Client(sink, {
  emitter: { component: 'harness', name: 'my-harness', version: '1.4.0' },
});
const result = client.record(record);
if (!result.queued) console.warn('record rejected', result.issues);

await client.shutdown(); // drains the queue, then closes the sink

The Client stamps its emitter onto every record that arrives without one; a record that reaches validation with no emitter is rejected with an /emitter issue and never sent. Record construction is documented in the core SDK README. A runnable version against a stand-in endpoint is examples/deliver.ts.

[!IMPORTANT] Chargebee routes on attribution.subscription_id. A record without one is never sent: deliver() returns it rejected with detail missing_subscription_id.

Configuration

Configure the sink with site and apiKey. Pass them explicitly or set CHARGEBEE_SITE and CHARGEBEE_API_KEY; explicit values take precedence, and apiKey is always required. Credentials belong to the sink and never appear in logs, errors, String(sink) or util.inspect(sink). An invalid configuration throws ConfigurationError from the constructor.

The sink sends each batch to https://{site}.{ingestDomain}/api/v2/batch/usage_events. ingestDomain defaults to ingest.chargebee.com; override it with ingestDomain or CHARGEBEE_INGEST_DOMAIN. For a host that is not a {site} subdomain of the ingest domain, set the full origin with ingestUrl or CHARGEBEE_INGEST_URL, which is mutually exclusive with site and ingestDomain.

Delivery

| AUDR field | Chargebee usage event | | --- | --- | | attribution.subscription_id | subscription_id | | record_id | deduplication_id | | timing.event_time | usage_timestamp, in milliseconds | | Every field, flattened | properties, such as usage__llm__input_tokens |

Chargebee accepts scalar properties only, so every field is flattened to a reversible name joined by __. Arrays and attribution.labels are sent as canonical JSON under a __json suffix, such as attribution__labels__json. Create metered features against these names. flattenRecord(record) returns the properties a record becomes before it is sent.

A batch is sent as one request, and each response becomes one BatchResult. A replay keyed on record_id is idempotent. The reference maps each response status to an outcome.

This sink forwards every field of the record, including attribution.labels and any x_* extension, to your Chargebee site verbatim. attribution.labels MUST NOT contain PII and resource.key_name is a label, never key material; the security policy holds the full rules. Enforce them where the record is built, the last point at which they can be enforced.

Documentation

License

Apache-2.0. Contributions follow CONTRIBUTING.md.