> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Ingestion from AUDR

> Send Agent Usage Detail Records (AUDR) from any emitter to Stigg, and meter them as raw events.

Stigg can ingest usage in the [Agent Usage Detail Record (AUDR)](https://openaudr.dev/) 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.

> [card] [What AUDR is](https://docs.stigg.io/documentation/ai-agents/audr.md#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](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/reporting-raw-events/index.md).

### Install the sink

```bash theme={null}
npm install @openaudr/audr @openaudr/audr-sink-stigg
```

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:

```typescript theme={null}
import { Client } from '@openaudr/audr';
import { StiggSink } from '@openaudr/audr-sink-stigg';

// Reads STIGG_API_KEY
const sink = new StiggSink({ eventName: 'ai.usage' });

const audrClient = new Client(sink, {
  emitter: { component: 'harness', name: 'my-harness', version: '1.4.0' },
});

// Records from your emitter go to audrClient.record(...)

await audrClient.shutdown(); // Sends the queued records, then closes the sink
```

| Option | Default | Description |
| - | - | - |
| `apiKey` | The `STIGG_API_KEY` environment variable | A Stigg server API key. Required. The key decides which Stigg environment receives the events. |
| `eventName` | None | The event name every record is sent under. Required. It can't be one of the names Stigg reserves: `$usage.reported`, `$usage.ingested` or `usage.credit`. |
| `apiUrl` | The `STIGG_API_URL` environment variable, then `https://api.stigg.io` | The Stigg API origin. |
| `retry` | 3 attempts, with backoff from 500 ms up to 30 seconds | How often to retry a request that failed for a transient reason, such as a timeout or a `429`. |
| `timeoutMs` | `10000` | The deadline for each request, in milliseconds. |
| `logger` | None | An object with `warn` and `error` methods, such as `console`. The sink logs nothing without one. |

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](https://github.com/openaudr/audr/blob/main/sinks/stigg/typescript/docs/reference.md).

### Check that events arrive

Open [Usage events](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/viewing-usage-events.md) 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](https://docs.stigg.io/documentation/modeling-your-pricing-in-stigg/features/creating-features/metered-features.md#event-meters), 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](https://docs.stigg.io/documentation/modeling-your-pricing-in-stigg/credits/custom-formula.md) 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](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/reporting-raw-events/index.md):

| Raw event field | AUDR field | Notes |
| - | - | - |
| `idempotencyKey` | `record_id` | A retried record is counted once. |
| `customerId` | `attribution.account_id` | Required. Set it to the Stigg customer ID. |
| `eventName` | None | The `eventName` option, the same for every record. |
| `dimensions` | Every field of the record | Nested fields are flattened into dimension names. |
| `timestamp` | `timing.event_time` | Converted to UTC. |

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`:

```json theme={null}
{
  "spec_version": "1.1.0",
  "record_id": "0193a1c2-7d4e-7f00-9a1b-2c3d4e5f6a7b",
  "emitter": { "component": "harness", "name": "my-harness", "version": "1.4.0" },
  "timing": { "event_time": "2026-11-16T12:00:00.000Z" },
  "resource": {
    "provider": "anthropic",
    "type": "model",
    "name": "claude-sonnet-5",
    "operation": "generation",
    "modality": "text"
  },
  "run": { "run_id": "01J8ZQ8Y2K3M4N5P6Q7R8S9T0V", "span_id": "turn-3", "run_type": "agent_run" },
  "attribution": {
    "environment": "production",
    "account_id": "acct_42",
    "feature_id": "support-chat",
    "labels": { "region": "eu" }
  },
  "usage": { "llm": { "input_tokens": 1200, "output_tokens": 340, "requests": 1 } }
}
```

Arrives in Stigg as this event, when the sink's `eventName` is `ai.usage`:

```json theme={null}
{
  "eventName": "ai.usage",
  "customerId": "acct_42",
  "idempotencyKey": "0193a1c2-7d4e-7f00-9a1b-2c3d4e5f6a7b",
  "timestamp": "2026-11-16T12:00:00.000Z",
  "dimensions": {
    "spec_version": "1.1.0",
    "record_id": "0193a1c2-7d4e-7f00-9a1b-2c3d4e5f6a7b",
    "emitter__component": "harness",
    "emitter__name": "my-harness",
    "emitter__version": "1.4.0",
    "timing__event_time": "2026-11-16T12:00:00.000Z",
    "resource__provider": "anthropic",
    "resource__type": "model",
    "resource__name": "claude-sonnet-5",
    "resource__operation": "generation",
    "resource__modality": "text",
    "run__run_id": "01J8ZQ8Y2K3M4N5P6Q7R8S9T0V",
    "run__span_id": "turn-3",
    "run__run_type": "agent_run",
    "attribution__environment": "production",
    "attribution__account_id": "acct_42",
    "attribution__feature_id": "support-chat",
    "attribution__labels__region": "eu",
    "usage__llm__input_tokens": 1200,
    "usage__llm__output_tokens": 340,
    "usage__llm__requests": 1
  }
}
```

> [!WARNING]
>
> 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:

| Detail | Cause | Fix |
| - | - | - |
| `missing_customer_id` | The record has no `attribution.account_id`. | Set it to the Stigg customer ID. |
| `invalid_customer_id` | `attribution.account_id` isn't a valid Stigg customer ID. | Use the customer ID exactly as it appears in Stigg. |
| `unsupported_correction` | The record corrects an earlier one, through `corrects`. | Stigg can't replace or void usage it has received. Report an adjustment as new usage instead. |
| `invalid_timestamp` | `timing.event_time` isn't a valid RFC 3339 time. | Fix the time in the emitter. |
| `invalid_field:/record_id` | `record_id` is empty or longer than 255 characters. | Fix the record ID in the emitter. |
| `unencodable_field:<pointer>` | A field is `null` or a number that isn't finite, such as `NaN`. The pointer names the field. | Leave the field out, or give it a value. |
| `dimensions_too_large` | The flattened record is larger than 1 MiB. | Remove large labels or extension fields. |
| `duplicate_record_id` | Two records in the batch share a `record_id` but differ. | Give each record its own ID. |
| `bad_user_input:<field>` | Stigg refused the event. The sink resends the rest of the request without it. | Check the named field. |

### 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](https://docs.stigg.io/documentation/ai-agents/audr.md) 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.


## Related topics

- [Reporting raw events](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/reporting-raw-events/index.md)
- [Reporting usage in AUDR format from the Agent SDK](https://docs.stigg.io/documentation/ai-agents/audr.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.