Skip to content

Commit 57d9df8

Browse files
feat(metering): Get Started guide (#3504)
* Start outlining the get started guide Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * Finish the rough draft Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * Add M&B scaffolding Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * Add metering and billing to rate limit check Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * Apply changes from testing Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * See if skipping product fixes build Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * appease vale Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * Finishing draft, adding concept diagram and words Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * Fix diagram, dev edit Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> * remove colors * Apply suggestions from code review --------- Signed-off-by: Diana <75819066+cloudjumpercat@users.noreply.github.com> Co-authored-by: Angel <angel.guarisma@konghq.com>
1 parent 9f160ba commit 57d9df8

File tree

4 files changed

+235
-2
lines changed

4 files changed

+235
-2
lines changed

.github/styles/base/Dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ Knatives
423423
knep
424424
kong
425425
kongair
426+
kong_konnect_api_request
426427
kong_name
427428
kong-ip
428429
Kong/kong
@@ -733,6 +734,7 @@ serializer
733734
serverless
734735
serviceaccounts
735736
serviceless
737+
service_name
736738
shm
737739
show_in_api
738740
Sigstore
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
---
2+
title: Get started with Metering and Billing in {{site.konnect_short_name}}
3+
description: Learn how to...
4+
content_type: how_to
5+
6+
permalink: /metering-and-billing/get-started/
7+
breadcrumbs:
8+
- /metering-and-billing/
9+
10+
products:
11+
- gateway
12+
- metering-and-billing
13+
14+
works_on:
15+
- konnect
16+
17+
tags:
18+
- get-started
19+
20+
tldr:
21+
q: What is Metering and Billing in {{site.konnect_short_name}}, and how can I get started with it?
22+
a: |
23+
[Metering & Billing](/metering-and-billing/) provides flexible billing and metering for AI and DevTool companies. It also includes real-time insights and usage limit enforcement.
24+
25+
This tutorial will help you get started with Metering & Billing by setting up metering based on {{site.base_gateway}} API requests, turn raw API usage into billable product offerings by defining features and pricing plans, and start subscriptions to assign to customers.
26+
27+
tools:
28+
- deck
29+
30+
prereqs:
31+
entities:
32+
services:
33+
- example-service
34+
routes:
35+
- example-route
36+
inline:
37+
- title: "{{site.konnect_short_name}} roles"
38+
content: |
39+
You need the [? role](/konnect-platform/teams-and-roles/#service-catalog) in {{site.konnect_short_name}} to configure metering and billing.
40+
icon_url: /assets/icons/kogo-white.svg
41+
42+
cleanup:
43+
inline:
44+
- title: Clean up Konnect environment
45+
include_content: cleanup/platform/konnect
46+
icon_url: /assets/icons/gateway.svg
47+
48+
min_version:
49+
gateway: '3.4'
50+
next_steps:
51+
- text: See all {{site.base_gateway}} tutorials
52+
url: /how-to/?products=gateway
53+
- text: Learn about {{site.base_gateway}} entities
54+
url: /gateway/entities/
55+
- text: Learn about how {{site.base_gateway}} is configured
56+
url: /gateway/configuration/
57+
- text: See all {{site.base_gateway}} plugins
58+
url: /plugins/
59+
automated_tests: false
60+
---
61+
62+
This getting-started guide shows how you can meter {{site.base_gateway}} API requests and invoice your customers based on their API consumption with Metering & Billing in {{site.konnect_short_name}}.
63+
64+
In this guide, you'll:
65+
* Create a {{site.base_gateway}} Consumer that you'll map as a customer
66+
* Set up a meter for {{site.base_gateway}} API requests
67+
* Create a premium plan based on API usage
68+
* Start subscriptions for a customer
69+
* Generate an invoice for a customer on the paid premium plan and see their API usage
70+
71+
The following diagram shows how {{site.base_gateway}} entities and Metering & Billing entities are associated:
72+
73+
{% mermaid %}
74+
flowchart TB
75+
subgraph gateway["<b>Kong Gateway</b>"]
76+
direction LR
77+
service["example-service"]
78+
route["example-route"]
79+
consumer1["Consumer-Kong Air"]
80+
end
81+
subgraph metering["<b>Konnect Metering & Billing</b>"]
82+
direction LR
83+
meter["Meter"]
84+
subgraph plan["Premium Plan"]
85+
direction LR
86+
feature2["Feature (example-service)"]
87+
rate-card2["Rate card"]
88+
end
89+
subgraph subscription["Premium Subscription"]
90+
direction LR
91+
customer1["Customer (Kong Air)"]
92+
end
93+
end
94+
gateway --> metering
95+
service --> meter
96+
meter --> feature2
97+
consumer1 --> customer1
98+
subscription --> plan
99+
100+
{% endmermaid %}
101+
102+
103+
## Create a Consumer
104+
105+
Before you configure metering and billing, you can set up a Consumer, Kong Air. [Consumers](/gateway/entities/consumer/) let you identify the client that's interacting with {{site.base_gateway}}. Later in this guide, you'll be mapping this Consumer to a customer in Metering & Billing and assigning them to a Premium plan. Doing this allows you map existing Consumers that are already consuming your APIs to customers to make them billable.
106+
107+
You'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.
108+
109+
<!--vale off-->
110+
{% entity_examples %}
111+
entities:
112+
consumers:
113+
- username: kong-air
114+
keyauth_credentials:
115+
- key: air-key
116+
{% endentity_examples %}
117+
<!--vale on-->
118+
119+
## Enable authentication
120+
121+
Authentication lets you identify a Consumer so you can invoice them as customers after they've consumed the resource, in this case, the API request.
122+
This example uses the [Key Authentication](/plugins/key-auth/) plugin, but you can use any [authentication plugin](/plugins/?category=authentication) that you prefer.
123+
124+
Enable the plugin globally, which means it applies to all {{site.base_gateway}} Services and Routes:
125+
126+
<!--vale off-->
127+
{% entity_examples %}
128+
entities:
129+
plugins:
130+
- name: key-auth
131+
config:
132+
key_names:
133+
- apikey
134+
{% endentity_examples %}
135+
<!--vale on-->
136+
137+
## Create a meter
138+
139+
In Metering & Billing, meters track and record the consumption of a resource or service over time. This usage can take various forms, such as API requests, compute time seconds, or tokens consumed. Usage metering is commonly event-based to ensure accuracy and data you can audit.
140+
141+
In this guide, you'll enable API Gateway requests for metering. This will meter API request traffic in Metering & Billing so that you can charge customers for API traffic usage.
142+
143+
1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
144+
1. Enable **API Gateway Requests**.
145+
146+
## Create a feature
147+
148+
Meters collect raw usage data, but features make that data billable. Without a feature, usage is tracked but not invoiced. Now that you're metering API consumption, you need to associate traffic from the `example-service` Gateway Service with a feature as something you want to price or govern.
149+
150+
Features are customer-facing, and show up on the invoice for paid plans. Feature examples could include things like flight data requests, GPT-5 input tokens, or available LLM models.
151+
152+
In this guide, you'll create a feature for the `example-service` you created in the prerequisites.
153+
154+
1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
155+
1. In the Metering & Billing sidebar, click **Product Catalog**.
156+
1. Click **Create Feature**.
157+
1. In the **Name** field, enter `example-service`.
158+
1. From the **Meter** dropdown menu, select "kong_konnect_api_request".
159+
1. Click **Add group by filter**.
160+
The group by filter ensures you only bill for traffic to `example-service`, not all {{site.base_gateway}} traffic. This lets you offer different pricing for different APIs.
161+
1. From the **Group by** dropdown menu, select "service_name".
162+
1. From the **Operator** dropdown menu, select "Equals".
163+
1. From the **Value** dropdown menu, select "example-service".
164+
1. Click **Save**.
165+
166+
## Create a Premium plan
167+
168+
Plans are the core building blocks of your product catalog. They are a collection of rate cards that define the price and access of a feature. Plans can be assigned to customers by starting a subscription.
169+
170+
A rate card describes price and usage limits or access control for a feature or item. Rate cards are made up of the associated feature, price, and optional usage limits or access control for the feature, called entitlements.
171+
172+
In this section, you'll create a Premium plan that grants paying customers access to the `example-service` at a rate of 5,000 requests per month:
173+
174+
1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
175+
1. In the Metering & Billing sidebar, click **Product Catalog**.
176+
1. Click the **Plans** tab.
177+
1. Click **Create Plan**.
178+
1. In the **Name** field, enter `Premium`.
179+
1. In the **Billing cadence** dropdown menu, select "1 month".
180+
1. Click **Save**.
181+
1. Click **Add Rate Card**.
182+
1. From the **Feature** dropdown menu, select "example-service".
183+
1. Click **Next**.
184+
1. From the **Pricing model** dropdown menu, select "Usage Based".
185+
1. In the **Price per package** field, enter `1`.
186+
1. In the **Quantity per package** field, enter `5000`.
187+
1. Click **Next**.
188+
1. Click **Save Rate Card**.
189+
1. Click **Publish Plan**.
190+
191+
## Start a subscription
192+
193+
Customers are the entities who pay for the consumption. In many cases, it's equal to your Consumer. Here you are going to create a customer and map our Consumer to it.
194+
195+
1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
196+
1. In the Metering & Billing sidebar, click **Billing**.
197+
1. Click **Create Customer**.
198+
1. In the **Name** field, enter `Kong Air`.
199+
1. In the **Include usage from** dropdown, select "kong-air".
200+
1. Click **Save**.
201+
1. Click the **Subscriptions** tab.
202+
1. Click **Create a Subscription**.
203+
1. From the **Subscribed Plan** dropdown, select "Premium".
204+
1. Click **Next**.
205+
1. Click **Create Subscription**.
206+
207+
<!--Note: Want to delete a customer? Cancel their subscription first and then you can delete them.-->
208+
209+
## Validate
210+
211+
You can run the following command to test the that the Kong Air Consumer is invoiced correctly:
212+
213+
<!--vale off-->
214+
{% validation rate-limit-check %}
215+
iterations: 6
216+
url: '/anything'
217+
headers:
218+
- 'apikey:air-key'
219+
{% endvalidation %}
220+
<!--vale on-->
221+
222+
This will generate six requests. Now, check the invoice that was created in Metering & Billing:
223+
224+
1. In the {{site.konnect_short_name}} sidebar, click **Metering & Billing**.
225+
1. In the Metering & Billing sidebar, click **Billing**.
226+
1. Click the **Invoices** tab.
227+
1. Click **Kong Air**.
228+
1. Click the **Invoicing** tab.
229+
1. Click **Preview Invoice**.
230+
231+
You'll see in Lines that `example-service` is listed and was used six times. In this guide, you're using the sandbox for invoices. To deploy your subscription in production, configure a payments integration in **Metering & Billing** > **Settings**.

app/_landing_pages/metering-and-billing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ rows:
142142
url: "https://konghq.com/contact-sales"
143143

144144

145-
145+

app/_plugins/blocks/validation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def render(context) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
1818

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

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

0 commit comments

Comments
 (0)