---
title: API Gateway - Kong
slug: ZC_RV7YZwjP__cyZ2BJaS
docTags: 
createdAt: 2024-07-15T13:30:19.471Z
---

You can use Amberflo's API Metering plugin for [Kong](https://docs.konghq.com/gateway/latest/) to:

- **Meter API requests** handled by your Kong instance
- **Monetize your APIs** based on usage

For implementation details, see the [GitHub repository](https://github.com/amberflo/kong-plugin-amberflo)

## &#x20;How it Works

1. **Request Interception**
   &#x20;The plugin intercepts incoming API requests handled by Kong.
2. **Customer Identification**
   &#x20;It determines which customer is making the request by inspecting request headers.
   &#x20;You can configure Kong to inject the customerId header **before** this plugin runs.
   - Example: If you use [Kong's Key Authentication plugin](https://docs.konghq.com/hub/kong-inc/key-auth/), this is done automatically.
3. **Meter Event Generation**
   &#x20;The plugin generates a meter event for each request.
4. **Efficient Metering**
   &#x20;To avoid performance overhead:
   - Meter records are **batched**
   - Records are sent to Amberflo **asynchronously**

This setup ensures high-throughput usage tracking with **minimal impact on gateway performance**.

## &#x20;Installation

1. **Compile the Plugin Binary**
   Compile the plugin and make the resulting binary available to your Kong instance.
   - **Important:** Ensure your compilation environment matches your Kong runtime environment. A mismatch may result in a binary that won't run correctly.
2. **Update Kong Configuration**&#x20;
   Add the plugin to your Kong configuration.
   &#x20;For example, if you place the plugin server binary at: `/opt/amberflo/metering` then the relevant sections of your kong.conf file should resemble [this one.](https://github.com/amberflo/kong-plugin-amberflo/blob/main/kong.conf) For more detailed guidance on configuring Kong, refer to their official documentation [here](https://docs.konghq.com/gateway/latest/plugin-development/pluginserver/go/#example-configuration) and [here](https://docs.konghq.com/gateway/latest/reference/configuration/).
3. **Enable the plugin**
   You can enable the plugin in one of two ways:
   - Add it to your kong.yaml file
   - Or enable it via a call to the **Kong Admin API**

## Configuration

Please find a sample configuration file [here](https://github.com/amberflo/kong-plugin-amberflo/blob/main/metering.json).

Here's a breakdown of the fields and their respective meanings.

![](https://api.archbee.com/api/optimize/GQ6FhONXoR2DQjp03hOcB/JPotmyY8MZvKiZtfIfdW0_image.png)

