What AUDR is
How records, emitters and sinks fit together, and how the Stigg Agent SDK writes records for sinks such as Chargebee.
Prerequisites
- A Stigg server API key for the environment the usage belongs to. Client and publishable keys can’t report usage.
- A harness, gateway or framework that writes AUDR records.
Set up AUDR ingestion
The Stigg sink is the@openaudr/audr-sink-stigg package, published by the AUDR project. It takes batches of records from an AUDR client and sends each record to Stigg as a raw event.
Install the sink
@openaudr/audr 0.2. It’s in alpha, so until version 1.0.0 a minor release can change its API.
Connect it to your AUDR client
Create the sink with an event name, and pass it to the AUDR client your emitter writes to:
An option you pass takes precedence over its environment variable. An invalid option throws a
ConfigurationError from the constructor.
One sink sends to one Stigg environment, because the API key selects it. To send records from several environments, create one sink and one client for each API key. The sink doesn’t filter on attribution.environment.
Call shutdown() on the client before the process exits, or queued records are lost. This matters most in serverless functions, request-scoped workers and CLIs.
For every option and response code, see the sink reference.
Check that events arrive
Open Usage events in the Stigg app, and filter by a customer your emitter reported for. Each record appears as an event with the name you passed aseventName, and its dimensions are the record’s fields.
Stigg accepts an event for a customer it doesn’t know, so an event can appear without being counted. A meter counts an event only when the customer has a subscription or credit grant with a feature whose meter selects that event. If usage doesn’t appear on a customer, check the customer ID, the event name and the meter’s filters.
Configure meters
The sink sends every record under the same event name, and your meters decide what counts. Create a metered feature with an event meter, and set it up as follows:- Filter on the event name you passed as
eventName, such asai.usage. - To count only some records, add conditions on dimensions. For example, add a condition on
attribution__feature_idto give each of your product’s features its own meter, or onresource__nameto meter one model. - Choose Sum and the dimension to add up, such as
usage__llm__input_tokens.
usage__llm__input_tokens while another sums usage__llm__output_tokens from the same records.
To charge credits, use a custom credit consumption formula that reads the record’s dimensions, such as dimensions.usage__llm__input_tokens * 0.002 + dimensions.usage__llm__output_tokens * 0.008. The sink never computes a price. If the emitter states a cost, it arrives as dimensions such as cost__total_cost, which a formula can read too.
How records map to events
Each AUDR record becomes one Stigg raw event:
The sink never sends a
resourceId, so usage counts toward the customer’s customer-level subscriptions. attribution.subscription_id arrives as the attribution__subscription_id dimension, which a meter condition can filter on.
Dimension names
Stigg accepts only strings, numbers and booleans as dimension values, so the sink flattens each record:- A nested field becomes one dimension, with its path joined by
__.usage.llm.input_tokensbecomesusage__llm__input_tokens. - Each label becomes its own dimension. A label
teambecomesattribution__labels__team. - An array becomes one JSON string, with
__jsonadded to its name. - Every other field is sent as it is, including
x_extension fields.
__, so meters and formulas that use these names keep working across sink versions.
Example
This record, written for the Stigg customeracct_42:
eventName is ai.usage:
Rejected records
The sink checks each record against Stigg’s rules before sending it. A record that breaks one is rejected and never sent, and the other records in the batch still go through. The AUDR client reports each rejected record with one of these details:Duplicates and retries
Stigg counts a retried record once. It treats two events as the same when they share anidempotencyKey, timestamp, customerId and eventName, and it keeps the first. The sink resends a failed request with the same body, so a retry is always a duplicate of the original.
To send a record again yourself, keep its record_id, timing.event_time, customer and event name unchanged. Changing any of them makes a new event that’s counted again. Stigg recognizes a duplicate for at least seven days after the original.
The sink doesn’t merge records from different emitters. If a harness and a gateway both write a record for the same model call, each becomes its own event. Send usage to Stigg from one layer only.