Skip to main content
The Agent SDK can report usage in the Agent Usage Detail Record (AUDR) 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.
Sending AUDR records from another system into Stigg instead? See Ingestion from AUDR.

What AUDR is

AUDR (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:

openaudr/audr on GitHub

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.

AUDR sinks

The sinks the AUDR project publishes, and how to install and configure each one.
The examples on this page use the Chargebee sink:
@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.
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 integrations, such as stiggVercelMiddleware(). For what each integration does, see 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:
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.
string
Always 1.1.0.
string
A new UUIDv7 for every record. Sinks use it to deduplicate retries.
object
The SDK that wrote the record: component is harness, name is @stigg/agent-sdk-js and version is the SDK version.
object
The model the call used.
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.
object
Who the call was for.
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.
object

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, 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.
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 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:
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: