Skip to main content

audr-sink-chargebee

PyPI Python versions

The Chargebee sink for AUDR delivers record batches from an 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.

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

Setup

pip install audr audr-sink-chargebee

Requires Python 3.11 or later.

Usage

import asyncio
import audr
from audr_sink_chargebee import ChargebeeSink

record = audr.AUDR(
    timing=audr.Timing(duration_ms=812),  # event_time defaults to now
    resource=audr.Resource(
        provider="anthropic",
        type="model",
        name="claude-sonnet-5",
        operation="generation",
        modality="text",
    ),
    usage=audr.Usage(llm=audr.LlmUsage(input_tokens=1200, output_tokens=340, requests=1)),
    run=audr.Run(run_id="01J8ZQ8Y2K3M4N5P6Q7R8S9T0V", span_id="turn-3", run_type="agent_run"),
    attribution=audr.Attribution(
        environment="production", account_id="acct_42", subscription_id="sub_42"
    ),
)


async def main() -> None:
    sink = ChargebeeSink()  # reads CHARGEBEE_SITE and CHARGEBEE_API_KEY
    async with audr.Client(
        sink,
        emitter=audr.Emitter(component="harness", name="my-harness", version="1.4.0"),
    ) as client:
        result = client.record(record)
        assert result.queued, result.issues


asyncio.run(main())

Leaving the async with block drains the queue and 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.

Configuration

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

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

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 __. Each label becomes its own property, such as attribution__labels__team, with a . or - in the key rewritten to _. Create metered features against these names; attribution__feature_id is the property to select a feature's meter on. flatten_audr(record) returns the properties a record becomes before it is sent.

A batch is sent as one request, and each response becomes one audr.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.

Metadata

Release files for audr-sink-chargebee 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for audr-sink-chargebee 0.3.0
File Size Uploaded Provenance Actions
audr_sink_chargebee-0.3.0.tar.gz 17.9 kB With provenance Details for audr_sink_chargebee-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for audr-sink-chargebee 0.3.0
File Interpreter ABI Platform Actions
audr_sink_chargebee-0.3.0-py3-none-any.whl Python 3 none any Details for audr_sink_chargebee-0.3.0-py3-none-any.whl

Total release size: 39.5 kB

Release files / audr_sink_chargebee-0.3.0.tar.gz

Download URL audr_sink_chargebee-0.3.0.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7dc4acaca6318ec2f0e30f7a9618c695be8ae6e1c9e8e45c4429b0a17ee8b75d
BLAKE2b-256 checksum
How to use checksums
9c0106ffd04bc59f18cdf0253c4a40539d68524470792ede3adb95aabdc833b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / audr_sink_chargebee-0.3.0-py3-none-any.whl

Download URL audr_sink_chargebee-0.3.0-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
988931c107de1d6b176f16bbcad0963582ebadc2749d997c416a1e3fb6bba654
BLAKE2b-256 checksum
How to use checksums
5e58071406819382cb5b7002302c347e8ff22822d9f1d7d2b1703db4a84f354f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Security for audr-sink-chargebee 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for audr_sink_chargebee-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page