> ## 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.

# Reporting usage in AUDR format

> Write an Agent Usage Detail Record (AUDR) for every model call the Agent SDK meters, and send it to a third-party business application such as Chargebee.

The Agent SDK can report usage in the [Agent Usage Detail Record (AUDR)](https://openaudr.dev/) format, an open standard for recording who started an agent run and what each step of it used. Turn it on, and the SDK writes one AUDR record for every model call it meters, alongside the usage it reports to Stigg.

> [!TIP]
>
> Sending AUDR records from another system into Stigg instead? See [Ingestion from AUDR](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/reporting-raw-events/ingestion-from-audr.md).

## What AUDR is

[AUDR](https://openaudr.dev/) (Agent Usage Detail Record) is an open standard for recording who initiated your agent runs and how much each cost, across every system a run passes through. Each record describes one metered operation, such as a model call, and who it belongs to, such as the customer and feature. A record holds the raw counts that drive cost, such as tokens, but no prices. Pricing happens downstream, in whatever system receives the records.

Two kinds of systems take part:

* **Emitters** write records. An emitter can be an agent harness, an AI gateway or a framework.
* **Sinks** receive records and deliver them to a destination, such as a billing system, a warehouse or a file.

One emitter can send to several sinks, and one sink can receive from several emitters.

Stigg plays both roles:

| Role | What Stigg does | See |
| - | - | - |
| Emitter | The Agent SDK writes a record for every model call it meters, for any sink, such as one that delivers to Chargebee | This page |
| Sink | Stigg receives records from any emitter and meters them as raw events | [Ingestion from AUDR](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/reporting-raw-events/ingestion-from-audr.md) |

> [card] [openaudr/audr on GitHub](https://github.com/openaudr/audr)
>
> The AUDR specification, the core SDKs and the published sinks.

## When to use it

Report usage to an AUDR sink when you want visibility into usage in other business applications as well as Stigg. The most common case is billing in a third-party business application such as Chargebee. Stigg checks entitlements and meters each call, and the billing system receives a record of each call and invoices it.

Records can also go to a warehouse or an observability stack. An AUDR sink can deliver them to an OpenTelemetry collector, a file or any other destination that has a sink, in one format across every model vendor.

Turning AUDR on doesn't change what the SDK reports to Stigg. The SDK reports each call's usage to Stigg as before, and also writes an AUDR record after the call. Writing a record can't block a call, because access is still decided by the check before the call.

## Report usage to an AUDR sink

### Install the AUDR packages

The SDK writes each record to an AUDR client, and the client's sink delivers it to a destination. Install both packages yourself: `@openaudr/audr` for the client, and the package of the sink you want.

> [card] [AUDR sinks](https://github.com/openaudr/audr/blob/main/sinks/README.md)
>
> The sinks the AUDR project publishes, and how to install and configure each one.

The examples on this page use the Chargebee sink:

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

`@openaudr/audr` is an optional peer dependency of the SDK, at versions `>=0.2.0 <0.3`. The SDK never loads it unless AUDR is turned on, so applications that leave AUDR off don't need it installed. The AUDR packages require Node.js 22.12 or later.

### Pass the audr option

Pass `audr` to the `StiggAgentSDK` constructor. AUDR is off until you do.

This example sends records to Chargebee. For another destination, swap `ChargebeeSink` for its sink.

```typescript theme={null}
import { Client } from '@openaudr/audr';
import { ChargebeeSink } from '@openaudr/audr-sink-chargebee';
import { StiggAgentSDK } from '@stigg/agent-sdk-js';

// Reads CHARGEBEE_SITE and CHARGEBEE_API_KEY
const audrClient = new Client(new ChargebeeSink());

const stigg = new StiggAgentSDK(process.env.STIGG_SERVER_API_KEY, {
  audr: { client: audrClient, environment: 'production' },
});
```

| Option | Description |
| - | - |
| `client` | Your own AUDR client. The SDK only calls its `record()` method. Its sink holds the credentials and handles batching and retries. |
| `environment` | The environment every record is for: `production`, `staging`, `development`, `test` or `evaluation`. Sinks ignore a record with no environment, so it's required. |

The constructor throws when `client` has no `record()` method or `environment` isn't one of the five values. A misconfiguration fails at startup instead of silently dropping every record.

One AUDR client serves the whole SDK. Every integration created from the same `StiggAgentSDK` writes to it: clients you wrap with `stigg.wrap()`, `fetch` functions you wrap with `stigg.wrapFetch()` and [agent framework](https://docs.stigg.io/documentation/ai-agents/overview.md#agent-frameworks) integrations, such as `stiggVercelMiddleware()`. For what each integration does, see [How it works](https://docs.stigg.io/documentation/ai-agents/overview.md#how-it-works).

### Add the subscription ID

Some AUDR sinks, such as Chargebee, associate each record with a subscription in the destination by `attribution.subscription_id`, and reject a record without one. The SDK doesn't set it.

If your sink needs it, add it with a client of your own that sets the subscription and passes the record on. The SDK only needs a `record()` method:

```typescript theme={null}
import { Client } from '@openaudr/audr';
import { ChargebeeSink } from '@openaudr/audr-sink-chargebee';
import { StiggAgentSDK, type AudrRecord } from '@stigg/agent-sdk-js';

const audrClient = new Client(new ChargebeeSink());

const stigg = new StiggAgentSDK(process.env.STIGG_SERVER_API_KEY, {
  audr: {
    environment: 'production',
    client: {
      record: (record: AudrRecord) =>
        audrClient.record({
          ...record,
          attribution: {
            ...record.attribution,
            subscription_id: subscriptionIdFor(record.attribution.account_id),
          },
        }),
    },
  },
});
```

`record()` is called synchronously after each model call, so look the subscription up from memory, such as a map you load at startup, instead of calling an API.

## What each record contains

Each record describes one model call. The SDK writes it from the same measurement it reports to Stigg: the usage in the vendor's response, the `stiggContext` of the call and the entitlement it was checked against. The values are arranged in AUDR's standard fields. See [Records and Stigg events](#records-and-stigg-events).

**spec\_version** `string`

Always `1.1.0`.

**record\_id** `string`

A new UUIDv7 for every record. Sinks use it to deduplicate retries.

**emitter** `object`

The SDK that wrote the record: `component` is `harness`, `name` is `@stigg/agent-sdk-js` and `version` is the SDK version.

**resource** `object`

The model the call used.

**properties**

**type** `string`

Always `model`.

**operation** `string`

Always `generation`.

**modality** `string`

Always `text`. A call that sends images or audio is still recorded as `text`, with the tokens the vendor reported.

**provider** `string`

The vendor, in lowercase:

| Integration | Provider |
| - | - |
| Wrapped client or wrapped `fetch` | The vendor of the client or recipe, such as `anthropic`. Any endpoint wrapped through the OpenAI recipe, such as DeepSeek, Together or vLLM, reports as `openai`. |
| LangChain | LangChain's `ls_provider` metadata |
| Vercel AI SDK | The model's provider, without the API part. `anthropic.messages` becomes `anthropic`. |
| Google ADK | Always `unknown`, because ADK doesn't state a provider |

**name** `string`

The model that served the call, as the response states it. When the response doesn't state one, it's the model the request asked for. A router or gateway can serve a different model from the one requested, which is why the response comes first. When neither is known, the name is `unknown`.

**usage.llm** `object`

The call's token counts, taken from the vendor's response. When the response has no count for a field, the record leaves that field out instead of setting it to `0`. For example, a call to a vendor that doesn't report cache usage has no `cache_read_tokens` or `cache_write_tokens`.

**properties**

**input\_tokens** `number`

Input tokens, excluding cache reads and writes.

**output\_tokens** `number`

Output tokens, including reasoning tokens.

**cache\_read\_tokens** `number`

Input tokens read from the vendor's cache.

**cache\_write\_tokens** `number`

Input tokens written to the vendor's cache.

**requests** `number`

Always `1`.

**attribution** `object`

Who the call was for.

**properties**

**environment** `string`

The `environment` you passed in the `audr` option.

**account\_id** `string`

The Stigg customer ID.

**feature\_id** `string`

The ID of the entitlement the call was checked against. For a credit currency, the currency ID. The SDK checks a call only when you tell it which feature or credits to enforce. See [Access enforcement](https://docs.stigg.io/documentation/ai-agents/access-enforcement.md). A call made without that is only metered, and its record has no `feature_id`.

Each sink uses `feature_id` in its own way. The Chargebee sink sends it as the `attribution__feature_id` property. To bill on it, create a metered feature in Chargebee that selects on that property and sums a counter, such as `usage__llm__input_tokens`.

**labels** `object`

The call's dimensions. See [Labels](#labels).

**run** `object`

The run the call belongs to. A run is one piece of work an agent does from start to finish, such as answering one user request. It can take several model calls. AUDR records each call as a span, a single step inside the run, so a sink can add up what a whole run used.

**properties**

**run\_id** `string`

Shared by every call in the same run:

| Integration | What makes one run |
| - | - |
| LangChain | The top-level run of the graph |
| Google ADK | One invocation, such as one `runAsync()`, whichever agent made each call |
| Wrapped client, wrapped `fetch` or Vercel AI SDK | Calls that pass the same `correlationId` in `stiggContext`. Without one, each call is its own run. |

A run ID must be 8 to 64 characters long. The SDK pads a shorter `correlationId` with underscores and cuts a longer one to 64 characters.

**span\_id** `string`

The ID of this call's span. Each call has its own.

**parent\_span\_id** `string`

The span of the step that made this call, such as the LangChain node that called the model. Set only for LangChain.

**name** `string`

The name of the agent that made the call, as your [agent framework](https://docs.stigg.io/documentation/ai-agents/overview.md#agent-frameworks) names it, such as `researcher`. Set only for calls made through a framework integration. It's the framework's name for the agent, which can differ from the `agentId` you use in Stigg.

**timing** `object`

**properties**

**event\_time** `string`

When the record was written, at the end of the call.

**duration\_ms** `number`

How long the call took, when the SDK knows when it started.

### Records and Stigg events

AUDR counts tokens the same way for every vendor. Each record has the same four counters, and they never overlap, so a billing system can price calls to any model with one set of meters.

Stigg receives each vendor's metrics under the vendor's own names, along with a total, so you can price each vendor exactly as it bills you. For example, OpenAI's `prompt_tokens` includes cached tokens, and AUDR's `input_tokens` excludes them.

Both describe the same call. To price it in Stigg and in another system, build Stigg's meters from the vendor's metrics and the other system's meters from the AUDR counters.

### Labels

Labels are key-value tags on a record, in `attribution.labels`. A sink passes them on to the destination, where you can filter or group usage by them. For example, the Chargebee sink sends a label `team` as the property `attribution__labels__team`.

The SDK turns each dimension of a call into a label. Dimensions are the key-value pairs you attach to a call in the `dimensions` field of its [`stiggContext`](https://docs.stigg.io/api-and-sdks/references/sdk/backend/rest/agent-sdk#stiggcontext), such as `{ team: 'support' }`. Stigg uses them to filter and attribute usage. When a call is made for an agent, the agent's ID becomes a label too, under its attribution key, such as `agentId: 'drafter'`.

AUDR limits labels, and the SDK drops a label that breaks the first two limits without a warning:

* A key must be 1 to 64 characters, using only letters, digits, `_`, `.` and `-`.
* A value must be a string of at most 256 characters.
* A record can hold at most 20 labels. The SDK doesn't drop extra labels, so the AUDR client rejects the whole record and logs a warning. Keep each call to 20 dimensions or fewer.

> [!WARNING]
>
> Labels leave your process and reach the billing system as they are. Keep personal data and other sensitive values out of dimensions when AUDR is on.

## Limitations

Some calls that Stigg meters write no AUDR record, so the destination can show less usage than Stigg:

* A call whose response reported no token counts writes no record, because the SDK writes records only for calls with token usage. Stigg still receives any other metrics the vendor reported, such as a gateway's cost.
* A call with estimated or incomplete usage writes no record. This happens when the SDK estimates usage or the vendor reported only part of it, such as a stream abandoned before the vendor reported its counts. AUDR has no way to mark a number as an estimate, and a billing system would charge it as stated. Stigg still receives the estimate, unless a [usage mapper](https://docs.stigg.io/documentation/ai-agents/usage-metering.md#usage-mappers) skips it. The SDK logs a warning the first time it skips a record.
* Tool calls write no record yet. Records cover model calls only.

## Avoid duplicate reports

A call reported twice is billed twice. Two setups cause this:

* A call passes through the SDK twice. For example, a LangChain handler over a wrapped client writes two records for one model call, and a sink can't tell them apart. Govern each call through one integration.
* The SDK's AUDR client sends to a Stigg sink. Stigg already receives this usage directly from the SDK, so every call would be counted twice. Records the SDK writes carry the emitter `@stigg/agent-sdk-js`, so you can filter them out of a pipeline that feeds Stigg.

## Errors and flushing

Writing a record never fails or delays a model call. The SDK writes the record and reports the usage to Stigg in parallel, and neither waits for the other. A failed Stigg report doesn't stop the record, and a failed record doesn't stop the report.

If the AUDR client throws, or its `record()` returns a promise that rejects, the error goes to `onError` with the operation `audr`. Check `context.operation` to tell AUDR failures apart from Stigg reporting failures:

```typescript theme={null}
const stigg = new StiggAgentSDK(process.env.STIGG_SERVER_API_KEY, {
  audr: { client: audrClient, environment: 'production' },
  onError: (error, context) => {
    if (context.operation === 'audr') audrTelemetry.capture(error, context);
    else myTelemetry.capture(error, context);
  },
});
```

A record the AUDR client rejects as invalid doesn't reach `onError`, because the client raises no error for it. The client logs a warning and drops the record.

The SDK never flushes or shuts down your AUDR client. In serverless functions, request-scoped workers and CLIs, call the client's `shutdown()` yourself before the process exits, or queued records are lost:

```typescript theme={null}
await stigg.flush({ close: true });  // Stigg reports
await audrClient.shutdown();         // AUDR records: send the queue, then close the sink
```


## Related topics

- [JavaScript](https://docs.stigg.io/api-and-sdks/changelog/agent-sdk/javascript.md)
- [Ingestion from AUDR](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/reporting-raw-events/ingestion-from-audr.md)
- [Providers, frameworks and formats](https://docs.stigg.io/documentation/ai-agents/providers/overview.md)
- [Reporting calculated usage](https://docs.stigg.io/documentation/getting-usage-data-into-stigg/reporting-calculated-usage.md)
- [Reporting entitlement usage](https://docs.stigg.io/documentation/managing-customers-and-subscriptions/customers/reporting-entitlement-usage.md)


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