---
title: "Create a MeteringAndBilling plugin"
method: POST
path: "/{workspace}/plugins#MeteringAndBilling"
tags: ["Plugins"]
---

# Create a MeteringAndBilling plugin

`POST /{workspace}/plugins#MeteringAndBilling`

Create a MeteringAndBilling plugin

## Request body

- MeteringAndBillingPlugin — A Plugin entity represents a plugin configuration that will be executed during the HTTP request/response lifecycle. It is how you can add functionalities to Services that run behind Kong, like Authentication or Rate Limiting for example. You can find more information about how to install and what values each plugin takes by visiting the [Kong Hub](https://docs.konghq.com/hub/). When adding a Plugin Configuration to a Service, every request made by a client to that Service will run said Plugin. If a Plugin needs to be tuned to different values for some specific Consumers, you can do so by creating a separate plugin instance that specifies both the Service and the Consumer, through the `service` and `consumer` fields.
  - `condition` string, nullable — An expression used for conditional control over plugin execution. If the expression evaluates to `true` during the request flow, the plugin is executed; otherwise, it is skipped.
  - `created_at` integer, nullable — Unix epoch when the resource was created.
  - `enabled` boolean, nullable — Whether the plugin is applied.
  - `id` string, nullable — A string representing a UUID (universally unique identifier).
  - `instance_name` string, nullable — A unique string representing a UTF-8 encoded name.
  - `name` 'metering-and-billing', required — The name of the Plugin that's going to be added. Currently, the Plugin must be installed in every Kong instance separately.
  - `ordering` object, nullable
    - `after` object
      - `access` string[]
    - `before` object
      - `access` string[]
  - `partials` object[] — A list of partials to be used by the plugin.
    - `id` string — A string representing a UUID (universally unique identifier).
    - `name` string — A unique string representing a UTF-8 encoded name.
    - `path` string
  - `tags` string[], nullable — An optional set of strings associated with the Plugin for grouping and filtering.
  - `updated_at` integer, nullable — Unix epoch when the resource was last updated.
  - `config` object, required
    - `api_token` string, required — Bearer token for authenticating with the ingest endpoint.
    - `attributes` object[] — Capture custom properties to the usage event data payload for pricing dimensions or reporting. Attributes add dimensions like provider, department or project that your billing model needs for tiered or per-dimension pricing.
      - `event_property_name` string, required — The property name in the usage event data payload.
      - `look_up_value_in` string, required — The header name or query parameter that contains the value, e.g 'x-department-id'
      - `source` 'header' | 'query', required — Where to find this attribute in the request.
    - `ingest_endpoint` string, required — The HTTP endpoint where usage events are sent.
    - `keepalive` number — How long in milliseconds an idle connection to the ingest endpoint is kept open before being closed.
    - `meter_ai_token_usage` boolean — Emit events for LLM input and output tokens on AI Gateway requests.
    - `meter_api_requests` boolean — Emit a usage event for each API Gateway request.
    - `queue` object
      - `concurrency_limit` -1 | 1 — The number of of queue delivery timers. -1 indicates unlimited.
      - `initial_retry_delay` number — Time in seconds before the initial retry is made for a failing batch.
      - `max_batch_size` integer — Maximum number of entries that can be processed at a time.
      - `max_bytes` integer — Maximum number of bytes that can be waiting on a queue, requires string content.
      - `max_coalescing_delay` number — Maximum number of (fractional) seconds to elapse after the first entry was queued before the queue starts calling the handler.
      - `max_entries` integer — Maximum number of entries that can be waiting on the queue.
      - `max_retry_delay` number — Maximum time in seconds between retries, caps exponential backoff.
      - `max_retry_time` number — Time in seconds before the queue gives up calling a failed handler for a batch.
    - `ssl_verify` boolean — Verify the TLS certificate presented by the ingest endpoint.
    - `subject` object — The subject identifies who gets billed for each request. Choose where the plugin should look for the customer identifier.
      - `field` string — The header name, query parameter, consumer field, or application field that contains the customer identifier, e.g. 'x-customer-id'
      - `look_up_value_in` 'application' | 'consumer' | 'header' | 'query' — Where to find the customer identifier in the request.
    - `timeout` number — Maximum time in milliseconds to wait for a response from the ingest endpoint.
  - `consumer` object — If set, the plugin will activate only for requests where the specified has been authenticated. (Note that some plugins can not be restricted to consumers this way.). Leave unset for the plugin to activate regardless of the authenticated Consumer.
    - `id` string
  - `protocols` string[] — A set of strings representing protocols.
  - `route` object — If set, the plugin will only activate when receiving requests via the specified route. Leave unset for the plugin to activate regardless of the route being used.
    - `id` string
  - `service` object — If set, the plugin will only activate when receiving requests via one of the routes belonging to the specified Service. Leave unset for the plugin to activate regardless of the Service being matched.
    - `id` string

## Response `201`

Created MeteringAndBilling plugin

- MeteringAndBillingPlugin — A Plugin entity represents a plugin configuration that will be executed during the HTTP request/response lifecycle. It is how you can add functionalities to Services that run behind Kong, like Authentication or Rate Limiting for example. You can find more information about how to install and what values each plugin takes by visiting the [Kong Hub](https://docs.konghq.com/hub/). When adding a Plugin Configuration to a Service, every request made by a client to that Service will run said Plugin. If a Plugin needs to be tuned to different values for some specific Consumers, you can do so by creating a separate plugin instance that specifies both the Service and the Consumer, through the `service` and `consumer` fields.
  - `condition` string, nullable — An expression used for conditional control over plugin execution. If the expression evaluates to `true` during the request flow, the plugin is executed; otherwise, it is skipped.
  - `created_at` integer, nullable — Unix epoch when the resource was created.
  - `enabled` boolean, nullable — Whether the plugin is applied.
  - `id` string, nullable — A string representing a UUID (universally unique identifier).
  - `instance_name` string, nullable — A unique string representing a UTF-8 encoded name.
  - `name` 'metering-and-billing', required — The name of the Plugin that's going to be added. Currently, the Plugin must be installed in every Kong instance separately.
  - `ordering` object, nullable
    - `after` object
      - `access` string[]
    - `before` object
      - `access` string[]
  - `partials` object[] — A list of partials to be used by the plugin.
    - `id` string — A string representing a UUID (universally unique identifier).
    - `name` string — A unique string representing a UTF-8 encoded name.
    - `path` string
  - `tags` string[], nullable — An optional set of strings associated with the Plugin for grouping and filtering.
  - `updated_at` integer, nullable — Unix epoch when the resource was last updated.
  - `config` object, required
    - `api_token` string, required — Bearer token for authenticating with the ingest endpoint.
    - `attributes` object[] — Capture custom properties to the usage event data payload for pricing dimensions or reporting. Attributes add dimensions like provider, department or project that your billing model needs for tiered or per-dimension pricing.
      - `event_property_name` string, required — The property name in the usage event data payload.
      - `look_up_value_in` string, required — The header name or query parameter that contains the value, e.g 'x-department-id'
      - `source` 'header' | 'query', required — Where to find this attribute in the request.
    - `ingest_endpoint` string, required — The HTTP endpoint where usage events are sent.
    - `keepalive` number — How long in milliseconds an idle connection to the ingest endpoint is kept open before being closed.
    - `meter_ai_token_usage` boolean — Emit events for LLM input and output tokens on AI Gateway requests.
    - `meter_api_requests` boolean — Emit a usage event for each API Gateway request.
    - `queue` object
      - `concurrency_limit` -1 | 1 — The number of of queue delivery timers. -1 indicates unlimited.
      - `initial_retry_delay` number — Time in seconds before the initial retry is made for a failing batch.
      - `max_batch_size` integer — Maximum number of entries that can be processed at a time.
      - `max_bytes` integer — Maximum number of bytes that can be waiting on a queue, requires string content.
      - `max_coalescing_delay` number — Maximum number of (fractional) seconds to elapse after the first entry was queued before the queue starts calling the handler.
      - `max_entries` integer — Maximum number of entries that can be waiting on the queue.
      - `max_retry_delay` number — Maximum time in seconds between retries, caps exponential backoff.
      - `max_retry_time` number — Time in seconds before the queue gives up calling a failed handler for a batch.
    - `ssl_verify` boolean — Verify the TLS certificate presented by the ingest endpoint.
    - `subject` object — The subject identifies who gets billed for each request. Choose where the plugin should look for the customer identifier.
      - `field` string — The header name, query parameter, consumer field, or application field that contains the customer identifier, e.g. 'x-customer-id'
      - `look_up_value_in` 'application' | 'consumer' | 'header' | 'query' — Where to find the customer identifier in the request.
    - `timeout` number — Maximum time in milliseconds to wait for a response from the ingest endpoint.
  - `consumer` object — If set, the plugin will activate only for requests where the specified has been authenticated. (Note that some plugins can not be restricted to consumers this way.). Leave unset for the plugin to activate regardless of the authenticated Consumer.
    - `id` string
  - `protocols` string[] — A set of strings representing protocols.
  - `route` object — If set, the plugin will only activate when receiving requests via the specified route. Leave unset for the plugin to activate regardless of the route being used.
    - `id` string
  - `service` object — If set, the plugin will only activate when receiving requests via one of the routes belonging to the specified Service. Leave unset for the plugin to activate regardless of the Service being matched.
    - `id` string

## Other responses

- `401` — Unauthorized

---

[API](https://skmtc.net/kong/apis/kong-enterprise-admin-api.md) · [All operations](https://skmtc.net/kong/apis/kong-enterprise-admin-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/kong/kong-enterprise-admin-api/revisions/28b1f8a59cdc/schema)
