Skip to main content
Stigg can ingest usage in the Agent Usage Detail Record (AUDR) format. If a harness, gateway or framework you already use writes AUDR records, point it at the Stigg sink, and each record arrives in Stigg as a raw event that your meters can count.

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

The sink works with @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 as eventName, 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:
  1. Filter on the event name you passed as eventName, such as ai.usage.
  2. To count only some records, add conditions on dimensions. For example, add a condition on attribution__feature_id to give each of your product’s features its own meter, or on resource__name to meter one model.
  3. Choose Sum and the dimension to add up, such as usage__llm__input_tokens.
Several meters can count the same event. One feature can sum 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_tokens becomes usage__llm__input_tokens.
  • Each label becomes its own dimension. A label team becomes attribution__labels__team.
  • An array becomes one JSON string, with __json added to its name.
  • Every other field is sent as it is, including x_ extension fields.
The separator is always __, so meters and formulas that use these names keep working across sink versions.

Example

This record, written for the Stigg customer acct_42:
Arrives in Stigg as this event, when the sink’s eventName is ai.usage:
The sink sends every field of the record to Stigg, labels included. Keep personal data out of attribution.labels where the record is written.

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 an idempotencyKey, 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.

Avoid double counting

Don’t send records from the Stigg Agent SDK to the Stigg sink. The SDK already reports its usage to Stigg directly, so every call would be counted twice. Use the Stigg sink for usage that reaches Stigg no other way.