Skip to content
Merged
2 changes: 2 additions & 0 deletions .github/styles/base/Dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ Knatives
knep
kong
kongair
kong_konnect_api_request
kong_name
kong-ip
Kong/kong
Expand Down Expand Up @@ -732,6 +733,7 @@ serializer
serverless
serviceaccounts
serviceless
service_name
shm
show_in_api
Sigstore
Expand Down
2 changes: 1 addition & 1 deletion app/_data/schemas/frontmatter/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"type": "array",
"items": {
"type": "string",
"enum": ["ai-gateway", "gateway", "insomnia", "mesh", "kic", "catalog", "advanced-analytics", "dev-portal", "operator", "konnect", "event-gateway", "konnect-reference-platform"]
"enum": ["ai-gateway", "gateway", "insomnia", "mesh", "kic", "catalog", "advanced-analytics", "dev-portal", "operator", "konnect", "event-gateway", "konnect-reference-platform", "metering-and-billing"]
}
},
"tools": {
Expand Down
253 changes: 253 additions & 0 deletions app/_how-tos/get-started-with-metering-and-billing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
---
title: Get started with Metering and Billing in {{site.konnect_short_name}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is get started if you use Kong API Gateway.
How can we have a separate docs for GW and Generic metering?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metering & Billing

description: Learn how to...
content_type: how_to

permalink: /metering-and-billing/get-started/
breadcrumbs:
- /metering-and-billing/

products:
- gateway
- metering-and-billing

works_on:
- konnect

tags:
- get-started

tldr:
q: What is Metering and Billing in {{site.konnect_short_name}}, and how can I get started with it?
a: |
blah

tools:
- deck

prereqs:
skip_product: true
inline:
- title: cURL
content: |
[cURL](https://curl.se/) is used to send requests to {{site.base_gateway}}.
`curl` is pre-installed on most systems.
entities:
services:
- example-service
routes:
- example-route

cleanup:
inline:
- title: Clean up Konnect environment
include_content: cleanup/platform/konnect
icon_url: /assets/icons/gateway.svg

min_version:
gateway: '3.4'
next_steps:
- text: See all {{site.base_gateway}} tutorials
url: /how-to/?products=gateway
- text: Learn about {{site.base_gateway}} entities
url: /gateway/entities/
- text: Learn about how {{site.base_gateway}} is configured
url: /gateway/configuration/
- text: See all {{site.base_gateway}} plugins
url: /plugins/
automated_tests: false
---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add an intro like:
"This getting-started guide shows how you can meter Kong API requests and invoice your customers after their API consumption."

## Create a Consumer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a Consumer

Create a Gateway Consumer


Create the two consumers, one for the free and one for premium. These will be mapped to our customers/subjects later on
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"one for the free and one for premium"
as it's not relevant here maybe instead say something like:

Create two consumers. Later, we will assign them a Free or Premium plan.


[Consumers](/gateway/entities/consumer/) let you identify the client that's interacting with {{site.base_gateway}}.
We're going to use key [authentication](/gateway/authentication/) in this tutorial, so the Consumer needs an API key to access any {{site.base_gateway}} Services.

<!--vale off-->
{% entity_examples %}
entities:
consumers:
- username: kong-air
keyauth_credentials:
- key: air-key
- username: kong-travel
keyauth_credentials:
- key: travel-key
{% endentity_examples %}
<!--vale on-->

## Enable authentication

Authentication lets you identify a Consumer so that you can apply rate limiting.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authentication lets you identify a Consumer so that you can apply rate limiting. =>
Authentication lets you identify a Consumer so you can invoice Customers after their consumption.

This example uses the [Key Authentication](/plugins/key-auth/) plugin, but you can use any [authentication plugin](/plugins/?category=authentication) that you prefer.

Enable the plugin globally, which means it applies to all {{site.base_gateway}} Services and Routes:

<!--vale off-->
{% entity_examples %}
entities:
plugins:
- name: key-auth
config:
key_names:
- apikey
{% endentity_examples %}
<!--vale on-->

## Enable rate limiting
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. Metering & Billing doesn't integrate with Gateway rate limiter


Set rate limits for the consumers. Free consumer gets 1,000 requests for example-service and premium gets 5,000 requests for the same service/api.

Enable the [Rate Limiting plugin](/plugins/rate-limiting/) for the Consumer.
In this example, the limit is 5 requests per minute and 1000 requests per hour.

<!--vale off-->
{% entity_examples %}
entities:
plugins:
- name: rate-limiting
consumer: kong-air
config:
month: 1000
- name: rate-limiting
consumer: kong-travel
config:
month: 5000
{% endentity_examples %}
<!--vale on-->

## Configure ACL plugin
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. Metering & Billing doesn't integrate with Gateway ACL


Configure the ACL plugin to only allow access to the service for customers who have signed up, so our two consumers:

<!--vale off-->
{% entity_examples %}
entities:
consumers:
- username: kong-air
acls:
- group: kong-air
keyauth_credentials:
- key: air-key

- username: kong-travel
acls:
- group: kong-travel
keyauth_credentials:
- key: travel-key
{% endentity_examples %}
<!--vale on-->

^ ChatGPT recommended this to fix my ACL error, tested and it seems to work.

## Create a meter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we explain why? Like:
"To meter API request traffic from our consumers we will create a meter:"

1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
1. Enable **API Gateway Requests**.

This will pull in request proxied by your API Gateway in {{site.konnect_short_name}} to Metering & Billing.

## Create a feature

Creating a feature that is linked to our service:

1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
1. In the Metering & Billing sidebar, click **Product Catalog**.
1. Click **Create Feature**.
1. In the **Name** field, enter `example-service`.
1. From the **Meter** dropdown menu, select "kong_konnect_api_request".
1. Click **Add group by filter**.
1. From the **Group by** dropdown menu, select "service_name".
1. From the **Operator** dropdown menu, select "Equals".
1. From the **Value** dropdown menu, select "example-service".
1. Click **Save**.

## Create a plan
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We setup two plans here, if we want to keep both let's split into two sections:

  1. Setup a Free Plan
  2. Setup a Paid Plan


Creating plans for our feature.

1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use nested list to separate bigger tasks?
If not, I think we should split this into three sections:

  1. Create Plan
  2. Add Rate Card
  3. Publish Plan

1. In the Metering & Billing sidebar, click **Product Catalog**.
1. Click the **Plans** tab.
1. Click **Create Plan**.
1. In the **Name** field, enter `Free`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main use-case should be paid, setup a usage-based price. Otherwise we won't have invoice.

1. In the **Billing cadence** dropdown menu, select "1 month".
1. Click **Save**.
1. Click **Add Rate Card**.
1. From the **Feature** dropdown menu, select "example-service".
1. Click **Next**.
1. From the **Pricing model** dropdown menu, select "Free".
1. Click **Next**.
1. From the **Entitlements** dropdown, select "Metered".
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting up entitlement is optional. Not sure if we should include in getting started.
Wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also today M&B will track entitlement balance but won't enforce it in Gateway yet. It's coming in Q2. Maybe call it out as an info box here.

1. From the **Usage Period Interval** dropdown, select "Monthly".
1. In the **Allowance for Period** field, enter `1000`.
1. Click **Save Rate Card**.
1. Click **Publish Plan**.
1. Navigate back to **Plans** in the breadcrumbs.
1. Click **Create Plan**.
1. In the **Name** field, enter `Premium`.
1. In the **Billing cadence** dropdown menu, select "1 month".
1. Click **Save**.
1. Click **Add Rate Card**.
1. From the **Feature** dropdown menu, select "example-service".
1. Click **Next**.
1. From the **Pricing model** dropdown menu, select "Package".
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO selecting "Usage Based" would be simpler and more suitable for getting started.

1. In the **Price per package** field, enter `1`.
1. In the **Quantity per package** field, enter `5000`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage-based price doesn't have a quantity. Only the packaged price has it, but we changed it to UBP.

1. Click **Next**.
1. From the **Entitlements** dropdown, select "Metered".
1. In the **Allowance for Period** field, enter `5000`.
1. Click **Save Rate Card**.
1. Click **Publish Plan**.

## Map Consumers to customers

Copy link
Copy Markdown
Contributor

@hekike hekike Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should explain what a customer is briefly like
"Customers are the entities who pay for the consumption. In many cases, it's equal to your Consumer. Here we are going to create a Customer and map our Consumer to it."

1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
1. In the Metering & Billing sidebar, click **Billing**.
1. Click **Create Customer**.
1. In the **Name** field, enter `Kong Air`.
1. In the **Include usage from** dropdown, select "kong-air".
1. Click **Save**.
1. Click the **Subscriptions** tab.
1. Click **Create a Subscription**.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a separate section: "Start Subscription"

1. From the **Subscribed Plan** dropdown, select "Free".
1. Click **Next**.
1. Click **Create Subscription**.
1. Navigate back to **Customers** in the breadcrumbs.
1. Click **Create Customer**.
1. In the **Name** field, enter `Kong Travel`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to setup two Customers? One is not enough?

1. In the **Include usage from** dropdown, select "kong-travel".
1. Click **Save**.
1. Click the **Subscriptions** tab.
1. Click **Create a Subscription**.
1. From the **Subscribed Plan** dropdown, select "Premium".
1. Click **Next**.
1. Click **Create Subscription**.

Note: Want to delete a customer? Cancel their subscription first and then you can delete them.

## Validate

You can run the following command to test the that the Kong Travel Consumer is invoiced correctly:

<!--vale off-->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need rate limit section

{% validation rate-limit-check %}
iterations: 6
url: '/anything'
headers:
- 'apikey:travel-key'
{% endvalidation %}
<!--vale on-->

Now, check the invoice that was created in Metering & Billing:

1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
1. In the Metering & Billing sidebar, click **Billing**.
1. Click the **Invoices** tab.
1. Click **Kong Travel**.
1. Click the **Invoicing** tab.
1. Click **Preview Invoice**.

You'll see in Lines that example-service is listed and was used six times.
12 changes: 12 additions & 0 deletions app/_indices/metering-and-billing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: Metering and Billing Documentation Index
sections:
- title: Reference
items:
- path: /metering-and-billing/
- path: /metering-and-billing/**/*
auto_exclude: true
- title: How-Tos
items:
- type: how-to
products:
- metering-and-billing
14 changes: 14 additions & 0 deletions app/_landing_pages/metering-and-billing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
metadata:
title: "Metering and Billing"
content_type: landing_page
description: Learn how to meter and bill for your features with Metering and Billing.
breadcrumbs:
- /metering-and-billing/
products:
- metering-and-billing

rows:
- header:
type: h1
text: "Metering and Billing"
sub_text: Turn any events, logs, and metrics into revenue with usage-based metering and billing.
2 changes: 1 addition & 1 deletion app/_plugins/blocks/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def render(context) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength

products = @page.fetch('products', [])

unless %w[gateway kic ai-gateway operator event-gateway].any? { |p| products.include?(p) }
unless %w[gateway kic ai-gateway operator event-gateway metering-and-billing].any? { |p| products.include?(p) }
raise ArgumentError,
"Unsupported product for {% validation #{@name} %}"
end
Expand Down
Loading