Metering & Billing

Enterprise only
Related Documentation
Made by
Kong Inc.
Supported Gateway Topologies
hybrid db-less traditional
Supported Konnect Deployments
hybrid cloud-gateways serverless
Compatible Protocols
grpc grpcs http https tcp tls tls_passthrough udp ws wss
Priority
16
Minimum Version
Kong Gateway - 3.14

Metering & Billing requires a separate purchase. Contact Sales for pricing and availability.

The Metering & Billing plugin allows you to meter API requests and AI token usage for usage-based billing for both Kong Gateway on-prem and Konnect deployments. The plugin supports flexible customer identification, custom pricing dimensions, and fine-grained traffic filtering.

If you’re using Kong Gateway on-prem and want to meter traffic, you must use the Metering & Billing plugin.

Legacy built-in event ingestion: If you previously enabled metering using the built-in Konnect UI, do not enable the Metering & Billing plugin at the same time. This can result in duplicate events. Disable the built-in event ingestion first, then enable the plugin.

How it works

The Metering & Billing plugin runs in the Kong 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 plugin:

  1. Resolves the subject (the customer identity that gets billed) from the configured source (a Consumer, application, or request header).
  2. Captures standard Kong Gateway metadata on the event, including Route, Service, and response status.
  3. Attaches any configured custom attributes from request headers or query parameters, such as department, project, or priority tier.
  4. Buffers the event locally and delivers it in batches to the configured ingest endpoint, with automatic retries on failure:

Events and subjects

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 a Kong Gateway Consumer, Konnect Dev Portal application, or any request header value such as x-customer-id or x-tenant-id.

If the plugin can’t resolve a subject from the configured source (for example, if the expected header is missing), the event is dropped.

Captured event dimensions

For each request it meters, the plugin captures a set of standard fields on the event’s data payload. The available fields depend on the event type:

kong.api_request

Emitted for each proxied API request when meter_api_requests is enabled on the plugin.

Field

Type

Description

client_ip string Client IP address that made the request.
control_plane_id string ID of the control plane that produced the event.
request_host string Host of the request.
request_method string HTTP method of the request.
request_uri string URI path of the request.
request_size_bytes integer Size of the request in bytes.
request_user_agent string User agent of the request.
response_size_bytes integer Size of the response in bytes.
response_http_status integer HTTP status code of the response.
route_id string ID of the matched Route.
route_name string Name of the matched Route.
service_id string ID of the Gateway Service.
service_name string Name of the Gateway Service.
service_port integer Port of the Gateway Service.
service_protocol string Protocol of the Gateway Service.
subject_type string Type of the resolved subject, for example consumer_id.
upstream_status string HTTP status code returned by the upstream service.

kong.llm_request

Emitted for AI traffic when meter_ai_token_usage is enabled. A separate event is produced for the request and the response.

Field

Type

Description

type string Phase of the interaction, either request or response.
control_plane_id string ID of the control plane that produced the event.
service_id string ID of the Gateway Service.
route_id string ID of the matched Route.
http_status integer HTTP status code of the response.
api_request_id string Identifier that correlates the request and response events.
ai_plugin_id string ID of the AI plugin that handled the request.
ai_plugin_name string Name of the AI plugin that handled the request.
model string LLM model name. Reflects the request or response model depending on the type.
provider string LLM provider name, for example openai.
tokens integer Token count. Prompt tokens for request events and completion tokens for response events.
cache_status string Cache status of the AI response.
subject_type string Type of the resolved subject, for example consumer_id.

Portal and application fields

The following fields are included only when the request is associated with a Konnect Dev Portal application or API product, and can appear on either event type.

Field

Type

Description

application_id string ID of the associated application.
portal_id string ID of the associated Dev Portal.
api_product_version_id string ID of the associated API product version.
api_id string ID of the associated API.
api_package_id string ID of the associated API package.

In addition to these standard fields, you can attach operator-defined custom fields to events. See Filtering traffic and custom dimensions for more information.

Filtering traffic and custom dimensions

You can further narrow which traffic and dimensions the plugin will ingest as events. The following table describes how you can configure the plugin to filter traffic or custom dimensions:

Use case

Description

Configuration example

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 plugins can be applied globally, to Routes, Gateway Services, or Consumers, you can apply the Metering & Billing plugin to these entities to further narrow down the traffic you want to meter from the control plane. Scope the plugin to a Route, Service, or Consumer.

Buffering and delivery

The plugin 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 plugin itself is stateless; it doesn’t persist events across Gateway restarts.

Enforcing entitlements

The Metering & Billing plugin only meters events, it doesn’t enforce metered limits on its own.

v3.16+ Use the Entitlement Enforcement plugin alongside Metering & Billing to block requests when a customer’s credit balance, usage limit, or feature access is exhausted. See Get started with Entitlement Enforcement and Enforce entitlements on LLM traffic for step-by-step guides.

In previous versions, Kong Gateway had no plugin to enforce M&B entitlements directly, so you had to pair Metering & Billing with a rate limiting plugin to cap traffic. We still recommend combining rate limiting with entitlement enforcement. For example, if you’re metering AI request tokens to 100 per month, you can use AI Rate Limiting Advanced to protect the upstream from a burst of requests, in addition to the Entitlement Enforcement plugin blocking requests once the monthly allowance is spent.

Usage-based billing

The Metering & Billing plugin can’t bill customers. If you want to bill customers based on usage events from the plugin, use Konnect Metering & Billing or OpenMeter self-hosted.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!