The Metering & Billing Policy runs in the AI Gateway request/response path and emits usage events in CloudEvents format.
These events are immutable once emitted and aren’t observability or analytics signals.
For each request, the Policy:
- Resolves the subject (the customer identity that gets billed) from the configured source (an AI Consumer, application, or request header).
- Captures standard AI Gateway metadata on the event, including the AI Model, AI Agent, or AI MCP Server that handled the request, and the response status.
- Attaches any configured custom attributes from request headers or query parameters, such as department, project, or priority tier.
- Buffers the event locally and delivers it in batches to the configured ingest endpoint, with automatic retries on failure:
Every usage event has a subject that identifies who is billed for the request. The subject is the most important configuration decision because it determines how usage is grouped and aggregated. You can set the subject to an AI Consumer, Konnect Dev Portal application, or any request header value such as x-customer-id or x-tenant-id.
If the Policy can’t resolve a subject from the configured source (for example, if the expected header is missing), the event is dropped.
You can further narrow which traffic and dimensions the Policy will ingest as events.
The following table describes how you can configure the Policy to filter traffic or custom dimensions:
|
Use case
|
Description
|
How to configure
|
|
Filtering on custom dimensions
|
You can use event attributes to capture custom properties for the usage event for pricing dimensions or reporting.
Event attributes allow you to filter based on criteria such as provider, department, priority, or project for tiered or per-dimension pricing.
You can define any attribute that is found in the header, query, or path of a request.
|
Set config.attributes with the source, what attribute to look up in the source, and which source value to use.
|
|
Filtering traffic in a control plane
|
Since the Policy can be applied globally or scoped to an AI Consumer, AI Model, AI Agent, or AI MCP Server, you can attach the Metering & Billing Policy to these entities to further narrow down the traffic you want to meter.
|
Scope the Policy to an AI Consumer, AI Model, AI Agent, or AI MCP Server.
|
The Policy buffers events in a local queue before sending them to the ingest endpoint in batches. If delivery fails, the queue retries with exponential backoff up to the configured maximum retry duration. Events that can’t be delivered within that window are dropped. The Policy itself is stateless; it doesn’t persist events across restarts.